Author: bodewig
Date: Wed Dec  7 11:34:34 2011
New Revision: 1211393

URL: http://svn.apache.org/viewvc?rev=1211393&view=rev
Log:
Allow PAX headers to set sizes bigger than 8GiB.  COMPRESS-163.  Based on patch 
by John Kodis

Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
    
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java?rev=1211393&r1=1211392&r2=1211393&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
 Wed Dec  7 11:34:34 2011
@@ -572,6 +572,20 @@ public class TarArchiveEntry implements 
     }
 
     /**
+     * Set this entry's file size.
+     *
+     * <p>Invoked by input stream when reading a PAX header.</p>
+     * @throws IllegalArgumentException if the size is &lt; 0
+     * @since Apache Commons Compress 1.4
+     */
+    void adjustSize(long size) {
+        if (size < 0){
+            throw new IllegalArgumentException("Size is out of range: " + 
size);
+        }
+        this.size = size;
+    }
+
+    /**
      * Indicates in case of a sparse file if an extension sparse header
      * follows.
      *

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=1211393&r1=1211392&r2=1211393&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 Wed Dec  7 11:34:34 2011
@@ -229,6 +229,11 @@ public class TarArchiveInputStream exten
             readGNUSparse();
         }
 
+        // If the size of the next element in the archive has changed
+        // due to a new size being reported in the posix header
+        // information, we update entrySize here so that it contains
+        // the correct value.
+        entrySize = currEntry.getSize();
         return currEntry;
     }
 
@@ -341,7 +346,7 @@ public class TarArchiveInputStream exten
             } else if ("uname".equals(key)){
                 currEntry.setUserName(val);
             } else if ("size".equals(key)){
-                currEntry.setSize(Long.parseLong(val));
+                currEntry.adjustSize(Long.parseLong(val));
             }
         }
     }

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java?rev=1211393&r1=1211392&r2=1211393&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
 Wed Dec  7 11:34:34 2011
@@ -115,4 +115,17 @@ public class TarArchiveEntryTest extends
         } catch (IllegalArgumentException expected) {
         }
     }
+
+    public void testAdjustFileSize(){
+        TarArchiveEntry t = new TarArchiveEntry("");
+        t.adjustSize(0);
+        t.adjustSize(1);
+        try {
+            t.adjustSize(-1);
+            fail("Should have generated IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+        }
+        t.adjustSize(077777777777L);
+        t.adjustSize(0100000000000L);
+    }
 }


Reply via email to