harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r486042 - 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/InflaterTest.java
Date Tue, 12 Dec 2006 05:59:58 GMT
Author: liangyx
Date: Mon Dec 11 21:59:57 2006
New Revision: 486042

URL: http://svn.apache.org/viewvc?view=rev&rev=486042
Log:
HARMONY-2510 ([classlib][archive]Inflater.inflate fails to throw DataFormatException while
the uncompression method is not acceptable.)

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/InflaterTest.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?view=diff&rev=486042&r1=486041&r2=486042
==============================================================================
--- 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
Mon Dec 11 21:59:57 2006
@@ -45,7 +45,11 @@
 	static {
 		oneTimeInitialization();
 	}
-
+    
+    private static final byte MAGIC_NUMBER = 120;
+    private boolean gotFirstByte = false;
+    private boolean pass_magic_number_check = true;
+    
 	/**
 	 * Release any resources associated with this Inflater. Any unused
 	 * input/output is discarded. This is also called by the finalize method.
@@ -175,6 +179,10 @@
                 throw new IllegalStateException();
             }
             
+            if (!pass_magic_number_check) {
+                throw new DataFormatException();
+            }
+
             if (needsInput()) {
                 return 0;
             }
@@ -310,6 +318,12 @@
 			setInputImpl(buf, off, nbytes, streamHandle);
 		} else {
             throw new ArrayIndexOutOfBoundsException();
+        }
+        
+        if(!gotFirstByte && nbytes>0)
+        {
+           pass_magic_number_check = (buf[off] == MAGIC_NUMBER || nbytes > 1);       
   
+           gotFirstByte = true;
         }
 	}
 

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java?view=diff&rev=486042&r1=486041&r2=486042
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
Mon Dec 11 21:59:57 2006
@@ -717,6 +717,18 @@
         Inflater inflater = new Inflater();
         byte[] b = new byte[1024];
         assertEquals(0, inflater.inflate(b));
-        inflater.end();       
-    }
+        inflater.end();
+        
+        // Regression for HARMONY-2510
+        inflater = new Inflater();
+        byte[] input = new byte[] { -1 };
+        inflater.setInput(input);
+        try {
+            inflater.inflate(b);
+            fail("should throw DataFormateException");
+        } catch (DataFormatException e) {
+            // expected
+        }       
+    }   
+    
 }



Mime
View raw message