Throw ArchiveException instead of EOFException when CPIO namesize <= 0#771
Conversation
|
Thanks for checking this. The EOFException from the attached one-byte ByteArrayInputStream case is expected and does not contradict the OOME report: with I agree that the original custom Here is a ByteArrayInputStream-based regression test that uses a normal finite byte array and a larger, but still test-sized, trailing payload: @Test
void testZeroNameSizeRejectedBeforeReadingTrailingData() throws Exception {
final int trailingBytes = 1024 * 1024;
final ByteArrayInputStream inputStream = new ByteArrayInputStream(newAsciiCpioEntryWithNameSize("00000000", trailingBytes));
try (CpioArchiveInputStream cpio = CpioArchiveInputStream.builder().setInputStream(inputStream).get()) {
assertThrows(IOException.class, () -> cpio.getNextEntry());
}
assertTrue(inputStream.available() > 0,
"A c_namesize of zero must be rejected before reading the attacker-controlled trailing data");
}On the vulnerable code path, the same input is drained completely and then EOFException is thrown, so the test fails at I also reran this with a real Java runtime. The ByteArrayInputStream case consumed the entire 1 MiB tail before throwing EOFException: With I have attached a patch version of the test as |
See also https://www.ibm.com/docs/en/zvm/7.3.0?topic=tar-cpio-format
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.