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

[PATCH 1/4] archive-zip: deduplicate code setting output buffer in write_zip_entry()

From
Toon Claes <toon@iotcl.com>
Date
Aug 4, 2025, 16:56 UTC
Message-ID
<20250804-toon-archive-zip-fix-v1-1-ca89858e5eaa@iotcl.com>
In-Reply-To
<20250804-toon-archive-zip-fix-v1-0-ca89858e5eaa@iotcl.com>

There were two callsites setting the size and address of the output buffer. Instead of setting them outside the loop and in the loop after calling git_deflate(). Set them once in the loop, right before the git_deflate() call.

Co-authored-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Toon Claes <toon@iotcl.com>
---
 archive-zip.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/archive-zip.c b/archive-zip.c
index df8866d5ba..cc6d0cadd9 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -458,8 +458,6 @@ static int write_zip_entry(struct archiver_args *args,
 		git_deflate_init_raw(&zstream, args->compression_level);
 
 		compressed_size = 0;
-		zstream.next_out = compressed;
-		zstream.avail_out = sizeof(compressed);
 
 		for (;;) {
 			readlen = read_istream(stream, buf, sizeof(buf));
@@ -473,6 +471,8 @@ static int write_zip_entry(struct archiver_args *args,
 
 			zstream.next_in = buf;
 			zstream.avail_in = readlen;
+			zstream.next_out = compressed;
+			zstream.avail_out = sizeof(compressed);
 			result = git_deflate(&zstream, 0);
 			if (result != Z_OK)
 				die(_("deflate error (%d)"), result);
@@ -481,8 +481,6 @@ static int write_zip_entry(struct archiver_args *args,
 			if (out_len > 0) {
 				write_or_die(1, compressed, out_len);
 				compressed_size += out_len;
-				zstream.next_out = compressed;
-				zstream.avail_out = sizeof(compressed);
 			}
 
 		}
-- 
2.50.1.327.g047016eb4a
Previous: Toon ClaesNext: René Scharfe
Message 2 of 9 in “Fix archiving some corner-case files into zip”
  1. 0/4 Fix archiving some corner-case files into zipToon Claes, Aug 4, 2025
  2. 1/4 archive-zip: deduplicate code setting output buffer in write_zip_entry()Toon Claes, Aug 4, 2025
  3. René ScharfeAug 7, 2025
  4. 2/4 archive-zip: remove unneccesarry condition in write_zip_entry()Toon Claes, Aug 4, 2025
  5. René ScharfeAug 7, 2025
  6. 3/4 archive-zip: in write_zip_entry() call git_deflate() in a loopToon Claes, Aug 4, 2025
  7. René ScharfeAug 7, 2025
  8. 4/4 archive-zip: move git_deflate() with Z_FINISH into the loopToon Claes, Aug 4, 2025
  9. René ScharfeAug 7, 2025

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.