commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1148784 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Date Wed, 20 Jul 2011 14:23:21 GMT
Author: bodewig
Date: Wed Jul 20 14:23:20 2011
New Revision: 1148784

URL: http://svn.apache.org/viewvc?rev=1148784&view=rev
Log:
AR entries may contain blanks in groupId or userId.  Submitted by Treykaz.  COMPRESS-140

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1148784&r1=1148783&r2=1148784&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Wed Jul 20 14:23:20 2011
@@ -45,6 +45,11 @@ The <action> type attribute can be add,u
   </properties>
   <body>
     <release version="1.2" date="as in SVN" description="Release 1.2">
+      <action issue="COMPRESS-140" type="fix" date="2011-07-20"
+              due-to="Trejkaz">
+        ArArchiveInputStream fails if entries contain only blanks for
+        userId or groupId.
+      </action> 
       <action issue="COMPRESS-139" type="fix" date="2011-07-13">
         ZipFile may leak resources on some JDKs.
       </action> 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java?rev=1148784&r1=1148783&r2=1148784&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
Wed Jul 20 14:23:20 2011
@@ -47,6 +47,8 @@ import org.apache.commons.compress.archi
  * and file names with a bigger size than 16 bytes are not possible at the
  * moment.
  * 
+ * @see http://www.freebsd.org/cgi/man.cgi?query=ar&sektion=5
+ *
  * @Immutable
  */
 public class ArArchiveEntry implements ArchiveEntry {

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=1148784&r1=1148783&r2=1148784&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Wed Jul 20 14:23:20 2011
@@ -36,16 +36,16 @@ public class ArArchiveInputStream extend
     private final InputStream input;
     private long offset = 0;
     private boolean closed;
-    
+
     /*
      * If getNextEnxtry has been called, the entry metadata is stored in
      * currentEntry.
      */
     private ArArchiveEntry currentEntry = null;
-    
+
     // Storage area for extra long names (GNU ar)
     private byte[] namebuffer = null;
-    
+
     /*
      * The offset where the current entry started. -1 if no entry has been
      * called
@@ -145,7 +145,7 @@ public class ArArchiveInputStream extend
 
         // entry name is stored as ASCII string
         String temp = ArchiveUtils.toAsciiString(name).trim();
-        
+
         if (temp.equals("//")){ // GNU extended filenames entry
             int bufflen = asInt(length); // Assume length will fit in an int
             namebuffer = new byte[bufflen];
@@ -161,8 +161,8 @@ public class ArArchiveInputStream extend
             int offset = Integer.parseInt(temp.substring(1));// get the offset
             temp = getExtendedName(offset); // convert to the long name
         }
-        currentEntry = new ArArchiveEntry(temp, asLong(length), asInt(userid),
-                                          asInt(groupid), asInt(filemode, 8),
+        currentEntry = new ArArchiveEntry(temp, asLong(length), asInt(userid, true),
+                                          asInt(groupid, true), asInt(filemode, 8),
                                           asLong(lastmodified));
         return currentEntry;
     }
@@ -193,11 +193,23 @@ public class ArArchiveInputStream extend
     }
 
     private int asInt(byte[] input) {
-        return asInt(input, 10);
+        return asInt(input, 10, false);
+    }
+
+    private int asInt(byte[] input, boolean treatBlankAsZero) {
+        return asInt(input, 10, treatBlankAsZero);
     }
 
     private int asInt(byte[] input, int base) {
-        return Integer.parseInt(new String(input).trim(), base);
+        return asInt(input, base, false);
+    }
+
+    private int asInt(byte[] input, int base, boolean treatBlankAsZero) {
+        String string = new String(input).trim();
+        if (string.length() == 0 && treatBlankAsZero) {
+            return 0;
+        }
+        return Integer.parseInt(string, base);
     }
 
     /*



Mime
View raw message