gzip: don't fail when there is exactly one trailing NUL byte
authorDaniel Barkalow <barkalow@iabervon.org>
Sat, 10 Oct 2009 09:35:13 +0000 (11:35 +0200)
committerJim Meyering <meyering@redhat.com>
Sat, 10 Oct 2009 09:35:52 +0000 (11:35 +0200)
* gzip.c (get_method): Require the second byte of magic only if
the first byte was nonzero.

gzip.c

diff --git a/gzip.c b/gzip.c
index 8543128a909e4b156ecc4a14e979c8be21101137..b0f792a876ce1e3a8362b6e2ddd7042cab7e4d8b 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -1266,8 +1266,13 @@ local int get_method(in)
        /* If try_byte returned EOF, magic[1] == (char) EOF.  */
     } else {
        magic[0] = (char)get_byte();
-       magic[1] = (char)get_byte();
-       imagic1 = 0; /* avoid lint warning */
+       if (magic[0]) {
+           magic[1] = (char)get_byte();
+           imagic1 = 0; /* avoid lint warning */
+       } else {
+           imagic1 = try_byte ();
+           magic[1] = (char) imagic1;
+       }
     }
     method = -1;                 /* unknown yet */
     part_nb++;                   /* number of parts in gzip file */