Skip to content

Commit c43928b

Browse files
committed
CpioArchiveInputStream.read(byte[], int, int) now throws an IOException
on a data pad count mismatch
1 parent 477abdd commit c43928b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The <action> type attribute can be add,update,fix,remove.
5959
<action type="fix" dev="ggregory" due-to="Gary Gregory">ZipArchiveOutputStream.close() does not close its underlying output stream.</action>
6060
<action type="fix" dev="ggregory" due-to="Gary Gregory">Don't use deprecated code in TarArchiveInputStream.</action>
6161
<action type="fix" dev="ggregory" due-to="Gary Gregory">Don't use deprecated code in TarFile.</action>
62+
<action type="fix" dev="ggregory" due-to="Gary Gregory">CpioArchiveInputStream.read(byte[], int, int) now throws an IOException on a data pad count mismatch.</action>
6263
<!-- ADD -->
6364
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
6465
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>

src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ public int read(final byte[] b, final int off, final int len) throws IOException
325325
return -1;
326326
}
327327
if (this.entryBytesRead == this.entry.getSize()) {
328-
skip(entry.getDataPadCount());
328+
final int dataPadCount = entry.getDataPadCount();
329+
if (skip(dataPadCount) != dataPadCount) {
330+
throw new IOException("Data pad count missmatch.");
331+
}
329332
this.entryEOF = true;
330333
if (this.entry.getFormat() == FORMAT_NEW_CRC && this.crc != this.entry.getChksum()) {
331334
throw new IOException("CRC Error. Occurred at byte: " + getBytesRead());
@@ -492,11 +495,9 @@ private byte[] readRange(final int len) throws IOException {
492495
return b;
493496
}
494497

495-
private void skip(final int bytes) throws IOException {
498+
private int skip(final int length) throws IOException {
496499
// bytes cannot be more than 3 bytes
497-
if (bytes > 0) {
498-
readFully(fourBytesBuf, 0, bytes);
499-
}
500+
return length > 0 ? readFully(fourBytesBuf, 0, length) : 0;
500501
}
501502

502503
/**

0 commit comments

Comments
 (0)