You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2012/01/29 21:56:50 UTC

svn commit: r1237475 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java

Author: bodewig
Date: Sun Jan 29 20:56:50 2012
New Revision: 1237475

URL: http://svn.apache.org/viewvc?rev=1237475&view=rev
Log:
Only assume a TAR is a TAR if it at least contains one 512 byte block.  COMPRESS-171

Added:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java   (with props)
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1237475&r1=1237474&r2=1237475&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sun Jan 29 20:56:50 2012
@@ -46,6 +46,10 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.4" date="unreleased"
              description="Release 1.4">
+      <action issue="COMPRESS-171" type="fix" date="2012-01-29">
+        ArchiveStreamFactory.createArchiveInputStream would claim
+        short text files were TAR archives.
+      </action> 
       <action issue="COMPRESS-156" type="add" date="2011-11-02">
         Support for the XZ format has been added.
       </action> 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=1237475&r1=1237474&r2=1237475&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java Sun Jan 29 20:56:50 2012
@@ -237,6 +237,7 @@ public class ArchiveStreamFactory {
                 return new TarArchiveInputStream(in);
             }
             // COMPRESS-117 - improve auto-recognition
+            if (signatureLength >= 512) {
             try {
                 TarArchiveInputStream tais = new TarArchiveInputStream(new ByteArrayInputStream(tarheader));
                 tais.getNextEntry();
@@ -246,6 +247,7 @@ public class ArchiveStreamFactory {
                 // autodetection, simply not a TAR
                 // ignored
             }
+            }
         } catch (IOException e) {
             throw new ArchiveException("Could not use reset and mark operations.", e);
         }

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java?rev=1237475&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java (added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java Sun Jan 29 20:56:50 2012
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.archivers;
+
+import java.io.ByteArrayInputStream;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class ArchiveStreamFactoryTest {
+
+    /**
+     * see https://issues.apache.org/jira/browse/COMPRESS-171
+     */
+    @Test
+    public void shortTextFilesAreNoTARs() throws Exception {
+        try {
+            new ArchiveStreamFactory()
+                .createArchiveInputStream(new ByteArrayInputStream("This certainly is not a tar archive, really, no kidding".getBytes()));
+            fail("created an input stream for a non-archive");
+        } catch (ArchiveException ae) {
+            assertTrue(ae.getMessage().startsWith("No Archiver found"));
+        }
+    }
+
+}
\ No newline at end of file

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native