From e9186fbe67cc6de61ac858e3e3ed0259d61635bb Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 12 Jul 2006 17:00:49 +0000 Subject: [PATCH] re PR libgcj/27271 (i/o error (java.util.zip.ZipException: Deflated stream ends early.)) PR libgcj/27271: * java/util/zip/ZipFile.java (getInputStream): Call addDummyByte on PartialInputStream. (PartialInputStream.dummyByteCount): New field. (PartialInputStream.fillBuffer): Handle dummy byte. (PartialInputStream.read): Likewise. (PartialInputStream.addDummyByte): New method. From-SVN: r115378 --- libjava/classpath/ChangeLog.gcj | 10 +++++++ libjava/classpath/java/util/zip/ZipFile.java | 30 ++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libjava/classpath/ChangeLog.gcj b/libjava/classpath/ChangeLog.gcj index 7304d663d72e..55eab669cb94 100644 --- a/libjava/classpath/ChangeLog.gcj +++ b/libjava/classpath/ChangeLog.gcj @@ -1,3 +1,13 @@ +2006-07-12 Tom Tromey + + PR libgcj/27271: + * java/util/zip/ZipFile.java (getInputStream): Call addDummyByte + on PartialInputStream. + (PartialInputStream.dummyByteCount): New field. + (PartialInputStream.fillBuffer): Handle dummy byte. + (PartialInputStream.read): Likewise. + (PartialInputStream.addDummyByte): New method. + 2006-06-14 Tom Tromey PR java/28024: diff --git a/libjava/classpath/java/util/zip/ZipFile.java b/libjava/classpath/java/util/zip/ZipFile.java index b8495516f16c..10c8365b833d 100644 --- a/libjava/classpath/java/util/zip/ZipFile.java +++ b/libjava/classpath/java/util/zip/ZipFile.java @@ -445,6 +445,7 @@ public class ZipFile implements ZipConstants case ZipOutputStream.STORED: return inp; case ZipOutputStream.DEFLATED: + inp.addDummyByte(); final Inflater inf = new Inflater(true); final int sz = (int) entry.getSize(); return new InflaterInputStream(inp, inf) @@ -520,6 +521,11 @@ public class ZipFile implements ZipConstants private long bufferOffset; private int pos; private long end; + // We may need to supply an extra dummy byte to our reader. + // See Inflater. We use a count here to simplify the logic + // elsewhere in this class. Note that we ignore the dummy + // byte in methods where we know it is not needed. + private int dummyByteCount; public PartialInputStream(RandomAccessFile raf, int bufferSize) throws IOException @@ -540,8 +546,17 @@ public class ZipFile implements ZipConstants { synchronized (raf) { - raf.seek(bufferOffset); - raf.readFully(buffer, 0, (int) Math.min(buffer.length, end - bufferOffset)); + long len = end - bufferOffset; + if (len == 0 && dummyByteCount > 0) + { + buffer[0] = 0; + dummyByteCount = 0; + } + else + { + raf.seek(bufferOffset); + raf.readFully(buffer, 0, (int) Math.min(buffer.length, len)); + } } } @@ -555,7 +570,7 @@ public class ZipFile implements ZipConstants public int read() throws IOException { - if (bufferOffset + pos >= end) + if (bufferOffset + pos >= end + dummyByteCount) return -1; if (pos == buffer.length) { @@ -569,9 +584,9 @@ public class ZipFile implements ZipConstants public int read(byte[] b, int off, int len) throws IOException { - if (len > end - (bufferOffset + pos)) + if (len > end + dummyByteCount - (bufferOffset + pos)) { - len = (int) (end - (bufferOffset + pos)); + len = (int) (end + dummyByteCount - (bufferOffset + pos)); if (len == 0) return -1; } @@ -681,5 +696,10 @@ public class ZipFile implements ZipConstants throw new AssertionError(uee); } } + + public void addDummyByte() + { + dummyByteCount = 1; + } } }