commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1296420 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/tar/ test/java/org/apache/commons/compress/archivers/tar/ test/resources/
Date Fri, 02 Mar 2012 19:59:51 GMT
Author: bodewig
Date: Fri Mar  2 19:59:50 2012
New Revision: 1296420

URL: http://svn.apache.org/viewvc?rev=1296420&view=rev
Log:
workaround for tar implementations that insert a NUL byte into header fields.  COMPRESS-181

Added:
    commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar   (with props)
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    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
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.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=1296420&r1=1296419&r2=1296420&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Fri Mar  2 19:59: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-181" type="update" date="2012-03-02">
+        Added a workaround for a Bug some tar implementations that add
+        a NUL byte as first byte in numeric header fields.
+      </action> 
       <action issue="COMPRESS-176" type="update" date="2012-02-28">
         Added a workaround for a Bug in WinZIP which uses backslashes
         as path separators in Unicode Extra Fields.

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=1296420&r1=1296419&r2=1296420&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
Fri Mar  2 19:59:50 2012
@@ -34,13 +34,18 @@ public class TarUtils {
 
     /**
      * Parse an octal string from a buffer.
-     * Leading spaces are ignored.
+     *
+     * <p>Leading spaces are ignored.
      * The buffer must contain a trailing space or NUL,
-     * and may contain an additional trailing space or NUL.
+     * and may contain an additional trailing space or NUL.</p>
      *
-     * The input buffer is allowed to contain all NULs,
+     * <p>The input buffer is allowed to contain all NULs,
      * in which case the method returns 0L
-     * (this allows for missing fields).
+     * (this allows for missing fields).</p>
+     *
+     * <p>To work-around some tar implementations that insert a
+     * leading NUL this method returns 0 if it detects a leading NUL
+     * since Commons Compress 1.4.</p>
      *
      * @param buffer The buffer from which to parse.
      * @param offset The offset into the buffer from which to parse.
@@ -57,14 +62,7 @@ public class TarUtils {
             throw new IllegalArgumentException("Length "+length+" must be at least 2");
         }
 
-        boolean allNUL = true;
-        for (int i = start; i < end; i++){
-            if (buffer[i] != 0){
-                allNUL = false;
-                break;
-            }
-        }
-        if (allNUL) {
+        if (buffer[start] == 0) {
             return 0L;
         }
 

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=1296420&r1=1296419&r2=1296420&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
Fri Mar  2 19:59:50 2012
@@ -18,10 +18,16 @@
 
 package org.apache.commons.compress.archivers.tar;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.StringReader;
+import java.net.URI;
+import java.net.URL;
+import java.util.Date;
 import java.util.Map;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class TarArchiveInputStreamTest {
 
@@ -40,4 +46,23 @@ public class TarArchiveInputStreamTest {
         assertEquals(1, headers.size());
         assertEquals("line1\nline2\nand3", headers.get("comment"));
     }
+
+    @Test
+    public void workaroundForBrokenTimeHeader() throws Exception {
+        URL tar = getClass().getResource("/simple-aix-native-tar.tar");
+        TarArchiveInputStream in = null;
+        try {
+            in = new TarArchiveInputStream(new FileInputStream(new File(new URI(tar.toString()))));
+            TarArchiveEntry tae = in.getNextTarEntry();
+            tae = in.getNextTarEntry();
+            assertEquals("sample/link-to-txt-file.lnk", tae.getName());
+            assertEquals(new Date(0), tae.getLastModifiedDate());
+            assertTrue(tae.isSymbolicLink());
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+    }        
+
 }
\ No newline at end of file

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java?rev=1296420&r1=1296419&r2=1296420&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
Fri Mar  2 19:59:50 2012
@@ -72,12 +72,6 @@ public class TarUtilsTest extends TestCa
             fail("Expected IllegalArgumentException - should be at least 2 bytes long");
         } catch (IllegalArgumentException expected) {
         }
-        buffer=new byte[]{0,0,' '}; // not all NULs
-        try {
-            TarUtils.parseOctal(buffer,0, buffer.length);
-            fail("Expected IllegalArgumentException - not all NULs");
-        } catch (IllegalArgumentException expected) {
-        }
         buffer=new byte[]{' ',0,0,0}; // not all NULs
         try {
             TarUtils.parseOctal(buffer,0, buffer.length);

Added: commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar?rev=1296420&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message