harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r483368 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/Deflater.java test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
Date Thu, 07 Dec 2006 07:47:55 GMT
Author: liangyx
Date: Wed Dec  6 23:47:52 2006
New Revision: 483368

URL: http://svn.apache.org/viewvc?view=rev&rev=483368
Log:
Apply patch for HARMONY-2481 ([classlib][archive]Memory access violation occurs in native
hyzip.lib if Deflater.deflate() is called before Deflater.setInput())

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

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Deflater.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Deflater.java?view=diff&rev=483368&r1=483367&r2=483368
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Deflater.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Deflater.java
Wed Dec  6 23:47:52 2006
@@ -48,6 +48,9 @@
     
     // Fill in the JNI id caches
     private static native void oneTimeInitialization();
+    
+    // A stub buffer used when deflate() called while inputBuffer has not been set.
+    private static final byte[] STUB_INPUT_BUFFER = new byte[0];
 
     static {
         oneTimeInitialization();
@@ -140,9 +143,13 @@
 		if (streamHandle == -1) {
             throw new IllegalStateException();
         }
-		// avoid int overflow, check null buf
-		if (off <= buf.length && nbytes >= 0 && off >= 0
-				&& buf.length - off >= nbytes) {
+        // avoid int overflow, check null buf
+        if (off <= buf.length && nbytes >= 0 && off >= 0
+                && buf.length - off >= nbytes) {
+            // put a stub buffer, no effect.
+            if (null == inputBuffer) {
+                setInput(STUB_INPUT_BUFFER);
+            }
             return deflateImpl(buf, off, nbytes, streamHandle, flushParm);
         }
 		throw new ArrayIndexOutOfBoundsException();

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java?view=diff&rev=483368&r1=483367&r2=483368
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
Wed Dec  6 23:47:52 2006
@@ -1245,4 +1245,16 @@
         assertEquals(compressedDataLength, def.getTotalOut());
         assertEquals(compressedDataLength, def.getBytesWritten());
     }
+    
+    //Regression Test for HARMONY-2481
+    public void test_deflate_beforeSetInput() throws Exception {
+        Deflater deflater = new Deflater();
+        deflater.finish();
+        byte[] buffer = new byte[1024];
+        assertEquals(8, deflater.deflate(buffer));
+        byte[] expectedBytes = { 120, -100, 3, 0, 0, 0, 0, 1 };
+        for (int i = 0; i < expectedBytes.length; i++) {
+            assertEquals(expectedBytes[i], buffer[i]);
+        }
+    }
 }



Mime
View raw message