commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1548937 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/arj/ archivers/sevenz/ utils/
Date Sat, 07 Dec 2013 16:03:55 GMT
Author: bodewig
Date: Sat Dec  7 16:03:54 2013
New Revision: 1548937

URL: http://svn.apache.org/r1548937
Log:
CRC32 is supposed to be an unsigned int

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/LocalFileHeader.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Archive.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Folder.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SubStreamsInfo.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
Sat Dec  7 16:03:54 2013
@@ -142,10 +142,10 @@ public class ArjArchiveInputStream exten
             if (basicHeaderSize <= 2600) {
                 basicHeaderBytes = new byte[basicHeaderSize];
                 readFully(in, basicHeaderBytes);
-                final int basicHeaderCrc32 = read32(in);
+                final long basicHeaderCrc32 = read32(in) & 0xFFFFFFFFL;
                 final CRC32 crc32 = new CRC32();
                 crc32.update(basicHeaderBytes);
-                if (basicHeaderCrc32 == (int)crc32.getValue()) {
+                if (basicHeaderCrc32 == crc32.getValue()) {
                     found = true;
                 }
             }
@@ -199,10 +199,10 @@ public class ArjArchiveInputStream exten
         if (extendedHeaderSize > 0) {
             mainHeader.extendedHeaderBytes = new byte[extendedHeaderSize];
             readFully(in, mainHeader.extendedHeaderBytes);
-            final int extendedHeaderCrc32 = read32(in);
+            final long extendedHeaderCrc32 = 0xffffFFFFL & read32(in);
             final CRC32 crc32 = new CRC32();
             crc32.update(mainHeader.extendedHeaderBytes);
-            if (extendedHeaderCrc32 != (int)crc32.getValue()) {
+            if (extendedHeaderCrc32 != crc32.getValue()) {
                 throw new IOException("Extended header CRC32 verification failure");
             }
         }
@@ -235,7 +235,7 @@ public class ArjArchiveInputStream exten
         localFileHeader.dateTimeModified = read32(firstHeader);
         localFileHeader.compressedSize = 0xffffFFFFL & read32(firstHeader);
         localFileHeader.originalSize = 0xffffFFFFL & read32(firstHeader);
-        localFileHeader.originalCrc32 = read32(firstHeader);
+        localFileHeader.originalCrc32 = 0xffffFFFFL & read32(firstHeader);
         localFileHeader.fileSpecPosition = read16(firstHeader);
         localFileHeader.fileAccessMode = read16(firstHeader);
         pushedBackBytes(20);
@@ -252,10 +252,10 @@ public class ArjArchiveInputStream exten
         while ((extendedHeaderSize = read16(in)) > 0) {
             final byte[] extendedHeaderBytes = new byte[extendedHeaderSize];
             readFully(in, extendedHeaderBytes);
-            final int extendedHeaderCrc32 = read32(in);
+            final long extendedHeaderCrc32 = 0xffffFFFFL & read32(in);
             final CRC32 crc32 = new CRC32();
             crc32.update(extendedHeaderBytes);
-            if (extendedHeaderCrc32 != (int)crc32.getValue()) {
+            if (extendedHeaderCrc32 != crc32.getValue()) {
                 throw new IOException("Extended header CRC32 verification failure");
             }
             extendedHeaders.add(extendedHeaderBytes);

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/LocalFileHeader.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/LocalFileHeader.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/LocalFileHeader.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/LocalFileHeader.java
Sat Dec  7 16:03:54 2013
@@ -30,7 +30,7 @@ class LocalFileHeader {
     int dateTimeModified;
     long compressedSize;
     long originalSize;
-    int originalCrc32;
+    long originalCrc32;
     int fileSpecPosition;
     int fileAccessMode;
     int firstChapter;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Archive.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Archive.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Archive.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Archive.java
Sat Dec  7 16:03:54 2013
@@ -27,7 +27,7 @@ class Archive {
     /// Whether each particular packed streams has a CRC.
     BitSet packCrcsDefined;
     /// CRCs for each packed stream, valid only if that packed stream has one.
-    int[] packCrcs;
+    long[] packCrcs;
     /// Properties of solid compression blocks.
     Folder[] folders;
     /// Temporary properties for non-empty files (subsumed into the files array later).

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Folder.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Folder.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Folder.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Folder.java
Sat Dec  7 16:03:54 2013
@@ -37,7 +37,7 @@ class Folder {
     /// Whether the folder has a CRC.
     boolean hasCrc;
     /// The CRC, if present.
-    int crc;
+    long crc;
     /// The number of unpack substreams, one per non-empty file in this folder.
     int numUnpackSubStreams;
 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
Sat Dec  7 16:03:54 2013
@@ -43,7 +43,7 @@ public class SevenZArchiveEntry implemen
     private boolean hasWindowsAttributes;
     private int windowsAttributes;
     private boolean hasCrc;
-    private int crc, compressedCrc;
+    private long crc, compressedCrc;
     private long size, compressedSize;
     
     public SevenZArchiveEntry() {
@@ -303,33 +303,69 @@ public class SevenZArchiveEntry implemen
 
     /**
      * Gets the CRC.
+     * @deprecated use getCrcValue instead.
      */
     public int getCrc() {
-        return crc;
+        return (int) crc;
     }
 
     /**
      * Sets the CRC.
+     * @deprecated use setCrcValue instead.
      */
     public void setCrc(int crc) {
         this.crc = crc;
     }
 
     /**
+     * Gets the CRC.
+     * @since Compress 1.7
+     */
+    public long getCrcValue() {
+        return crc;
+    }
+
+    /**
+     * Sets the CRC.
+     * @since Compress 1.7
+     */
+    public void setCrcValue(long crc) {
+        this.crc = crc;
+    }
+
+    /**
      * Gets the compressed CRC.
+     * @deprecated use getCompressedCrcValue instead.
      */
     int getCompressedCrc() {
-        return compressedCrc;
+        return (int) compressedCrc;
     }
 
     /**
      * Sets the compressed CRC.
+     * @deprecated use setCompressedCrcValue instead.
      */
     void setCompressedCrc(int crc) {
         this.compressedCrc = crc;
     }
 
     /**
+     * Gets the compressed CRC.
+     * @since Compress 1.7
+     */
+    long getCompressedCrcValue() {
+        return compressedCrc;
+    }
+
+    /**
+     * Sets the compressed CRC.
+     * @since Compress 1.7
+     */
+    void setCompressedCrcValue(long crc) {
+        this.compressedCrc = crc;
+    }
+
+    /**
      * Get this entry's file size.
      *
      * @return This entry's file size.

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
Sat Dec  7 16:03:54 2013
@@ -165,7 +165,7 @@ public class SevenZFile {
                     archiveVersionMajor, archiveVersionMinor));
         }
 
-        final int startHeaderCrc = Integer.reverseBytes(file.readInt());
+        final long startHeaderCrc = 0xffffFFFFL & Integer.reverseBytes(file.readInt());
         final StartHeader startHeader = readStartHeader(startHeaderCrc);
         
         final int nextHeaderSizeInt = (int) startHeader.nextHeaderSize;
@@ -177,7 +177,7 @@ public class SevenZFile {
         file.readFully(nextHeader);
         final CRC32 crc = new CRC32();
         crc.update(nextHeader);
-        if (startHeader.nextHeaderCrc != (int) crc.getValue()) {
+        if (startHeader.nextHeaderCrc != crc.getValue()) {
             throw new IOException("NextHeader CRC mismatch");
         }
         
@@ -202,7 +202,7 @@ public class SevenZFile {
         return archive;
     }
     
-    private StartHeader readStartHeader(final int startHeaderCrc) throws IOException {
+    private StartHeader readStartHeader(final long startHeaderCrc) throws IOException {
         final StartHeader startHeader = new StartHeader();
         DataInputStream dataInputStream = null;
         try {
@@ -210,7 +210,7 @@ public class SevenZFile {
                     new BoundedRandomAccessFileInputStream(file, 20), 20, startHeaderCrc));
              startHeader.nextHeaderOffset = Long.reverseBytes(dataInputStream.readLong());
              startHeader.nextHeaderSize = Long.reverseBytes(dataInputStream.readLong());
-             startHeader.nextHeaderCrc = Integer.reverseBytes(dataInputStream.readInt());
+             startHeader.nextHeaderCrc = 0xffffFFFFL & Integer.reverseBytes(dataInputStream.readInt());
              return startHeader;
         } finally {
             if (dataInputStream != null) {
@@ -331,10 +331,10 @@ public class SevenZFile {
         
         if (nid == NID.kCRC) {
             archive.packCrcsDefined = readAllOrBits(header, (int)numPackStreams);
-            archive.packCrcs = new int[(int)numPackStreams];
+            archive.packCrcs = new long[(int)numPackStreams];
             for (int i = 0; i < (int)numPackStreams; i++) {
                 if (archive.packCrcsDefined.get(i)) {
-                    archive.packCrcs[i] = Integer.reverseBytes(header.readInt());
+                    archive.packCrcs[i] = 0xffffFFFFL & Integer.reverseBytes(header.readInt());
                 }
             }
             
@@ -380,7 +380,7 @@ public class SevenZFile {
             for (int i = 0; i < (int)numFolders; i++) {
                 if (crcsDefined.get(i)) {
                     folders[i].hasCrc = true;
-                    folders[i].crc = Integer.reverseBytes(header.readInt());
+                    folders[i].crc = 0xffffFFFFL & Integer.reverseBytes(header.readInt());
                 } else {
                     folders[i].hasCrc = false;
                 }
@@ -414,7 +414,7 @@ public class SevenZFile {
         final SubStreamsInfo subStreamsInfo = new SubStreamsInfo();
         subStreamsInfo.unpackSizes = new long[totalUnpackStreams];
         subStreamsInfo.hasCrc = new BitSet(totalUnpackStreams);
-        subStreamsInfo.crcs = new int[totalUnpackStreams];
+        subStreamsInfo.crcs = new long[totalUnpackStreams];
         
         int nextUnpackStream = 0;
         for (final Folder folder : archive.folders) {
@@ -444,10 +444,10 @@ public class SevenZFile {
         
         if (nid == NID.kCRC) {
             final BitSet hasMissingCrc = readAllOrBits(header, numDigests);
-            final int[] missingCrcs = new int[numDigests];
+            final long[] missingCrcs = new long[numDigests];
             for (int i = 0; i < numDigests; i++) {
                 if (hasMissingCrc.get(i)) {
-                    missingCrcs[i] = Integer.reverseBytes(header.readInt());
+                    missingCrcs[i] = 0xffffFFFFL & Integer.reverseBytes(header.readInt());
                 }
             }
             int nextCrc = 0;
@@ -725,7 +725,7 @@ public class SevenZFile {
                 files[i].setDirectory(false);
                 files[i].setAntiItem(false);
                 files[i].setHasCrc(archive.subStreamsInfo.hasCrc.get(nonEmptyFileCounter));
-                files[i].setCrc(archive.subStreamsInfo.crcs[nonEmptyFileCounter]);
+                files[i].setCrcValue(archive.subStreamsInfo.crcs[nonEmptyFileCounter]);
                 files[i].setSize(archive.subStreamsInfo.unpackSizes[nonEmptyFileCounter]);
                 ++nonEmptyFileCounter;
             } else {
@@ -821,7 +821,7 @@ public class SevenZFile {
                 currentFolderInputStream, file.getSize());
         if (file.getHasCrc()) {
             currentEntryInputStream = new CRC32VerifyingInputStream(
-                    fileStream, file.getSize(), file.getCrc());
+                    fileStream, file.getSize(), file.getCrcValue());
         } else {
             currentEntryInputStream = fileStream;
         }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
Sat Dec  7 16:03:54 2013
@@ -131,8 +131,8 @@ public class SevenZOutputFile {
             ++numNonEmptyStreams;
             entry.setSize(currentOutputStream.getBytesWritten());
             entry.setCompressedSize(fileBytesWritten);
-            entry.setCrc((int) crc32.getValue());
-            entry.setCompressedCrc((int) compressedCrc32.getValue());
+            entry.setCrcValue(crc32.getValue());
+            entry.setCompressedCrcValue(compressedCrc32.getValue());
             entry.setHasCrc(true);
         } else {
             entry.setHasStream(false);
@@ -219,7 +219,7 @@ public class SevenZOutputFile {
         final byte[] startHeaderBytes = startHeaderBaos.toByteArray();
         crc32.reset();
         crc32.update(startHeaderBytes);
-        file.writeInt(Integer.reverseBytes((int)crc32.getValue()));
+        file.writeInt(Integer.reverseBytes((int) crc32.getValue()));
         file.write(startHeaderBytes);
     }
     
@@ -299,7 +299,7 @@ public class SevenZOutputFile {
         header.write(1);
         for (final SevenZArchiveEntry entry : files) {
             if (entry.hasStream()) {
-                header.writeInt(Integer.reverseBytes(entry.getCompressedCrc()));
+                header.writeInt(Integer.reverseBytes((int) entry.getCompressedCrcValue()));
             }
         }
         
@@ -327,7 +327,7 @@ public class SevenZOutputFile {
         header.write(1);
         for (final SevenZArchiveEntry entry : files) {
             if (entry.hasStream()) {
-                header.writeInt(Integer.reverseBytes(entry.getCrc()));
+                header.writeInt(Integer.reverseBytes((int) entry.getCrcValue()));
             }
         }
         

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/StartHeader.java
Sat Dec  7 16:03:54 2013
@@ -20,5 +20,5 @@ package org.apache.commons.compress.arch
 class StartHeader {
     long nextHeaderOffset;
     long nextHeaderSize;
-    int nextHeaderCrc;
+    long nextHeaderCrc;
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SubStreamsInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SubStreamsInfo.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SubStreamsInfo.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SubStreamsInfo.java
Sat Dec  7 16:03:54 2013
@@ -26,5 +26,5 @@ class SubStreamsInfo {
     /// Whether CRC is present for each unpacked stream.
     BitSet hasCrc;
     /// CRCs of unpacked streams, if present.
-    int[] crcs;
+    long[] crcs;
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.java?rev=1548937&r1=1548936&r2=1548937&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/CRC32VerifyingInputStream.java
Sat Dec  7 16:03:54 2013
@@ -30,10 +30,10 @@ import java.util.zip.CRC32;
 public class CRC32VerifyingInputStream extends InputStream {
     private final InputStream in;
     private long bytesRemaining;
-    private final int expectedCrc32;
+    private final long expectedCrc32;
     private final CRC32 crc32 = new CRC32();
     
-    public CRC32VerifyingInputStream(final InputStream in, final long size, final int expectedCrc32)
{
+    public CRC32VerifyingInputStream(final InputStream in, final long size, final long expectedCrc32)
{
         this.in = in;
         this.expectedCrc32 = expectedCrc32;
         this.bytesRemaining = size;
@@ -55,7 +55,7 @@ public class CRC32VerifyingInputStream e
             crc32.update(ret);
             --bytesRemaining;
         }
-        if (bytesRemaining == 0 && expectedCrc32 != (int)crc32.getValue()) {
+        if (bytesRemaining == 0 && expectedCrc32 != crc32.getValue()) {
             throw new IOException("CRC32 verification failed");
         }
         return ret;
@@ -85,7 +85,7 @@ public class CRC32VerifyingInputStream e
             crc32.update(b, off, ret);
             bytesRemaining -= ret;
         }
-        if (bytesRemaining <= 0 && expectedCrc32 != (int)crc32.getValue()) {
+        if (bytesRemaining <= 0 && expectedCrc32 != crc32.getValue()) {
             throw new IOException("CRC32 verification failed");
         }
         return ret;



Mime
View raw message