[Toybox] [PATCH] Follow RFC1952 when consuming gzip header

Puck Meerburg puck at puck.moe
Sun Dec 13 10:33:13 PST 2020


The FEXTRA field, indicated by bit 2 of the flag byte, contains
arbitrary extra data, prefixed by a 16-bit length value. The previous
code skipped over the length, but not the actual contents, breaking
decompression of certain files.
---
 lib/deflate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-------------- next part --------------
>From d41029bd74a707d4dfd8b6a5d2095c53f3f97244 Mon Sep 17 00:00:00 2001
From: Puck Meerburg <puck at puck.moe>
Date: Sun, 13 Dec 2020 18:27:08 +0000
Subject: [PATCH] Follow RFC1952 when consuming gzip header

The FEXTRA field, indicated by bit 2 of the flag byte, contains
arbitrary extra data, prefixed by a 16-bit length value. The previous
code skipped over the length, but not the actual contents, breaking
decompression of certain files.
---
 lib/deflate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/deflate.c b/lib/deflate.c
index eebcd3de..8c724429 100644
--- a/lib/deflate.c
+++ b/lib/deflate.c
@@ -403,7 +403,7 @@ static int is_gzip(struct bitbuf *bb)
   bitbuf_skip(bb, 6*8);
 
   // Skip extra, name, comment, header CRC fields
-  if (flags & 4) bitbuf_skip(bb, 16);
+  if (flags & 4) bitbuf_skip(bb, bitbuf_get(bb, 16) * 8);
   if (flags & 8) while (bitbuf_get(bb, 8));
   if (flags & 16) while (bitbuf_get(bb, 8));
   if (flags & 2) bitbuf_skip(bb, 16);
-- 
2.26.2



More information about the Toybox mailing list