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
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private CpioArchiveEntry readOldAsciiEntry() throws IOException {
ret.setRemoteDevice(readAsciiLong(6, 8));
ret.setTime(readAsciiLong(11, 8));
final long nameSize = readAsciiLong(6, 8);
if (nameSize < 0) {
if (nameSize <= 0) {
throw new ArchiveException("Found illegal entry with negative name length");
}
ret.setSize(readAsciiLong(11, 8));
Expand Down Expand Up @@ -524,7 +524,7 @@ private CpioArchiveEntry readOldBinaryEntry(final boolean swapHalfWord) throws I
oldEntry.setRemoteDevice(readBinaryLong(2, swapHalfWord));
oldEntry.setTime(readBinaryLong(4, swapHalfWord));
final long nameSize = readBinaryLong(2, swapHalfWord);
if (nameSize < 0) {
if (nameSize <= 0) {
throw new ArchiveException("Found illegal entry with negative name length");
}
oldEntry.setSize(readBinaryLong(4, swapHalfWord));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,34 @@ void testEndOfFileInEntry_c_namesize_0x00000000() throws Exception {
}
}

@Test
void testEndOfFileInEntry_c_namesize_0x00000000_magicOldAscii() throws Exception {
// CPIO header with c_namesize = 0x00000000
// @formatter:off
final String header =
"070707" + // c_magic
"000000" + // dev
"000000" + // c_ino
"007004" + // c_mode
"000000" + // c_uid
"000000" + // c_gid
"00000001" + // c_nlink
"00000000" + // c_mtime
"00000000" + // c_filesize
"00000000" + // c_devmajor
"00000000" + // c_devminor
"00000000" + // c_rdevmajor
"00000000" + // c_rdevminor
"00000000" + // c_namesize
"00000000"; // c_check
// @formatter:on
final byte[] data = new byte[header.getBytes(StandardCharsets.US_ASCII).length + 1];
System.arraycopy(header.getBytes(), 0, data, 0, header.getBytes().length);
try (CpioArchiveInputStream cpio = CpioArchiveInputStream.builder().setByteArray(data).get()) {
assertThrows(ArchiveException.class, () -> cpio.getNextEntry());
}
}

@Test
void testEndOfFileInEntry_c_namesize_0xFFFFFFFF() throws Exception {
// CPIO header with c_namesize = 0xFFFFFFFF
Expand Down
Loading