COMPRESS-335 yet another strange case of tar checksum
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a513026..5612f69 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,10 @@
<body>
<release version="1.11" date="not released, yet"
description="Release 1.11">
+ <action issue="COMPRESS-335" type="fix" date="2016-02-05">
+ checksums of tars that pad the checksum field to the left are
+ now calculated properly.
+ </action>
<action issue="COMPRESS-334" type="fix" date="2016-02-05"
due-to="Jeremy Gustie">
ArArchiveInputStream failed to read past the first entry when
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
index 65088eb..204debf 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
@@ -591,7 +591,7 @@
* @since 1.5
*/
public static boolean verifyCheckSum(byte[] header) {
- long storedSum = 0;
+ long storedSum = parseOctal(header, CHKSUM_OFFSET, CHKSUMLEN);
long unsignedSum = 0;
long signedSum = 0;
@@ -599,11 +599,6 @@
for (int i = 0; i < header.length; i++) {
byte b = header[i];
if (CHKSUM_OFFSET <= i && i < CHKSUM_OFFSET + CHKSUMLEN) {
- if ('0' <= b && b <= '7' && digits++ < 6) {
- storedSum = storedSum * 8 + b - '0';
- } else if (digits > 0) {
- digits = 6; // only look at the first octal digit sequence
- }
b = ' ';
}
unsignedSum += 0xff & b;
diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
index ad18902..8e1e7bf 100644
--- a/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
+++ b/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
@@ -56,6 +56,13 @@
}
@Test
+ public void testCOMPRESS335() throws Exception {
+ final ArchiveInputStream tar = getStreamFor("COMPRESS-335.tar");
+ assertNotNull(tar);
+ assertTrue(tar instanceof TarArchiveInputStream);
+ }
+
+ @Test
public void testDetection() throws Exception {
final ArchiveInputStream ar = getStreamFor("bla.ar");
diff --git a/src/test/resources/COMPRESS-335.tar b/src/test/resources/COMPRESS-335.tar
new file mode 100644
index 0000000..0266b63
--- /dev/null
+++ b/src/test/resources/COMPRESS-335.tar
Binary files differ