Author: rgoers
Date: Tue Nov  2 04:33:21 2010
New Revision: 1029951

URL: http://svn.apache.org/viewvc?rev=1029951&view=rev
Log:
Fix VFS-322 - Tar files can files over 2GB. Note that the unit test for this is 
slow and creates a 3GB file

Modified:
    commons/proper/vfs/trunk/core/pom.xml
    
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/tar/TarInputStream.java
    commons/proper/vfs/trunk/pom.xml
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/pom.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/pom.xml?rev=1029951&r1=1029950&r2=1029951&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/pom.xml (original)
+++ commons/proper/vfs/trunk/core/pom.xml Tue Nov  2 04:33:21 2010
@@ -51,12 +51,11 @@
       <artifactId>commons-net</artifactId>
       <optional>true</optional>
     </dependency>
-    <!--TODO:Revert to [compress] if/when released
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-compress</artifactId>
-         <optional>true</optional>
-       </dependency-->
+         <scope>test</scope>
+       </dependency>
     <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>

Modified: 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/tar/TarInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/tar/TarInputStream.java?rev=1029951&r1=1029950&r2=1029951&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/tar/TarInputStream.java
 (original)
+++ 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/tar/TarInputStream.java
 Tue Nov  2 04:33:21 2010
@@ -40,7 +40,7 @@ class TarInputStream
     private TarEntry currEntry;
     private boolean debug;
     private int entryOffset;
-    private int entrySize;
+    private long entrySize;
     private boolean hasHitEOF;
     private byte[] oneBuf;
     private byte[] readBuf;
@@ -122,7 +122,7 @@ class TarInputStream
 
         if (currEntry != null)
         {
-            final int numToSkip = entrySize - entryOffset;
+            final long numToSkip = entrySize - entryOffset;
 
             if (debug)
             {
@@ -134,7 +134,8 @@ class TarInputStream
 
             if (numToSkip > 0)
             {
-                skip(numToSkip);
+                // Use our internal skip to move to the end of the current 
entry
+                longSkip(numToSkip);
             }
 
             readBuf = null;
@@ -182,8 +183,7 @@ class TarInputStream
 
             entryOffset = 0;
 
-            // REVIEW How do we resolve this discrepancy?!
-            entrySize = (int) currEntry.getSize();
+            entrySize = currEntry.getSize();
         }
 
         if (null != currEntry && currEntry.isGNULongNameEntry())
@@ -235,7 +235,13 @@ class TarInputStream
     public int available()
             throws IOException
     {
-        return entrySize - entryOffset;
+      long remaining = entrySize - entryOffset;
+      
+      if(remaining > Integer.MAX_VALUE) {
+        return Integer.MAX_VALUE;
+      }
+      
+      return (int) remaining;
     }
 
     /**
@@ -353,7 +359,7 @@ class TarInputStream
 
         if ((numToRead + entryOffset) > entrySize)
         {
-            numToRead = (entrySize - entryOffset);
+            numToRead = (int)(entrySize - entryOffset);
         }
 
         if (null != readBuf)
@@ -428,6 +434,18 @@ class TarInputStream
     {
     }
 
+    public void longSkip(final long numToSkip) throws IOException {
+      for(long skipped = 0; skipped < numToSkip;) {
+        if(numToSkip - skipped > Integer.MAX_VALUE) {
+          skip((int)Integer.MAX_VALUE);
+          skipped += Integer.MAX_VALUE;
+        } else {
+          skip((int)(numToSkip - skipped));
+          skipped += numToSkip - skipped;
+        }
+      }
+    }
+    
     /**
      * Skip bytes in the input buffer. This skips bytes in the current entry's
      * data, not the entire archive, and will stop at the end of the current

Modified: commons/proper/vfs/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/pom.xml?rev=1029951&r1=1029950&r2=1029951&view=diff
==============================================================================
--- commons/proper/vfs/trunk/pom.xml (original)
+++ commons/proper/vfs/trunk/pom.xml Tue Nov  2 04:33:21 2010
@@ -301,7 +301,7 @@
       <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-compress</artifactId>
-        <version>1.0</version>
+        <version>1.1</version>
       </dependency>
       <dependency>
         <groupId>org.apache.jackrabbit</groupId>

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1029951&r1=1029950&r2=1029951&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Tue Nov  2 04:33:21 2010
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0" date="in SVN" description="">
+       <action dev="rgoers" type="fix" issue="VFS-322" due-to="Curtis Boyden">
+        Allow tar files that contain files over 2GB in size.
+      </action>
        <action dev="rgoers" type="fix" issue="VFS-324" due-to="sebb">
         Clear the cache in RamFileSystem and the children in RamFileData.
       </action>


Reply via email to