commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1369655 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/TarUtils.java test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java test/resources/COMPRESS-197.tar
Date Sun, 05 Aug 2012 19:51:15 GMT
Author: jukka
Date: Sun Aug  5 19:51:15 2012
New Revision: 1369655

URL: http://svn.apache.org/viewvc?rev=1369655&view=rev
Log:
COMPRESS-197: Tar file for Android backup cannot be read

Allow more than one or two NUL or space characters at the end of a field

Added:
    commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=1369655&r1=1369654&r2=1369655&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
Sun Aug  5 19:51:15 2012
@@ -130,10 +130,11 @@ public class TarUtils {
             throw new IllegalArgumentException(
                     exceptionMessage(buffer, offset, length, end-1, trailer));
         }
-        // May have additional NUL or space
-        trailer = buffer[end-1];
-        if (trailer == 0 || trailer == ' '){
+        // May have additional NULs or spaces
+        trailer = buffer[end - 1];
+        while (start < end - 1 && (trailer == 0 || trailer == ' ')) {
             end--;
+            trailer = buffer[end - 1];
         }
 
         for ( ;start < end; start++) {

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java?rev=1369655&r1=1369654&r2=1369655&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
Sun Aug  5 19:51:15 2012
@@ -20,10 +20,12 @@ package org.apache.commons.compress.arch
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
 import java.util.Calendar;
@@ -120,4 +122,24 @@ public class TarArchiveInputStreamTest {
         }
     }
 
-}
\ No newline at end of file
+    @Test
+    public void testCompress197() throws Exception {
+        TarArchiveInputStream tar = getTestStream("/COMPRESS-197.tar");
+        try {
+            TarArchiveEntry entry = tar.getNextTarEntry();
+            while (entry != null) {
+                entry = tar.getNextTarEntry();
+            }
+        } catch (IOException e) {
+            fail("COMPRESS-197: " + e.getMessage());
+        } finally {
+            tar.close();
+        }
+    }
+
+    private TarArchiveInputStream getTestStream(String name) {
+        return new TarArchiveInputStream(
+                TarArchiveInputStreamTest.class.getResourceAsStream(name));
+    }
+
+}

Added: commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar?rev=1369655&view=auto
==============================================================================
Files commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar (added) and commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
Sun Aug  5 19:51:15 2012 differ



Mime
View raw message