Repository navigation
Reject image sequences with total sample size exceeding 16x file size - #3402
Open
17krishna8 wants to merge 1 commit into
Open
17krishna8 wants to merge 1 commit into
17krishna8 wants to merge 1 commit into
Conversation
avifCodecDecodeInputFillFromSampleTable() materializes one avifDecodeSample per sample declared by the stsc/stsz/stco boxes. Each sample is individually checked against the io sizeHint, but overlapping chunks are not, so a tiny file declaring many chunks at the same offset and the default imageCountLimit can materialize the whole budget of samples: a 4 KiB file parses successfully with imageCount = 2 592 000 and about 125 MiB of samples, before any decoding. Reject the sample table instead when the sum of the sample sizes exceeds 16x the sizeHint, mirroring the equivalent iloc guard for still images. Chunks are disjoint in a well-formed file, so the sum of the sample sizes is at most the file size there; 16x leaves a comfortable margin. Files streamed through a custom avifIO with no sizeHint are unaffected. The new avifsampletabletest builds hand-crafted minimal 'avis' files; OverlappingChunksExceedTotalSizeBudget fails at head (parse returns OK with imageCount = 2 592 000) and passes with this change.
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.
Description
avifCodecDecodeInputFillFromSampleTable()materializes oneavifDecodeSampleper sample declared by thestsc/stsz/stcoboxes, at parse time. Each sample is individually checked against the iosizeHint(offset + size <= sizeHint), but nothing bounds the sum of the sample sizes, and overlapping chunks are not rejected. A tiny crafted file can therefore declare a huge number of samples that all overlap at the same offset:stcoentries at offset 0,samplesPerChunk = 2592andallSamplesSize = 1parses successfully withimageCount = 2 592 000(the whole defaultimageCountLimitbudget) and about 125 MiB of materialized samples, before any decoding happens. Nothing in the file is invalid per se: all per-sample checks pass because every sample is within the file.This is the image-sequence counterpart of the
ilocover-allocation issue (#3372, #3398): the still-image path bounds item data against the file size, but the track/sample-table path does not.Change
avifCodecDecodeInputFillFromSampleTable()now sums the sample sizes while filling the decode input and rejects the file when the total exceeds 16x thesizeHint(returningAVIF_RESULT_NOT_IMPLEMENTED, mirroring the proposed iloc guard in #3398):avifIOwith nosizeHintare unaffected (the bound is disabled, as is the existing per-sample check),Test
New
avifsampletabletestbuilds hand-crafted minimalavisfiles byte-by-byte (no test data needed):SampleTableTest.OverlappingChunksExceedTotalSizeBudget— the file above fails at head (parse returnsOKwithimageCount = 2 592 000) and returnsAVIF_RESULT_NOT_IMPLEMENTEDwith this change,SampleTableTest.DisjointChunksParse— control: a well-formed sequence still parses with the rightimageCount.All existing sequence tests pass locally (
avifanimationtest,avifkeyframetest,avifiostatstest,avifdecodetest).Suggested changelog entry: Reject image sequences whose sample table declares more sample data than the file can hold.