Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Stan, Gary Gregory">CpioArchiveInputStream.getNextEntry() now throws a MemoryLimitException instead of OutOfMemoryError when it can't process input greater than available memory.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">CpioArchiveInputStream.readOldAsciiEntry(boolean) now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">CpioArchiveInputStream.readOldBinaryEntry(boolean) now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" issue="COMPRESS-711" dev="pkarwasz" due-to="Piotr P. Karwasz">Fix checksum calculation in CpioArchiveInputStream when reading with a non-zero offset.</action>
<!-- FIX gzip -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">GzipParameters.setOperatingSystem(int) now throws CompressorException on illegal input.</action>
<action type="fix" issue="COMPRESS-705" dev="ggregory" due-to="Mario Fredenhagen, Gary Gregory">GZip IOException: Extra subfield length exceeds remaining bytes in extra field; use new option GzipCompressorInputStream.Builder.setIgnoreExtraField(boolean).</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ public int read(final byte[] b, final int off, final int len) throws IOException
final int tmpread = readFully(b, off, tmplength);
if (entry.getFormat() == FORMAT_NEW_CRC) {
for (int pos = 0; pos < tmpread; pos++) {
crc += b[pos] & 0xFF;
crc &= 0xFFFFFFFFL;
crc += b[off + pos] & 0xFF;
}
crc &= 0xFFFFFFFFL;
}
if (tmpread > 0) {
entryBytesRead += tmpread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.commons.compress.archivers.cpio;

import static org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -33,6 +34,7 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.Issue;

class CpioArchiveInputStreamTest extends AbstractTest {

Expand Down Expand Up @@ -184,4 +186,19 @@ void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
assertEquals(-1, archive.read());
}
}

@Test
@Issue("https://issues.apache.org/jira/browse/COMPRESS-711")
void testCrcVerification() throws Exception {
try (CpioArchiveInputStream archive = CpioArchiveInputStream.builder().setURI(getURI("bla.cpio")).get()) {
assertNotNull(archive.getNextEntry());
assertDoesNotThrow(() -> {
final byte[] buffer = new byte[1024];
// Read with an offset to test that the right bytes are checksummed
while (archive.read(buffer, 1, 1023) != -1) {
// noop
}
});
}
}
}