This is the mail archive of the
java-patches@sources.redhat.com
mailing list for the Java project.
ZIP: Treat Z_BUF_ERROR as end of stream
- To: java-patches at sources dot redhat dot com
- Subject: ZIP: Treat Z_BUF_ERROR as end of stream
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Mon, 18 Dec 2000 14:00:56 +1300
I discovered a problem with our Inflater and some zip files. zlib
would return Z_BUF_ERROR after completing decompression if avail_in
was 0. I think this has to do with not providing an extra padding byte
at the end of the input stream when using the no header zlib option.
This seems to fix it.
regards
[ bryce ]
2000-12-18 Bryce McKinlay <bryce@albatross.co.nz>
* java/util/zip/natInflater.cc (inflate): Treat Z_BUF_ERROR as
end-of-stream if avail_in is 0.
Index: natInflater.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/zip/natInflater.cc,v
retrieving revision 1.7
diff -u -r1.7 natInflater.cc
--- natInflater.cc 2000/05/20 23:30:46 1.7
+++ natInflater.cc 2000/12/18 00:49:06
@@ -106,6 +106,16 @@
switch (::inflate (s, Z_SYNC_FLUSH))
{
+ case Z_BUF_ERROR:
+ /* Using the no_header option, zlib requires an extra padding byte at the
+ end of the stream in order to successfully complete decompression (see
+ zlib/contrib/minizip/unzip.c). We don't do this, so can end up with a
+ Z_BUF_ERROR at the end of a stream when zlib has completed inflation
+ and there's no more input. Thats not a problem. */
+ if (s->avail_in != 0)
+ throw new java::lang::InternalError;
+ // Fall through.
+
case Z_STREAM_END:
is_finished = true;
if (s->avail_out == (unsigned int) len)
@@ -123,11 +133,6 @@
case Z_MEM_ERROR:
_Jv_Throw (new java::lang::OutOfMemoryError);
- break;
-
- case Z_BUF_ERROR:
- // FIXME?
- _Jv_Throw (new java::lang::InternalError);
break;
case Z_OK: