git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git 1.5.1-rc1 doesn't like empty files

From
Junio C Hamano <junkio@cox.net>
Date
Mar 20, 2007, 06:00 UTC
Message-ID
<7v648wbgiy.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0703192245490.6730@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
> We've had this bug before - thinking that we don't need to inflate() 
> anything because we already had it all..
>
> 		Linus

Thanks. I think we _do_ need a big fat warning near the code to avoid the same mistake in the future. Something like this?

diff --git a/sha1_file.c b/sha1_file.c
index 9fe2bd6..d273aff 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1030,7 +1030,17 @@ static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size
 		n = size;
 	memcpy(buf, (char *) buffer + bytes, n);
 	bytes = n;
-	if (bytes < size) {
+	if (bytes <= size) {
+		/*
+		 * The above condition must be (bytes <= size), not
+		 * (bytes < size).  In other words, even if we expect
+		 * no more output, the input zlib stream may have bytes
+		 * that express "this concludes the stream", and we do
+		 * want to eat that input.  Otherwise we would not be
+		 * able to test that we consumed all the input to reach
+		 * the expected size *and* zlib gave status == Z_STREAM_END
+		 * to signal all went well.
+		 */
 		stream->next_out = buf + bytes;
 		stream->avail_out = size - bytes;
 		while (status == Z_OK)
Previous: Linus TorvaldsNext: Junio C Hamano
Message 16 of 18 in “git 1.5.1-rc1 doesn't like empty files”
  1. Pavel RoskinMar 20, 2007
  2. Nicolas VilzMar 20, 2007
  3. Linus TorvaldsMar 20, 2007
  4. Pavel RoskinMar 20, 2007
  5. Linus TorvaldsMar 20, 2007
  6. Pavel RoskinMar 20, 2007
  7. Shawn O. PearceMar 20, 2007
  8. Alexander LitvinovMar 20, 2007
  9. Andy ParkinsMar 20, 2007
  10. Junio C HamanoMar 20, 2007
  11. Andy ParkinsMar 20, 2007
  12. Linus TorvaldsMar 20, 2007
  13. Junio C HamanoMar 20, 2007
  14. Pavel RoskinMar 20, 2007
  15. Linus TorvaldsMar 20, 2007
  16. Junio C HamanoMar 20, 2007
  17. Junio C HamanoMar 20, 2007
  18. Linus TorvaldsMar 20, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.