git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH decompress BUG] Fix decompress_next_from() wrong argument value
@ 2008-01-11 20:47 Marco Costalba
  2008-01-12  0:16 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Costalba @ 2008-01-11 20:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-12 18:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-11 20:47 [PATCH decompress BUG] Fix decompress_next_from() wrong argument value Marco Costalba
2008-01-12  0:16 ` Junio C Hamano
2008-01-12  7:06   ` Marco Costalba
2008-01-12  7:31     ` Junio C Hamano
2008-01-12  7:42       ` Marco Costalba
2008-01-12 18:44         ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).