Repository navigation
Conversation
PngChunkZtxt and PngChunkItxt inflated their compressed text until the compressed data ended, regardless of the Allocator limit that bounds other allocations, so a small text chunk could inflate to gigabytes. Inflate through a BoundedInputStream that throws an AllocationRequestException once the text exceeds the Allocator limit, and decode it directly with IOUtils.toString. Add Allocator.getLimit() so the limit can be read outside the common package. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes IMAGING-400.
PngChunkZtxtandPngChunkItxtinflated their compressed text withIOUtils.toByteArray(new InflaterInputStream(...)), reading until the compressed data ended regardless of theAllocatorlimit. 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:BoundedInputStreamwith a maximum ofAllocator.getLimit() + 1bytes, whoseonMaxCountcallback throws anAllocationRequestException, so text up to the limit is accepted and anything longer is rejected;IOUtils.toString(InputStream, Charset), without an intermediate byte array;Allocator.getLimit()is a new public method, since the chunk classes live outside thecommonpackage; it may also be useful for IMAGING-379.The limit is the general
Allocatorlimit (1 GiB by default, configurable through theorg.apache.commons.imaging.common.Allocatorsystem 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:
AbstractPngTextChunkTestchecks text at, just above and far above a small limit, plus UTF-8 decoding;AllocatorTest.testGetLimitcovers the new method. Compressed zTXt and iTXt round trips remain covered byPngTextTest.mvn.