You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2013/01/05 08:04:13 UTC

svn commit: r1429212 - /ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java

Author: bodewig
Date: Sat Jan  5 07:04:13 2013
New Revision: 1429212

URL: http://svn.apache.org/viewvc?rev=1429212&view=rev
Log:
another fix from commons - tar doesn't use specified encoding when reading GNU long names

Modified:
    ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java   (contents, props changed)

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=1429212&r1=1429211&r2=1429212&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 Sat Jan  5 07:04:13 2013
@@ -302,11 +302,11 @@ public class TarInputStream extends Filt
 
         if (currEntry.isGNULongNameEntry()) {
             // read in the name
-            StringBuffer longName = new StringBuffer();
+            ByteArrayOutputStream longName = new ByteArrayOutputStream();
             byte[] buf = new byte[SMALL_BUFFER_SIZE];
             int length = 0;
             while ((length = read(buf)) >= 0) {
-                longName.append(new String(buf, 0, length)); // TODO default charset?
+                longName.write(buf, 0, length);
             }
             getNextEntry();
             if (currEntry == null) {
@@ -314,12 +314,19 @@ public class TarInputStream extends Filt
                 // Malformed tar file - long entry name not followed by entry
                 return null;
             }
-            // remove trailing null terminator
-            if (longName.length() > 0
-                && longName.charAt(longName.length() - 1) == 0) {
-                longName.deleteCharAt(longName.length() - 1);
+            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.setName(longName.toString());
+            
+            currEntry.setName(encoding.decode(longNameData));
         }
 
         if (currEntry.isPaxHeader()){ // Process Pax headers

Propchange: ant/core/trunk/src/main/org/apache/tools/tar/TarInputStream.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sat Jan  5 07:04:13 2013
@@ -0,0 +1 @@
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java:1428942