On Mon, 30 Nov 2026 13:21:51 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).

Thank you for your work here.  A few high level comments:

-  It might be beneficial to see if the ZipException can be thrown from 
findEnd() as long as it does not require a heavy lift.
-  for the test:
-- Please convert to junit
-- It would be clearer/easier to use 
`ByteBuffer.wrap(zipArray).order(ByteOrder.LITTLE_ENDIAN);` 
-- Add comments making it clear what you are changing such as the output for 
example from zipdetails.  This makes it easier for future maintainers

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

Changes requested by lancea (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/34122#pullrequestreview-6118285709

Reply via email to