jar and zip fixes

Mark Wielaard mark@klomp.org
Mon Oct 27 00:46:00 GMT 2003


Hi,

The kaffe hackers found a bug in the reading of jar manifests for which
Helmer Kraemer found the fix. While testing a new Mauve test for this
issue I found a bug in the interaction between ZipOutStream and
DeflaterOutputStream which caused the size and crc to not be correctly
updated when write(int) was used, since in those cases the overridden
method write(byte[], int, int) was not called.

The following fixes both issues:

2003-10-26  Mark Wielaard  <mark@klomp.org>

        Reported by Helmer Kraemer <hkraemer@freenet.de>
        * java/util/jar/JarInputStream.java (readManifest): Don't call
        closeEntry().

        * java/util/zip/DeflaterOutputStream.java (inbufWrite): New method.
        (finish): Use inbufWrite().
        (write(int)): Likewise.
        (write(byte[],int,int)): Likewise.

OK to commit?

There is still one zip related failure in mauve:
FAIL: gnu.testlet.java.util.zip.InflaterInputStream.basic: compressing string (number 2)
But this is caused by incorrect PrintStream flushing. I have not yet
looked for a fix.

Cheers,

Mark
-------------- next part --------------
? java/util/zip/DeflaterOutputStream.java.fixed
Index: java/util/jar/JarInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/jar/JarInputStream.java,v
retrieving revision 1.7
diff -u -r1.7 JarInputStream.java
--- java/util/jar/JarInputStream.java	22 Jan 2002 22:40:41 -0000	1.7
+++ java/util/jar/JarInputStream.java	27 Oct 2003 00:37:17 -0000
@@ -116,7 +116,6 @@
 	  }
 	firstEntry = (JarEntry) super.getNextEntry();
       }
-    closeEntry();
 
     if (verify)
       {
Index: java/util/zip/DeflaterOutputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/zip/DeflaterOutputStream.java,v
retrieving revision 1.9
diff -u -r1.9 DeflaterOutputStream.java
--- java/util/zip/DeflaterOutputStream.java	27 May 2003 06:34:29 -0000	1.9
+++ java/util/zip/DeflaterOutputStream.java	27 Oct 2003 00:37:17 -0000
@@ -127,12 +127,7 @@
    */
   public void finish () throws IOException
   {
-    if (inbufLength > 0)
-      {
-	def.setInput (inbuf, 0, inbufLength);
-	deflate ();
-	inbufLength = 0;
-      }
+    inbufWrite();
     def.finish();
     while (! def.finished ())
       {
@@ -145,28 +140,27 @@
   public void write (int bval) throws IOException
   {
     if (inbuf == null)
-      {
-	inbuf = new byte[128];
-      }
+      inbuf = new byte[128];
     else if (inbufLength == inbuf.length)
-      {
-	def.setInput (inbuf, 0, inbufLength);
-	deflate ();
-	inbufLength = 0;
-      }
+      inbufWrite ();
     inbuf[inbufLength++] = (byte) bval;
   }
 
   public void write (byte[] buf, int off, int len) throws IOException
   {
+    inbufWrite ();
+    def.setInput (buf, off, len);
+    deflate ();
+  }
+
+  private void inbufWrite () throws IOException
+  {
     if (inbufLength > 0)
       {
-	def.setInput (inbuf, 0, inbufLength);
-	deflate ();
+	int size = inbufLength;
 	inbufLength = 0;
+	write (inbuf, 0, size);
       }
-    def.setInput (buf, off, len);
-    deflate ();
   }
 
   // Used, if needed, for write(int).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20031027/a7e660c2/attachment.sig>


More information about the Java-patches mailing list