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

[PATCH decompress BUG] Fix decompress_next_from() wrong argument value

From
MCMarco Costalba <mcostalba@gmail.com>
Date
Jan 11, 2008, 20:47 UTC
Message-ID
<e5bfff550801111247l1ccf171ene5b53b8d6841a864@mail.gmail.com>

Function decompress_next_from() needs a pointer to a buffer and the buffer size as arguments.

Interesting enough the function fill() that returns the buffer pointer happens to modify also the buffer size, stored in a variable at file scope.

So we need to guarantee fill() is called before to use buffer size as argument in decompress_next_from()

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
---
Patch to be applied above decompress helper series.

Not to be pedantic, but have a function that gives two really coupled values, as a buffer pointer and the size, the first as return value and the second through a variable at file scope is not something you are going to see advertised in the programming books!

Sorry for this little rant but this bug really made me crazy.
With this patch 'make test' runs with success!
 builtin-unpack-objects.c |    3 ++-
 index-pack.c             |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c
index f1a4883..72293ec 100644
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
@@ -68,7 +68,8 @@ static void *get_data(unsigned long size)
 	decompress_into(&stream, buf, size);

 	for (;;) {
-		int ret = decompress_next_from(&stream, fill(1), len, Z_NO_FLUSH);
+		void* tmp = fill(1); // fill() modifies len, so be sure is evaluated as first
+		int ret = decompress_next_from(&stream, tmp, len, Z_NO_FLUSH);
 		use(len - stream.avail_in);
 		if (stream.total_out == size && ret == Z_STREAM_END)
 			break;
diff --git a/index-pack.c b/index-pack.c
index 30d7837..13b308d 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -173,7 +173,8 @@ static void *unpack_entry_data(unsigned long
offset, unsigned long size)
 	decompress_into(&stream, buf, size);

 	for (;;) {
-		int ret = decompress_next_from(&stream, fill(1), input_len, Z_NO_FLUSH);
+		void* tmp = fill(1); // fill() modifies input_len, so be sure is
evaluated as first
+		int ret = decompress_next_from(&stream, tmp, input_len, Z_NO_FLUSH);
 		use(input_len - stream.avail_in);
 		if (stream.total_out == size && ret == Z_STREAM_END)
 			break;
-- 
1.5.4.rc2.95.g0eaa-dirty
Next: Junio C Hamano
Message 1 of 6 in “Fix decompress_next_from() wrong argument value”
  1. Fix decompress_next_from() wrong argument valueMarco Costalba, Jan 11, 2008
  2. Junio C HamanoJan 12, 2008
  3. Marco CostalbaJan 12, 2008
  4. Junio C HamanoJan 12, 2008
  5. Marco CostalbaJan 12, 2008
  6. Junio C HamanoJan 12, 2008

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.