harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r785159 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/Inflater.java test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
Date Tue, 16 Jun 2009 10:54:54 GMT
Author: tellison
Date: Tue Jun 16 10:54:51 2009
New Revision: 785159

URL: http://svn.apache.org/viewvc?rev=785159&view=rev
Log:
Apply patch HARMONY-6210 ([classlib][archive] Inflater.setInput crashes when input is read
1 byte at a time)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java?rev=785159&r1=785158&r2=785159&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
Tue Jun 16 10:54:51 2009
@@ -47,7 +47,7 @@
 
     private boolean finished; // Set by the inflateImpl native
 
-    private boolean gotFirstByte = false;
+    private boolean gotFirstHeaderByte;
 
     int inLength;
 
@@ -78,6 +78,7 @@
      */
     public Inflater(boolean noHeader) {
         streamHandle = createStream(noHeader);
+        gotFirstHeaderByte = noHeader;
     }
 
     private native long createStream(boolean noHeader1);
@@ -395,9 +396,9 @@
             throw new ArrayIndexOutOfBoundsException();
         }
 
-        if (!gotFirstByte && nbytes > 0) {
-            pass_magic_number_check = (buf[off] == MAGIC_NUMBER || nbytes > 1);
-            gotFirstByte = true;
+        if (!gotFirstHeaderByte && nbytes > 0) {
+            pass_magic_number_check = (buf[off] == MAGIC_NUMBER);
+            gotFirstHeaderByte = true;
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java?rev=785159&r1=785158&r2=785159&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
Tue Jun 16 10:54:51 2009
@@ -20,6 +20,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.zip.ZipEntry;
@@ -157,6 +158,26 @@
 	    assertEquals("Failed to read entry", 12, r);
 	}
 
+    public void testReadOneByteAtATime() throws IOException {
+        InputStream in = new FilterInputStream(Support_Resources.getStream("hyts_ZipFile.zip"))
{
+            @Override
+            public int read(byte[] buffer, int offset, int count) throws IOException {
+                return super.read(buffer, offset, 1); // one byte at a time
+            }
+
+            @Override
+            public int read(byte[] buffer) throws IOException {
+                return super.read(buffer, 0, 1); // one byte at a time
+            }
+        };
+
+        zis = new ZipInputStream(in);
+        while ((zentry = zis.getNextEntry()) != null) {
+            zentry.getName();
+        }
+        zis.close();
+    }
+
 	/**
 	 * @tests java.util.zip.ZipInputStream#skip(long)
 	 */



Mime
View raw message