commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1427353 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: UnsupportedZipFeatureException.java ZipArchiveInputStream.java ZipLong.java
Date Tue, 01 Jan 2013 10:51:42 GMT
Author: bodewig
Date: Tue Jan  1 10:51:42 2013
New Revision: 1427353

URL: http://svn.apache.org/viewvc?rev=1427353&view=rev
Log:
explicitly fail when ZipArchiveInputStream reads a split/spanned archive

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java?rev=1427353&r1=1427352&r2=1427353&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
Tue Jan  1 10:51:42 2013
@@ -29,7 +29,7 @@ public class UnsupportedZipFeatureExcept
 
     private final Feature reason;
     private final ZipArchiveEntry entry;
-    private static final long serialVersionUID = 4430521921766595597L;
+    private static final long serialVersionUID = 20130101L;
 
     /**
      * Creates an exception.
@@ -60,6 +60,18 @@ public class UnsupportedZipFeatureExcept
     }
 
     /**
+     * Creates an exception when the whole archive uses an unsupported
+     * feature.
+     *
+     * @param reason the feature that is not supported
+     */
+    public UnsupportedZipFeatureException(Feature reason) {
+        super("unsupported feature " + reason +  " used in archive.");
+        this.reason = reason;
+        this.entry = null;
+    }
+
+    /**
      * The unsupported feature that has been used.
      */
     public Feature getFeature() {
@@ -90,6 +102,11 @@ public class UnsupportedZipFeatureExcept
          * The entry uses a data descriptor.
          */
         public static final Feature DATA_DESCRIPTOR = new Feature("data descriptor");
+        /**
+         * The archive uses splitting or spanning.
+         * @since 1.5
+         */
+        public static final Feature SPLITTING = new Feature("splitting");
 
         private final String name;
 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1427353&r1=1427352&r2=1427353&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Tue Jan  1 10:51:42 2013
@@ -174,18 +174,30 @@ public class ZipArchiveInputStream exten
     }
 
     public ZipArchiveEntry getNextZipEntry() throws IOException {
+        boolean firstEntry = true;
         if (closed || hitCentralDirectory) {
             return null;
         }
         if (current != null) {
             closeEntry();
+            firstEntry = false;
         }
+
         byte[] lfh = new byte[LFH_LEN];
         try {
-            readFully(lfh);
+            if (firstEntry) {
+                // split archives have a special signature before the
+                // first local file header - look for it and fail with
+                // the appropriate error message if this is a split
+                // archive.
+                readFirstLocalFileHeader(lfh);
+            } else {
+                readFully(lfh);
+            }
         } catch (EOFException e) {
             return null;
         }
+            
         ZipLong sig = new ZipLong(lfh);
         if (sig.equals(ZipLong.CFH_SIG)) {
             hitCentralDirectory = true;
@@ -258,6 +270,21 @@ public class ZipArchiveInputStream exten
     }
 
     /**
+     * Fills the given array with the first local file header and
+     * deals with splitting/spanning markers that may prefix the first
+     * LFH.
+     */
+    private void readFirstLocalFileHeader(byte[] lfh) throws IOException {
+        readFully(lfh);
+        ZipLong sig = new ZipLong(lfh);
+        if (sig.equals(ZipLong.DD_SIG)) {
+            throw new 
+                UnsupportedZipFeatureException(UnsupportedZipFeatureException
+                                               .Feature.SPLITTING);
+        }
+    }
+
+    /**
      * Records whether a Zip64 extra is present and sets the size
      * information from it if sizes are 0xFFFFFFFF and the entry
      * doesn't use a data descriptor.

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java?rev=1427353&r1=1427352&r2=1427353&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
Tue Jan  1 10:51:42 2013
@@ -50,7 +50,11 @@ public final class ZipLong implements Cl
     public static final ZipLong LFH_SIG = new ZipLong(0X04034B50L);
 
     /**
-     * Data Descriptor signature
+     * Data Descriptor signature.
+     *
+     * <p>Actually, PKWARE uses this as marker for split/spanned
+     * archives and other archivers have started to use it as Data
+     * Descriptor signature (as well).</p>
      * @since 1.1
      */
     public static final ZipLong DD_SIG = new ZipLong(0X08074B50L);



Mime
View raw message