Tim Ellison wrote:
<snip>
FYI here is my hacked available() impl, which needs some testing before
it is good to go in..

With this patch for available() applied the ASN1Exception no longer gets thrown in BerInputStream.read(), but instead an ASN1Exception is thrown in BerInputStream.readSequence() at line 671. The message from this exception is "Mandatory value is missing at [3255]".

Looking in the byte buffer contents, I see that after index 3255 all its values are 0, whereas in M11 they are all populated as expected. It looks like DTD.read() is assuming that its stream.read(enc) call (around line 149) will return a full buffer, but with the new zip changes it does not. Applying a patch something like this (along with Tim's ZipFile patch below) fixes the test failures and I get a clean run of the full swing test suite:

Index: DTD.java
===================================================================
--- DTD.java    (revision 884214)
+++ DTD.java    (working copy)
@@ -142,8 +142,12 @@

    public void read(final DataInputStream stream) throws IOException {
        // converts from DataInputStream into a byte array
-        byte[] enc = new byte[stream.available()];
-        stream.read(enc);
+        int available = stream.available();
+        byte[] enc = new byte[available];
+        int readBytes = 0;
+        while (readBytes != available) {
+ readBytes += stream.read(enc, readBytes, available - readBytes); + }
        // decode the byte array
        Asn1Dtd asn1 = new Asn1Dtd(enc);

Regards,
Oliver


Index: src/main/java/java/util/zip/ZipFile.java
===================================================================
--- src/main/java/java/util/zip/ZipFile.java    (revision 884543)
+++ src/main/java/java/util/zip/ZipFile.java    (working copy)
@@ -247,7 +247,7 @@
             rafstrm.skip(entry.nameLen + localExtraLenOrWhatever);
             rafstrm.mLength = rafstrm.mOffset + entry.compressedSize;
             if (entry.compressionMethod == ZipEntry.DEFLATED) {
-                return new InflaterInputStream(rafstrm, new
Inflater(true));
+                return new ZipInflaterInputStream(rafstrm, new
Inflater(true), 1024, entry);
             } else {
                 return rafstrm;
             }
@@ -415,4 +415,27 @@
             return n;
         }
     }
+
+    static class ZipInflaterInputStream extends InflaterInputStream {
+
+        ZipEntry entry;
+        long bytesRead = 0;
+
+        public ZipInflaterInputStream(InputStream is, Inflater inf, int
bsize, ZipEntry entry) {
+            super(is, inf, bsize);
+            this.entry = entry;
+        }
+
+        public int read(byte[] buffer, int off, int nbytes) throws
IOException {
+            int i = super.read(buffer, off, nbytes);
+            if (i != -1) {
+                bytesRead += i;
+            }
+            return i;
+        }
+
+        public int available() throws IOException {
+            return super.available() == 0 ? 0 : (int) (entry.getSize()
- bytesRead);
+        }
+    }
 }




--
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

Reply via email to