reject jpeg scans referencing an undefined huffman table - #751
Open
metsw24-max wants to merge 1 commit into
Open
reject jpeg scans referencing an undefined huffman table#751metsw24-max wants to merge 1 commit into
metsw24-max wants to merge 1 commit into
Conversation
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.
The JPEG decoder reads each scan component's DC and AC Huffman table numbers from the SOS marker and only checks that they fall in 0 to 3, never that a DHT marker actually defined the selected slot. The JpegHuffman tables held in the decode context are not zero-initialised, so a file whose scan points at a table that was never built runs the entropy decoder over uninitialised state: the slow path in JpegHuffmanDecode forms a symbol index from the garbage delta[] and returns values[] at that index, reading well past the end of the context. I ran into it while fuzzing SimdImageLoadFromMemory under AddressSanitizer, which reports a heap-buffer-overflow read in JpegDecodeBlock on a crafted three-component baseline image whose third component selects an undefined DC table. Checking the selectors against the tables that were actually defined, at the scan header once it is known which tables the scan will use, rejects such a file before decoding and lines up with how libjpeg treats an undefined table. The DC table is only consumed by the first DC scan and the AC table only by the AC scans, so the check follows that split to avoid rejecting valid progressive files that name an unused selector. I applied the same guard to the AVX2 decoder, which keeps its own scan-header parser.