@@ -541,6 +541,9 @@ private Map<ZipEntry, NameAndComment> populateFromCentralDirectory()
541541 ze .setExternalAttributes (ZipLong .getValue (CFH_BUF , off ));
542542 off += WORD ;
543543
544+ if (archive .length () - archive .getFilePointer () < fileNameLen ) {
545+ throw new EOFException ();
546+ }
544547 final byte [] fileName = new byte [fileNameLen ];
545548 archive .readFully (fileName );
546549 ze .setName (entryEncoding .decode (fileName ), fileName );
@@ -550,12 +553,18 @@ private Map<ZipEntry, NameAndComment> populateFromCentralDirectory()
550553 // data offset will be filled later
551554 entries .add (ze );
552555
556+ if (archive .length () - archive .getFilePointer () < extraLen ) {
557+ throw new EOFException ();
558+ }
553559 final byte [] cdExtraData = new byte [extraLen ];
554560 archive .readFully (cdExtraData );
555561 ze .setCentralDirectoryExtra (cdExtraData );
556562
557563 setSizesAndOffsetFromZip64Extra (ze , offset , diskStart );
558564
565+ if (archive .length () - archive .getFilePointer () < commentLen ) {
566+ throw new EOFException ();
567+ }
559568 final byte [] comment = new byte [commentLen ];
560569 archive .readFully (comment );
561570 ze .setComment (entryEncoding .decode (comment ));
@@ -881,9 +890,18 @@ private void resolveLocalFileHeaderData(final Map<ZipEntry, NameAndComment>
881890 }
882891 lenToSkip -= skipped ;
883892 }
893+ if (archive .length () - archive .getFilePointer () < extraFieldLen ) {
894+ throw new EOFException ();
895+ }
884896 final byte [] localExtraData = new byte [extraFieldLen ];
885897 archive .readFully (localExtraData );
886- ze .setExtra (localExtraData );
898+ try {
899+ ze .setExtra (localExtraData );
900+ } catch (RuntimeException ex ) {
901+ final ZipException z = new ZipException ("Invalid extra data in entry " + ze .getName ());
902+ z .initCause (ex );
903+ throw z ;
904+ }
887905 offsetEntry .dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH
888906 + SHORT + SHORT + fileNameLen + extraFieldLen ;
889907
0 commit comments