You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/02/23 01:36:16 UTC
svn commit: r1292596 - in /commons/proper/compress/trunk/src: changes/
main/java/org/apache/commons/compress/archivers/tar/
test/java/org/apache/commons/compress/archivers/tar/
Author: sebb
Date: Thu Feb 23 00:36:15 2012
New Revision: 1292596
URL: http://svn.apache.org/viewvc?rev=1292596&view=rev
Log:
COMPRESS-179 TarUtils.formatLongOctalOrBinaryBytes() assumes the field will be 12 bytes long
Modified:
commons/proper/compress/trunk/src/changes/changes.xml
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.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=1292596&r1=1292595&r2=1292596&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Thu Feb 23 00:36:15 2012
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
<body>
<release version="1.4" date="unreleased"
description="Release 1.4">
+ <action issue="COMPRESS-179" type="fix" date="2012-02-23">
+ TarUtils.formatLongOctalOrBinaryBytes() assumes the field will be 12 bytes long
+ </action>
<action issue="COMPRESS-175" type="fix" date="2012-02-22">
GNU Tar sometimes uses binary encoding for UID and GID
</action>
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java?rev=1292596&r1=1292595&r2=1292596&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java Thu Feb 23 00:36:15 2012
@@ -58,6 +58,13 @@ public interface TarConstants {
int GIDLEN = 8;
/**
+ * The maximum value of gid/uid in a tar archive which can
+ * be expressed in octal char notation (that's 7 sevens, octal).
+ * @since 1.4
+ */
+ long MAXID = 07777777L;
+
+ /**
* The length of the checksum field in a header buffer.
*/
int CHKSUMLEN = 8;
@@ -69,7 +76,8 @@ public interface TarConstants {
int SIZELEN = 12;
/**
- * The maximum size of a file in a tar archive (That's 11 sevens, octal).
+ * The maximum size of a file in a tar archive
+ * which can be expressed in octal char notation (that's 11 sevens, octal).
*/
long MAXSIZE = 077777777777L;
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=1292596&r1=1292595&r2=1292596&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java Thu Feb 23 00:36:15 2012
@@ -324,7 +324,10 @@ public class TarUtils {
public static int formatLongOctalOrBinaryBytes(
final long value, byte[] buf, final int offset, final int length) {
- if (value < TarConstants.MAXSIZE + 1) {
+ // Check whether we are dealing with UID/GID or SIZE field
+ final long maxAsOctalChar = length == TarConstants.UIDLEN ? TarConstants.MAXID : TarConstants.MAXSIZE;
+
+ if (value <= maxAsOctalChar) { // OK to store as octal chars
return formatLongOctalBytes(value, buf, offset, length);
}
Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java?rev=1292596&r1=1292595&r2=1292596&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java Thu Feb 23 00:36:15 2012
@@ -110,20 +110,43 @@ public class TarUtilsTest extends TestCa
}
}
- private void checkRoundTripOctal(final long value) {
- byte [] buffer = new byte[12];
+ private void checkRoundTripOctal(final long value, final int bufsize) {
+ byte [] buffer = new byte[bufsize];
long parseValue;
TarUtils.formatLongOctalBytes(value, buffer, 0, buffer.length);
parseValue = TarUtils.parseOctal(buffer,0, buffer.length);
assertEquals(value,parseValue);
}
+ private void checkRoundTripOctal(final long value) {
+ checkRoundTripOctal(value, TarConstants.SIZELEN);
+ }
+
public void testRoundTripOctal() {
checkRoundTripOctal(0);
checkRoundTripOctal(1);
// checkRoundTripOctal(-1); // TODO What should this do?
- checkRoundTripOctal(077777777777L);
+ checkRoundTripOctal(TarConstants.MAXSIZE);
// checkRoundTripOctal(0100000000000L); // TODO What should this do?
+
+ checkRoundTripOctal(0, TarConstants.UIDLEN);
+ checkRoundTripOctal(1, TarConstants.UIDLEN);
+ checkRoundTripOctal(TarConstants.MAXID, 8);
+ }
+
+ private void checkRoundTripOctalOrBinary(final long value, final int bufsize) {
+ byte [] buffer = new byte[bufsize];
+ long parseValue;
+ TarUtils.formatLongOctalOrBinaryBytes(value, buffer, 0, buffer.length);
+ parseValue = TarUtils.parseOctalOrBinary(buffer,0, buffer.length);
+ assertEquals(value,parseValue);
+ }
+
+ public void testRoundTripOctalOrBinary() {
+ checkRoundTripOctalOrBinary(0, 8);
+ checkRoundTripOctalOrBinary(1, 8);
+ checkRoundTripOctalOrBinary(Long.MAX_VALUE, 8); // [0x7f ff ff ff ff ff ff ff
+ checkRoundTripOctalOrBinary(TarConstants.MAXSIZE, 8); // will need binary format
}
// Check correct trailing bytes are generated