On Tue, 1 Dec 2026 09:37:58 GMT, Timofei Fedotov <[email protected]> wrote:

>> ZipInputStream.readLOC() calls ZipEntry.setExtra0() without translating 
>> IllegalArgumentException into ZipException. setExtra0() rejects a local 
>> entry when the combined central-header size, entry name, and extra field 
>> exceeds 65535 bytes.
>> 
>> For example, an empty entry name with an extra-field length of 65490 causes 
>> IllegalArgumentException from getNextEntry(). The same input also causes the 
>> JarInputStream constructor to throw the unchecked exception instead of its 
>> documented IOException.
>> 
>> Malformed local headers should be rejected with ZipException. The exception 
>> translation should cover both entry creation and extra-field processing so 
>> that all invalid LOC length combinations follow the public IOException 
>> contract.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Timofei Fedotov has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Handle oversized ZIP entry names

Thank you for the update, we are getting close.

Please add comments introducing each test.  Its important to make it clear that 
this test is only creating a LOC which is being processed so that future 
maintainers will have a better understanding

src/java.base/share/classes/java/util/zip/ZipInputStream.java line 532:

> 530:         } catch (IllegalArgumentException ex) {
> 531:             throw (ZipException) new ZipException(
> 532:                     "invalid LOC header (bad entry name)").initCause(ex);

I am assuming the the IAE is due to the call to !isCENHeaderValid(name, extra, 
comment)?

If so, I don't see a reason to set the cause in the case.  It is OK, but not 
really needed.

test/jdk/java/util/zip/ZipInputStream/ZipInputStreamExtraLength.java line 49:

> 47: public class ZipInputStreamExtraLength {
> 48: 
> 49:     private static final int LOC_HEADER_SIZE = 30;

You can use ZipEntry.LOCHDR

test/jdk/java/util/zip/ZipInputStream/ZipInputStreamExtraLength.java line 51:

> 49:     private static final int LOC_HEADER_SIZE = 30;
> 50: 
> 51:     private static byte[] localHeader(int nameLength, int extraLength) {

consider a better name such as initLOCHeader or createLOCHeader

test/jdk/java/util/zip/ZipInputStream/ZipInputStreamExtraLength.java line 56:

> 54:                 .order(ByteOrder.LITTLE_ENDIAN);
> 55: 
> 56:         header.putInt(0, 0x04034b50);

You can use ZipEntry.LOCSIG here

test/jdk/java/util/zip/ZipInputStream/ZipInputStreamExtraLength.java line 57:

> 55: 
> 56:         header.putInt(0, 0x04034b50);
> 57:         header.putShort(4, (short) 20);

Add a comment as to what the Version and general purpose bit flags are

test/jdk/java/util/zip/ZipInputStream/ZipInputStreamExtraLength.java line 80:

> 78: 
> 79:     @Test
> 80:     public void oversizedExtraFieldZipInputStream() {

This should be a @ParameterizedTest

-------------

PR Review: https://git.openjdk.org/jdk/pull/34121#pullrequestreview-6136317155
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758381104
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758066744
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758237318
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758056940
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758207522
PR Review Comment: https://git.openjdk.org/jdk/pull/34121#discussion_r4758298924

Reply via email to