ensure CPIO only uses the least-significant 32bit of CRC

https://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt

> The CRC format is identical to the new ASCII format described in the previous 
> section except that the magic field is set to ``070702'' and the check field 
> is set to the sum of all bytes in the file data. This sum is computed 
> treating all bytes as unsigned values and using unsigned arithmetic. Only the 
> least-significant 32 bits of the sum are stored.


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b893471b
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b893471b
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b893471b

Branch: refs/heads/master
Commit: b893471b95285cc2364e3b2b8f6220ac6dc362a4
Parents: 44d376b
Author: Stefan Bodewig <bode...@apache.org>
Authored: Wed Mar 29 14:32:40 2017 +0200
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Wed Mar 29 14:32:40 2017 +0200

----------------------------------------------------------------------
 .../apache/commons/compress/archivers/cpio/CpioArchiveEntry.java | 4 ++--
 .../commons/compress/archivers/cpio/CpioArchiveOutputStream.java | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b893471b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
 
b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
index f625dcf..e5675f0 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
@@ -376,7 +376,7 @@ public class CpioArchiveEntry implements CpioConstants, 
ArchiveEntry {
      */
     public long getChksum() {
         checkNewFormat();
-        return this.chksum;
+        return this.chksum & 0xFFFFFFFFL;
     }
 
     /**
@@ -679,7 +679,7 @@ public class CpioArchiveEntry implements CpioConstants, 
ArchiveEntry {
      */
     public void setChksum(final long chksum) {
         checkNewFormat();
-        this.chksum = chksum;
+        this.chksum = chksum & 0xFFFFFFFFL;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b893471b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
index 02a53b8..88ec07e 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
@@ -434,6 +434,7 @@ public class CpioArchiveOutputStream extends 
ArchiveOutputStream implements
         if (this.entry.getFormat() == FORMAT_NEW_CRC) {
             for (int pos = 0; pos < len; pos++) {
                 this.crc += b[pos] & 0xFF;
+                this.crc &= 0xFFFFFFFFL;
             }
         }
         count(len);

Reply via email to