commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r741476 - in /commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers: ./ ar/ cpio/ jar/ tar/ zip/
Date Fri, 06 Feb 2009 08:59:15 GMT
Author: bodewig
Date: Fri Feb  6 08:59:14 2009
New Revision: 741476

URL: http://svn.apache.org/viewvc?rev=741476&view=rev
Log:
use length of signature read when trying to match input stream formats

Modified:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Fri Feb  6 08:59:14 2009
@@ -82,18 +82,17 @@
         input.mark(signature.length);
         int signatureLength = input.read(signature);
         // TODO if reset is not supported pass on the IOException or return null?
-        // TODO, what if we failed to read 12 bytes?
         input.reset();
 
-        if(ZipArchiveInputStream.matches(signature)) {
+        if(ZipArchiveInputStream.matches(signature, signatureLength)) {
             return new ZipArchiveInputStream(input);
-        } else if(JarArchiveInputStream.matches(signature)) {
+        } else if(JarArchiveInputStream.matches(signature, signatureLength)) {
             return new JarArchiveInputStream(input);
-        } else if(TarArchiveInputStream.matches(signature)) {
+        } else if(TarArchiveInputStream.matches(signature, signatureLength)) {
             return new TarArchiveInputStream(input);
-        } else if(ArArchiveInputStream.matches(signature)) {
+        } else if(ArArchiveInputStream.matches(signature, signatureLength)) {
             return new ArArchiveInputStream(input);
-        } else if(CpioArchiveInputStream.matches(signature)) {
+        } else if(CpioArchiveInputStream.matches(signature, signatureLength)) {
             return new CpioArchiveInputStream(input);
         } 
         return null;

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Fri Feb  6 08:59:14 2009
@@ -108,9 +108,12 @@
         return ret;
     }
         
-    public static boolean matches( byte[] signature ) {
+    public static boolean matches(byte[] signature, int length) {
         // 3c21 7261 6863 0a3e
         
+        if (length < 8) {
+            return false;
+        }
         if (signature[0] != 0x21) {
             return false;
         }

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
Fri Feb  6 08:59:14 2009
@@ -442,9 +442,12 @@
         return (ArchiveEntry)entry;
     }
         
-    public static boolean matches( byte[] signature ) {
+    public static boolean matches(byte[] signature, int length) {
         // 3037 3037 30
         
+        if (length < 5) {
+            return false;
+        }
         if (signature[0] != 0x30) {
             return false;
         }

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java
Fri Feb  6 08:59:14 2009
@@ -40,9 +40,13 @@
         }
     }
         
-    public static boolean matches( byte[] signature ) {
+    public static boolean matches(byte[] signature, int length ) {
         // 4b50 0403 0014 0008
 
+        if (length < 8) {
+            return false;
+        }
+
         if (signature[0] != 0x50) {
             return false;
         }

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
Fri Feb  6 08:59:14 2009
@@ -44,9 +44,13 @@
         return in.read();
     }
     
-    public static boolean matches( byte[] signature ) {
+    public static boolean matches(byte[] signature, int length) {
         // 6574 7473 2e31 6d78
         
+        if (length < 8) {
+            return false;
+        }
+
         if (signature[0] != 0x74) {
             return false;
         }

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=741476&r1=741475&r2=741476&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Fri Feb  6 08:59:14 2009
@@ -53,6 +53,10 @@
     public static boolean matches( byte[] signature, int length ) {
         // 4b50 0403 0014 0000
 
+        if (length < 8) {
+            return false;
+        }
+
         if (signature[0] != 0x50) {
             return false;
         }



Mime
View raw message