On Wed, 2 Dec 2026 14:00:48 GMT, Timofei Fedotov <[email protected]> wrote:

>> ZipFile reads the ZIP64 central directory size as a signed 64-bit value but 
>> does not reject negative values before allocating the central directory 
>> buffer. Values from -45 through -1 pass the existing consistency checks and 
>> cause NegativeArraySizeException in new byte[cenlen].
>> 
>> A minimal 99-byte ZIP64 structure reproduces the issue with ZipFile and 
>> JarFile. The same malformed archive also affects URLClassLoader and the 
>> zipfs FileSystem implementation, which contains equivalent parsing logic. 
>> ZipInputStream is unaffected because it does not read the central directory.
>> 
>> Negative ZIP64 sizes and offsets should be rejected with ZipException or 
>> IOException during header validation rather than causing an unchecked 
>> allocation exception.
>> 
>> 
>> ---------
>> - [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:
> 
>   Simplify ZIP64 regression test setup and parameterized cases

I think we are getting closer as mentioned for 8398547.

For test comments, we are hoping for a bit more.  see  
open/test/jdk/java/util/zip/ZipFile/DupEntriesGetInputStream.java, 
open/test/jdk/java/util/zip/ZipInputStream/Zip64DataDescriptor.java or 
open/test/jdk/jdk/nio/zipfs/ZipFSMaxCenHdrTest.java for inspiration

test/jdk/java/util/zip/ZipFile/NegativeZip64CentralDirectorySize.java line 75:

> 73:             "invalid END header (negative central directory size or 
> offset)";
> 74: 
> 75:     private static byte[] archive(boolean negativeOffset) {

could use a better name other than archive

test/jdk/java/util/zip/ZipFile/NegativeZip64CentralDirectorySize.java line 89:

> 87:         buffer.putShort(ZIP64_END_OFFSET + ZIP64_ENDVEM, (short) 45);
> 88:         buffer.putShort(ZIP64_END_OFFSET + ZIP64_ENDVER, (short) 45);
> 89: 

useful to add comments to the above  or append to each putXX for example

// size of zip64 end
// version made by
// version needed to extract

I would do this for all of these putXX calls in this method

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

PR Review: https://git.openjdk.org/jdk/pull/34122#pullrequestreview-6153929581
PR Review Comment: https://git.openjdk.org/jdk/pull/34122#discussion_r4772184783
PR Review Comment: https://git.openjdk.org/jdk/pull/34122#discussion_r4772002798

Reply via email to