This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: Fix PR libgcj/14446


I'm checking this in on the trunk.

A little more analysis came in for PR libgcj/14446, so I
opportunistically fixed it.  We needed to avoid sign extension when
comparing CRCs; we also needed a fix from Classpath so that
InflaterInputStream.read() correctly went via the decompressor.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR libgcj/14446:
	* java/util/zip/GZIPInputStream.java (read): Avoid sign extension
	when comparing CRCs.
	* java/util/zip/InflaterInputStream.java (onebytebuffer): New
	field.
	(read()): New overload.

Index: java/util/zip/GZIPInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/zip/GZIPInputStream.java,v
retrieving revision 1.9
diff -u -r1.9 GZIPInputStream.java
--- java/util/zip/GZIPInputStream.java 30 Jul 2004 17:00:34 -0000 1.9
+++ java/util/zip/GZIPInputStream.java 22 Sep 2004 20:08:23 -0000
@@ -230,7 +230,9 @@
 	    tmp[i] = (byte) eof_read();
 	  }
 
-	int header_crc = read4(tmp, 0);
+	// Be careful to avoid sign extension here; CRC32.getValue()
+	// returns a long.
+	long header_crc = read4(tmp, 0) & 0xffffffffL;
 	if (crc.getValue() != header_crc)
 	  throw new ZipException("corrupted gzip file - crc mismatch");
 	int isize = read4(tmp, 4);
Index: java/util/zip/InflaterInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/zip/InflaterInputStream.java,v
retrieving revision 1.21
diff -u -r1.21 InflaterInputStream.java
--- java/util/zip/InflaterInputStream.java 30 Jul 2004 17:00:34 -0000 1.21
+++ java/util/zip/InflaterInputStream.java 22 Sep 2004 20:08:23 -0000
@@ -70,6 +70,9 @@
    */
   protected int len;
 
+  // We just use this if we are decoding one byte at a time with the
+  // read() call.
+  private byte[] onebytebuffer = new byte[1];
 
   /**
    * Create an InflaterInputStream with the default decompresseor
@@ -156,6 +159,19 @@
   }
 
   /**
+   * Reads one byte of decompressed data.
+   *
+   * The byte is in the lower 8 bits of the int.
+   */
+  public int read() throws IOException
+  { 
+    int nread = read(onebytebuffer, 0, 1);
+    if (nread > 0)
+      return onebytebuffer[0] & 0xff;
+    return -1;
+  }
+
+  /**
    * Decompresses data into the byte array
    *
    * @param b the array to read and decompress data into


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]