ppkarwasz opened a new pull request, #583:
URL: https://github.com/apache/commons-imaging/pull/583

   Fixes [IMAGING-400](https://issues.apache.org/jira/browse/IMAGING-400).
   
   `PngChunkZtxt` and `PngChunkItxt` inflated their compressed text with 
`IOUtils.toByteArray(new InflaterInputStream(...))`, reading until the 
compressed data ended regardless of the `Allocator` limit. With Deflate ratios 
of about 1000:1, a small text chunk could inflate to gigabytes when reading 
metadata.
   
   Both chunks now call a shared `AbstractPngTextChunk.inflateText(...)`, which:
   
   - inflates through a `BoundedInputStream` with a maximum of 
`Allocator.getLimit() + 1` bytes, whose `onMaxCount` callback throws an 
`AllocationRequestException`, so text up to the limit is accepted and anything 
longer is rejected;
   - decodes the text directly with `IOUtils.toString(InputStream, Charset)`, 
without an intermediate byte array;
   - reads the compressed text in place instead of copying it out of the chunk 
data first.
   
   `Allocator.getLimit()` is a new public method, since the chunk classes live 
outside the `common` package; it may also be useful for IMAGING-379.
   
   The limit is the general `Allocator` limit (1 GiB by default, configurable 
through the `org.apache.commons.imaging.common.Allocator` system property). 
Real text chunks, including XMP, are at most a few hundred KB, so a tighter 
default for decompressed text could be discussed separately.
   
   Tests: `AbstractPngTextChunkTest` checks text at, just above and far above a 
small limit, plus UTF-8 decoding; `AllocatorTest.testGetLimit` covers the new 
method. Compressed zTXt and iTXt round trips remain covered by `PngTextTest`.
   
   - [x] Read the contribution guidelines.
   - [x] Read the ASF Generative Tooling Guidance.
   - [x] I used AI to create any part of, or all of, this pull request: Claude 
Code (Claude Opus 5.5) helped analyze the text chunk parsers, draft the change 
and tests, and write this description; I reviewed and verified everything.
   - [x] Run a successful build using the default Maven goal with `mvn`.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request has a meaningful subject line and body.
   


-- 
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]

Reply via email to