From a9ae24b6538a8c75b13826ef8a2547344fd2e08c Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sat, 24 Sep 2011 10:26:07 -0700 Subject: Change gzread() and related to ignore junk after gzip streams. Previously the new gz* functions (introduced in 1.2.4) would read and return raw data after the last gzip stream. This is inconsistent with the behavior of gzip and the previous versions of zlib. Now when one or more gzip streams have been decoded from the file, which is then followed by data that is not a gzip stream (as detemined by not finding the magic header), then that subsequent trailing garbage is ignored, and no error is returned. --- gzread.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gzread.c') diff --git a/gzread.c b/gzread.c index 8fc2915..213ad8c 100644 --- a/gzread.c +++ b/gzread.c @@ -207,6 +207,15 @@ local int gz_head(state) } } + /* no gzip header -- if we were decoding gzip before, then this is trailing + garbage. Ignore the trailing garbage and finish. */ + if (state->direct == 0) { + strm->avail_in = 0; + state->eof = 1; + state->have = 0; + return 0; + } + /* doing raw i/o, save start of raw data for seeking, copy any leftover input to output -- this assumes that the output buffer is larger than the input buffer, which also assures space for gzungetc() */ -- cgit v1.2.3-55-g6feb