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 2014/06/21 07:06:25 UTC

git commit: PR 56641 cannot read entries with empty gid/uid anymore

Repository: ant
Updated Branches:
  refs/heads/master 7472cb03e -> 34fdc2f62


PR 56641 <untar> cannot read entries with empty gid/uid anymore

manually merging
http://svn.apache.org/viewvc?view=revision&revision=1588618 from
Commons Compress


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/34fdc2f6
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/34fdc2f6
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/34fdc2f6

Branch: refs/heads/master
Commit: 34fdc2f62a8e282875c134c78aaf14105af92cf9
Parents: 7472cb0
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Jun 21 07:05:20 2014 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Jun 21 07:05:30 2014 +0200

----------------------------------------------------------------------
 WHATSNEW                                    |  4 ++++
 src/main/org/apache/tools/tar/TarUtils.java | 22 +++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/34fdc2f6/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 74e79b4..c8fbe50 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -7,6 +7,10 @@ Changes that could break older environments:
 Fixed bugs:
 -----------
 
+* TarArchiveInputStream failed to read archives with empty gid/uid
+  fields.
+  Bugzilla Report 56641
+
 Other changes:
 --------------
 

http://git-wip-us.apache.org/repos/asf/ant/blob/34fdc2f6/src/main/org/apache/tools/tar/TarUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/tar/TarUtils.java b/src/main/org/apache/tools/tar/TarUtils.java
index cc41063..264ff99 100644
--- a/src/main/org/apache/tools/tar/TarUtils.java
+++ b/src/main/org/apache/tools/tar/TarUtils.java
@@ -60,7 +60,7 @@ public class TarUtils {
 
             public String decode(byte[] buffer) {
                 final int length = buffer.length;
-                StringBuffer result = new StringBuffer(length);
+                StringBuilder result = new StringBuilder(length);
 
                 for (int i = 0; i < length; ++i) {
                     byte b = buffer[i];
@@ -130,10 +130,6 @@ public class TarUtils {
             end--;
             trailer = buffer[end - 1];
         }
-        if (start == end) {
-            throw new IllegalArgumentException(
-                    exceptionMessage(buffer, offset, length, start, trailer));
-        }
 
         for ( ;start < end; start++) {
             final byte currentByte = buffer[start];
@@ -194,7 +190,7 @@ public class TarUtils {
         if (negative) {
             // 2's complement
             val--;
-            val ^= ((long) Math.pow(2, (length - 1) * 8) - 1);
+            val ^= (long) Math.pow(2, (length - 1) * 8) - 1;
         }
         return negative ? -val : val;
     }
@@ -236,7 +232,15 @@ public class TarUtils {
     // Helper method to generate the exception message
     private static String exceptionMessage(byte[] buffer, final int offset,
             final int length, int current, final byte currentByte) {
-        String string = new String(buffer, offset, length); // TODO default charset?
+        // default charset is good enough for an exception message,
+        //
+        // the alternative was to modify parseOctal and
+        // parseOctalOrBinary to receive the ZipEncoding of the
+        // archive (deprecating the existing public methods, of
+        // course) and dealing with the fact that ZipEncoding#decode
+        // can throw an IOException which parseOctal* doesn't declare
+        String string = new String(buffer, offset, length);
+
         string=string.replaceAll("\0", "{NUL}"); // Replace NULs to allow string to be printed
         final String s = "Invalid byte "+currentByte+" at offset "+(current-offset)+" in '"+string+"' len="+length;
         return s;
@@ -549,8 +553,8 @@ public class TarUtils {
     public static long computeCheckSum(final byte[] buf) {
         long sum = 0;
 
-        for (int i = 0; i < buf.length; ++i) {
-            sum += BYTE_MASK & buf[i];
+        for (byte element : buf) {
+            sum += BYTE_MASK & element;
         }
 
         return sum;