You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2012/03/09 18:29:02 UTC

svn commit: r1298934 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java

Author: bodewig
Date: Fri Mar  9 17:29:01 2012
New Revision: 1298934

URL: http://svn.apache.org/viewvc?rev=1298934&view=rev
Log:
make sure 'too big' messages for fields that can't be represented in ustar headers are consistent

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=1298934&r1=1298933&r2=1298934&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Fri Mar  9 17:29:01 2012
@@ -470,52 +470,28 @@ public class TarArchiveOutputStream exte
             paxHeaders.put("SCHILY.devminor",
                            String.valueOf(entry.getDevMinor()));
         }
-        if (entry.getMode() > TarConstants.MAXID) {
-            throw new RuntimeException("mode '" + entry.getMode()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
-        }
+        failForBigNumber("mode", entry.getMode(), TarConstants.MAXID);
     }
 
     private void failForBigNumbers(TarArchiveEntry entry) {
-        if (entry.getSize() > TarConstants.MAXSIZE) {
-            throw new RuntimeException("file size '" + entry.getSize()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXSIZE + " bytes)");
-        }
-        if (entry.getGroupId() > TarConstants.MAXID) {
-            throw new RuntimeException("group id '" + entry.getGroupId()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
-        }
-        final long mtime =  entry.getModTime().getTime() / 1000;
-        if (mtime < 0 || mtime > TarConstants.MAXSIZE) {
-            throw new RuntimeException("last modification time '"
-                                       + entry.getModTime()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXSIZE + " bytes)");
-        }
-        if (entry.getUserId() > TarConstants.MAXID) {
-            throw new RuntimeException("user id '" + entry.getUserId()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
-        }
-        if (entry.getMode() > TarConstants.MAXID) {
-            throw new RuntimeException("mode '" + entry.getMode()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
-        }
-        if (entry.getDevMajor() > TarConstants.MAXID) {
-            throw new RuntimeException("major device number '"
-                                       + entry.getDevMajor()
-                                       + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
-        }
-        if (entry.getDevMinor() > TarConstants.MAXID) {
-            throw new RuntimeException("minor device number '"
-                                       + entry.getDevMinor()
+        failForBigNumber("entry size", entry.getSize(), TarConstants.MAXSIZE);
+        failForBigNumber("group id", entry.getGroupId(), TarConstants.MAXID);
+        failForBigNumber("last modification time",
+                         entry.getModTime().getTime() / 1000,
+                         TarConstants.MAXSIZE);
+        failForBigNumber("user id", entry.getUserId(), TarConstants.MAXID);
+        failForBigNumber("mode", entry.getMode(), TarConstants.MAXID);
+        failForBigNumber("major device number", entry.getDevMajor(),
+                         TarConstants.MAXID);
+        failForBigNumber("minor device number", entry.getDevMinor(),
+                         TarConstants.MAXID);
+    }
+
+    private void failForBigNumber(String field, long value, long maxValue) {
+        if (value < 0 || value > maxValue) {
+            throw new RuntimeException(field + " '" + value
                                        + "' is too big ( > "
-                                       + TarConstants.MAXID + " bytes)");
+                                       + maxValue + " )");
         }
     }
 }