pjfanning opened a new pull request, #1235: URL: https://github.com/apache/poi/pull/1235
Follow-up to #1227, which made `ZipArchiveFakeEntry` read every in-memory entry via `IOUtils.toByteArrayWithMaxLength`. That starts from a 4KB buffer and grows by doubling, so larger entries produce a cascade of reallocations and short-lived garbage arrays. With poi-integration running tests in parallel, this regressed heap usage badly enough to cause `OutOfMemoryError` on a Jenkins CI box. This restores the exactly-sized single allocation for entries with a known declared size, while keeping #1227's protection against untrusted size fields: - New `IOUtils.toByteArray` overload takes a `maxInitBufferSize` that caps the **initial** buffer allocation; the buffer still grows as real data arrives, bounded by `length`/`maxLength`. Existing overloads are unchanged. - `ZipArchiveFakeEntry` uses it with a 2MB cap: entries up to 2MB (the vast majority) get one exactly-sized allocation, larger ones grow from a 2MB base, and a bogus huge declared size can force at most a 2MB eager allocation. - Reads are bounded by the declared entry size again: an entry holding fewer bytes than declared fails with `EOFException` (as before #1227), and an entry holding **more** bytes than declared is now rejected with an `IOException` instead of the extra bytes being read. The stricter size validation changes which exception 20 corrupt fuzz files in the poi-integration corpus surface (they all declare entry sizes smaller than the data actually present). The expected exceptions in `poi-integration-exceptions.csv` were re-derived by running each handler against each file; the full poi-integration suite passes locally with the updated expectations. No legitimate (non-fuzz) file in the corpus is affected by the stricter checks. New unit tests cover the init-cap calculation, the new overload, the known-size happy path, and both rejection cases (fewer/more bytes than declared); the rejection tests fail against the previous code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
