@@ -383,44 +383,45 @@ private int readFully(final byte[] b, final int off, final int len) throws IOExc
383383 }
384384
385385 private CpioArchiveEntry readNewEntry (final boolean hasCrc ) throws IOException {
386- final CpioArchiveEntry ret ;
386+ final CpioArchiveEntry newEntry ;
387387 if (hasCrc ) {
388- ret = new CpioArchiveEntry (FORMAT_NEW_CRC );
388+ newEntry = new CpioArchiveEntry (FORMAT_NEW_CRC );
389389 } else {
390- ret = new CpioArchiveEntry (FORMAT_NEW );
390+ newEntry = new CpioArchiveEntry (FORMAT_NEW );
391391 }
392-
393- ret .setInode (readAsciiLong (8 , 16 ));
392+ newEntry .setInode (readAsciiLong (8 , 16 ));
394393 final long mode = readAsciiLong (8 , 16 );
395394 if (CpioUtil .fileType (mode ) != 0 ) { // mode is initialized to 0
396- ret .setMode (mode );
397- }
398- ret .setUID (readAsciiLong (8 , 16 ));
399- ret .setGID (readAsciiLong (8 , 16 ));
400- ret .setNumberOfLinks (readAsciiLong (8 , 16 ));
401- ret .setTime (readAsciiLong (8 , 16 ));
402- ret .setSize (readAsciiLong (8 , 16 ));
403- if (ret .getSize () < 0 ) {
395+ newEntry .setMode (mode );
396+ }
397+ newEntry .setUID (readAsciiLong (8 , 16 ));
398+ newEntry .setGID (readAsciiLong (8 , 16 ));
399+ newEntry .setNumberOfLinks (readAsciiLong (8 , 16 ));
400+ newEntry .setTime (readAsciiLong (8 , 16 ));
401+ newEntry .setSize (readAsciiLong (8 , 16 ));
402+ if (newEntry .getSize () < 0 ) {
404403 throw new IOException ("Found illegal entry with negative length" );
405404 }
406- ret .setDeviceMaj (readAsciiLong (8 , 16 ));
407- ret .setDeviceMin (readAsciiLong (8 , 16 ));
408- ret .setRemoteDeviceMaj (readAsciiLong (8 , 16 ));
409- ret .setRemoteDeviceMin (readAsciiLong (8 , 16 ));
405+ newEntry .setDeviceMaj (readAsciiLong (8 , 16 ));
406+ newEntry .setDeviceMin (readAsciiLong (8 , 16 ));
407+ newEntry .setRemoteDeviceMaj (readAsciiLong (8 , 16 ));
408+ newEntry .setRemoteDeviceMin (readAsciiLong (8 , 16 ));
410409 final long namesize = readAsciiLong (8 , 16 );
411410 if (namesize < 0 ) {
412411 throw new IOException ("Found illegal entry with negative name length" );
413412 }
414- ret .setChksum (readAsciiLong (8 , 16 ));
413+ newEntry .setChksum (readAsciiLong (8 , 16 ));
415414 final String name = readCString ((int ) namesize );
416- ret .setName (name );
415+ newEntry .setName (name );
417416 if (CpioUtil .fileType (mode ) == 0 && !name .equals (CPIO_TRAILER )) {
418417 throw new IOException (
419418 "Mode 0 only allowed in the trailer. Found entry name: " + ArchiveUtils .sanitize (name ) + " Occurred at byte: " + getBytesRead ());
420419 }
421- skip (ret .getHeaderPadCount (namesize - 1 ));
422-
423- return ret ;
420+ final int headerPadCount = newEntry .getHeaderPadCount (namesize - 1 );
421+ if (skip (headerPadCount ) != headerPadCount ) {
422+ throw new IOException ("Header pad count mismatch." );
423+ }
424+ return newEntry ;
424425 }
425426
426427 private CpioArchiveEntry readOldAsciiEntry () throws IOException {
@@ -455,35 +456,35 @@ private CpioArchiveEntry readOldAsciiEntry() throws IOException {
455456 }
456457
457458 private CpioArchiveEntry readOldBinaryEntry (final boolean swapHalfWord ) throws IOException {
458- final CpioArchiveEntry ret = new CpioArchiveEntry (FORMAT_OLD_BINARY );
459+ final CpioArchiveEntry oldEntry = new CpioArchiveEntry (FORMAT_OLD_BINARY );
459460
460- ret .setDevice (readBinaryLong (2 , swapHalfWord ));
461- ret .setInode (readBinaryLong (2 , swapHalfWord ));
461+ oldEntry .setDevice (readBinaryLong (2 , swapHalfWord ));
462+ oldEntry .setInode (readBinaryLong (2 , swapHalfWord ));
462463 final long mode = readBinaryLong (2 , swapHalfWord );
463464 if (CpioUtil .fileType (mode ) != 0 ) {
464- ret .setMode (mode );
465+ oldEntry .setMode (mode );
465466 }
466- ret .setUID (readBinaryLong (2 , swapHalfWord ));
467- ret .setGID (readBinaryLong (2 , swapHalfWord ));
468- ret .setNumberOfLinks (readBinaryLong (2 , swapHalfWord ));
469- ret .setRemoteDevice (readBinaryLong (2 , swapHalfWord ));
470- ret .setTime (readBinaryLong (4 , swapHalfWord ));
467+ oldEntry .setUID (readBinaryLong (2 , swapHalfWord ));
468+ oldEntry .setGID (readBinaryLong (2 , swapHalfWord ));
469+ oldEntry .setNumberOfLinks (readBinaryLong (2 , swapHalfWord ));
470+ oldEntry .setRemoteDevice (readBinaryLong (2 , swapHalfWord ));
471+ oldEntry .setTime (readBinaryLong (4 , swapHalfWord ));
471472 final long namesize = readBinaryLong (2 , swapHalfWord );
472473 if (namesize < 0 ) {
473474 throw new IOException ("Found illegal entry with negative name length" );
474475 }
475- ret .setSize (readBinaryLong (4 , swapHalfWord ));
476- if (ret .getSize () < 0 ) {
476+ oldEntry .setSize (readBinaryLong (4 , swapHalfWord ));
477+ if (oldEntry .getSize () < 0 ) {
477478 throw new IOException ("Found illegal entry with negative length" );
478479 }
479480 final String name = readCString ((int ) namesize );
480- ret .setName (name );
481+ oldEntry .setName (name );
481482 if (CpioUtil .fileType (mode ) == 0 && !name .equals (CPIO_TRAILER )) {
482483 throw new IOException ("Mode 0 only allowed in the trailer. Found entry: " + ArchiveUtils .sanitize (name ) + "Occurred at byte: " + getBytesRead ());
483484 }
484- skip (ret .getHeaderPadCount (namesize - 1 ));
485+ skip (oldEntry .getHeaderPadCount (namesize - 1 ));
485486
486- return ret ;
487+ return oldEntry ;
487488 }
488489
489490 private byte [] readRange (final int len ) throws IOException {
0 commit comments