Reject oversized sequence headers in the libgav1 codec - #3404
Open
17krishna8 wants to merge 1 commit into
Open
17krishna8 wants to merge 1 commit into
17krishna8 wants to merge 1 commit into
Conversation
dav1d enforces the decoder's imageSizeLimit through its frame_size_limit setting, and libaom through AOMD_SET_FRAME_SIZE_LIMIT (or the aom_codec_peek_stream_info() fallback for older versions). The libgav1 API has no equivalent, so gav1CodecGetNextImage() handed the full data to libgav1 regardless of the maximum frame size declared by the AV1 sequence header, and the oversized frames were only caught after the fact, if at all. Pre-parse the sequence header with avifSequenceHeaderParse() and reject the sample with avifDimensionsTooLarge(), matching the libaom fallback. The same crafted file is now rejected by every decoder libavif builds with. CodecTest.OversizedSequenceHeaderRejected builds a hand-crafted minimal AVIF whose sequence header declares a 65536x65536 maximum frame size behind a small ispe. It fails at head (libgav1 accepts the sequence header) 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
dav1d enforces the decoder's
imageSizeLimitthrough itsframe_size_limitsetting, and libaom through theAOMD_SET_FRAME_SIZE_LIMITcodec control (or theaom_codec_peek_stream_info()+avifDimensionsTooLarge()fallback when that control is not available). The libgav1 API has no equivalent, sogav1CodecGetNextImage()handed the full data to libgav1 regardless of the maximum frame size declared by the AV1 sequence header:max_frame65536x65536 (way above the defaultimageSizeLimitof 16384x16384) is rejected by the dav1d and aom decoders, but libgav1 accepts the sequence header and proceeds to decode. The oversized dimensions are only caught after the fact, if at all, depending on the actual frame sizes.Change
gav1CodecGetNextImage()now pre-parses the sequence header withavifSequenceHeaderParse()and rejects the sample whenavifDimensionsTooLarge(maxWidth, maxHeight, codec->imageSizeLimit, codec->imageDimensionLimit), mirroring the libaom fallback path incodec_aom.c(same check, same error message). The check is skipped when no sequence header is found in the sample, so partial/incremental reads are unaffected.With this change the same crafted file is rejected by every decoder libavif can be built with.
Test
CodecTest.OversizedSequenceHeaderRejectedbuilds a hand-crafted minimal AVIF (no test data needed):ispeadvertises a small 64x64 image so parsing succeeds,mdatcontains a hand-built sequence header OBU declaring a 65536x65536 maximum frame size,avifDecoderParsemust succeed andavifDecoderNextImagemust fail,tile->codec->getNextImage() failed) and passes with this change.Verified locally with a
AVIF_CODEC_LIBGAV1=LOCALbuild (libgav1 from ext/), plusavifdecodetest/avifreadimagetestregressions on the regular build.Suggested changelog entry: libgav1 now rejects AV1 sequence headers exceeding the decoder's image size limits, like dav1d and libaom already did.