harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r964042 - in /harmony/enhanced/java/trunk/classlib: modules/archive/src/main/java/java/util/zip/ modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ support/src/test/java/tests/resources/
Date Wed, 14 Jul 2010 13:28:33 GMT
Author: hindessm
Date: Wed Jul 14 13:28:33 2010
New Revision: 964042

URL: http://svn.apache.org/viewvc?rev=964042&view=rev
Log:
Applying patches from "[#HARMONY-6384] Jar decoding breaks upon
encountering a Z_SYNC_FLUSH block".

Added:
    harmony/enhanced/java/trunk/classlib/support/src/test/java/tests/resources/hyts_flushed.jar
  (with props)
Modified:
    harmony/enhanced/java/trunk/classlib/modules/archive/src/main/java/java/util/zip/ZipFile.java
    harmony/enhanced/java/trunk/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/archive/src/main/java/java/util/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/archive/src/main/java/java/util/zip/ZipFile.java?rev=964042&r1=964041&r2=964042&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/archive/src/main/java/java/util/zip/ZipFile.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/archive/src/main/java/java/util/zip/ZipFile.java
Wed Jul 14 13:28:33 2010
@@ -347,8 +347,28 @@ public class ZipFile implements ZipConst
 
         /*
          * Seek to the first CDE and read all entries.
+         * However, when Z_SYNC_FLUSH is used the offset may not point directly
+         * to the CDE so skip over until we find it. 
+         * At most it will be 6 bytes away (one or two bytes for empty block, 4 bytes for
+         * empty block signature).  
          */
-        rafs = new RAFStream(mRaf, centralDirOffset);
+        scanOffset = centralDirOffset;
+        stopOffset = scanOffset + 6;
+        
+        while (true) {
+            mRaf.seek(scanOffset);
+            if (ZipEntry.readIntLE(mRaf) == CENSIG) {
+                break;
+            }
+
+            scanOffset++;
+            if (scanOffset > stopOffset) {
+                throw new ZipException(Messages.getString("archive.3A"));
+            }
+        }
+        
+        // If CDE is found then go and read all the entries
+        rafs = new RAFStream(mRaf, scanOffset);
         bin = new BufferedInputStream(rafs, 4096);
         for (int i = 0; i < numEntries; i++) {
             ZipEntry newEntry = new ZipEntry(ler, bin);

Modified: harmony/enhanced/java/trunk/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java?rev=964042&r1=964041&r2=964042&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
Wed Jul 14 13:28:33 2010
@@ -661,4 +661,12 @@ public class JarFileTest extends TestCas
         res = jarFile.getInputStream(zipEntry).read();
         assertEquals("Wrong length of empty jar entry", -1, res);
     }
+
+    public void testJarWrittenWithFlush() throws IOException {
+        File f = new File(resources, "hyts_flushed.jar");
+        Support_Resources.copyFile(resources, null, "hyts_flushed.jar");
+
+        // Harmony crashes with ZipException: Central Directory Entry not found
+        new JarFile(f);
+    }
 }

Added: harmony/enhanced/java/trunk/classlib/support/src/test/java/tests/resources/hyts_flushed.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/support/src/test/java/tests/resources/hyts_flushed.jar?rev=964042&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/java/trunk/classlib/support/src/test/java/tests/resources/hyts_flushed.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message