ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1488951 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW contributors.xml src/main/org/apache/tools/tar/TarConstants.java src/main/org/apache/tools/tar/TarEntry.java src/main/org/apache/tools/tar/TarInputStream.java
Date Mon, 03 Jun 2013 10:21:30 GMT
Author: bodewig
Date: Mon Jun  3 10:21:30 2013
New Revision: 1488951

URL: http://svn.apache.org/r1488951
Log:
propely handle GNU longlink entries, PR 55040, submitted by Christoph Gysin

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java   (contents, props changed)
    ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java   (contents, props changed)
    ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java   (contents, props changed)

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/CONTRIBUTORS (original)
+++ ant/core/trunk/CONTRIBUTORS Mon Jun  3 10:21:30 2013
@@ -50,6 +50,7 @@ Charles Hudak
 Charlie Hubbard
 Chris Povirk
 Christian Knorr
+Christoph Gysin
 Christoph Wilhelms
 Christophe Labouisse
 Christopher A. Longo

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Jun  3 10:21:30 2013
@@ -12,6 +12,9 @@ Fixed bugs:
    be able to read archives created by DotNetZip and maybe other
    archivers as well.
 
+ * TarInputStream should now properly read GNU longlink entries' names.
+   Bugzilla Report 55040.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Mon Jun  3 10:21:30 2013
@@ -223,6 +223,10 @@
   </name>
   <name>
     <first>Christoph</first>
+    <last>Gysin</last>
+  </name>
+  <name>
+    <first>Christoph</first>
     <last>Wilhelms</last>
   </name>
   <name>

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java Mon Jun  3 10:21:30 2013
@@ -238,6 +238,11 @@ public interface TarConstants {
     byte   LF_CONTIG = (byte) '7';
 
     /**
+     * Identifies the *next* file on the tape as having a long linkname.
+     */
+    byte LF_GNUTYPE_LONGLINK = (byte) 'K';
+
+    /**
      * Identifies the *next* file on the tape as having a long name.
      */
     byte LF_GNUTYPE_LONGNAME = (byte) 'L';

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarConstants.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Jun  3 10:21:30 2013
@@ -0,0 +1 @@
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java:1488935-1488936

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java Mon Jun  3 10:21:30 2013
@@ -653,6 +653,16 @@ public class TarEntry implements TarCons
     }
 
     /**
+     * Indicate if this entry is a GNU long linkname block
+     *
+     * @return true if this is a long name extension provided by GNU tar
+     */
+    public boolean isGNULongLinkEntry() {
+        return linkFlag == LF_GNUTYPE_LONGLINK
+            && name.equals(GNU_LONGLINK);
+    }
+
+    /**
      * Indicate if this entry is a GNU long name block
      *
      * @return true if this is a long name extension provided by GNU tar

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java
------------------------------------------------------------------------------
  Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java:r1488935-1488936

Modified: ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java?rev=1488951&r1=1488950&r2=1488951&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java Mon Jun  3 10:21:30 2013
@@ -303,31 +303,25 @@ public class TarInputStream extends Filt
         entryOffset = 0;
         entrySize = currEntry.getSize();
 
-        if (currEntry.isGNULongNameEntry()) {
-            // read in the name
-            ByteArrayOutputStream longName = new ByteArrayOutputStream();
-            int length = 0;
-            while ((length = read(SMALL_BUF)) >= 0) {
-                longName.write(SMALL_BUF, 0, length);
-            }
-            getNextEntry();
-            if (currEntry == null) {
+        if (currEntry.isGNULongLinkEntry()) {
+            byte[] longLinkData = getLongNameData();
+            if (longLinkData == null) {
                 // Bugzilla: 40334
-                // Malformed tar file - long entry name not followed by entry
+                // Malformed tar file - long link entry name not followed by
+                // entry
                 return null;
             }
-            byte[] longNameData = longName.toByteArray();
-            // remove trailing null terminator(s)
-            length = longNameData.length;
-            while (length > 0 && longNameData[length - 1] == 0) {
-                --length;
-            }
-            if (length != longNameData.length) {
-                byte[] l = new byte[length];
-                System.arraycopy(longNameData, 0, l, 0, length);
-                longNameData = l;
+            currEntry.setLinkName(encoding.decode(longLinkData));
+        }
+
+        if (currEntry.isGNULongNameEntry()) {
+            byte[] longNameData = getLongNameData();
+            if (longNameData == null) {
+                // Bugzilla: 40334
+                // Malformed tar file - long entry name not followed by
+                // entry
+                return null;
             }
-            
             currEntry.setName(encoding.decode(longNameData));
         }
 
@@ -348,6 +342,39 @@ public class TarInputStream extends Filt
     }
 
     /**
+     * Get the next entry in this tar archive as longname data.
+     *
+     * @return The next entry in the archive as longname data, or null.
+     * @throws IOException on error
+     */
+    protected byte[] getLongNameData() throws IOException {
+        // read in the name
+        ByteArrayOutputStream longName = new ByteArrayOutputStream();
+        int length = 0;
+        while ((length = read(SMALL_BUF)) >= 0) {
+            longName.write(SMALL_BUF, 0, length);
+        }
+        getNextEntry();
+        if (currEntry == null) {
+            // Bugzilla: 40334
+            // Malformed tar file - long entry name not followed by entry
+            return null;
+        }
+        byte[] longNameData = longName.toByteArray();
+        // remove trailing null terminator(s)
+        length = longNameData.length;
+        while (length > 0 && longNameData[length - 1] == 0) {
+            --length;
+        }
+        if (length != longNameData.length) {
+            byte[] l = new byte[length];
+            System.arraycopy(longNameData, 0, l, 0, length);
+            longNameData = l;
+        }
+        return longNameData;
+    }
+
+    /**
      * Get the next record in this tar archive. This will skip
      * over any remaining data in the current entry, if there
      * is one, and place the input stream at the header of the

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java
------------------------------------------------------------------------------
  Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java:r1488935-1488936,1488947



Mime
View raw message