Repository navigation
reject out-of-range component quant_tbl_no in encoder - #256
Open
rootvector2 wants to merge 1 commit into
Open
rootvector2 wants to merge 1 commit into
rootvector2 wants to merge 1 commit into
Conversation
ProcessCompressionParams validates each component's sampling factors and component index but never range-checks comp_info[c].quant_tbl_no, an application-settable field of the public jpeg_compress_struct. InitQuantizer later reads cinfo->quant_tbl_ptrs[quant_tbl_no], a NUM_QUANT_TBLS element array, guarded only by a null check, so an out-of-range value reads a pointer past the array and dereferences it (ASan: out-of-bounds read reached via jpegli_start_compress -> InitCompress -> InitQuantizer). libjpeg-turbo bounds-checks the same value in jcdctmgr.c, and the decoder DQT path already bounds it at NUM_QUANT_TBLS - 1. Add the missing range check in the central per-component validation loop, matching those and the sibling DC/AC Huffman index checks.
This branch has not been deployed
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
ProcessCompressionParams(lib/jpegli/encode.cc) validates each component'scomponent_indexand sampling factors but never range-checkscomp_info[c].quant_tbl_no, a field of the publicjpeg_compress_structthat the application can set to anyint.InitQuantizer(lib/jpegli/quant.cc) then readscinfo->quant_tbl_ptrs[quant_tbl_no], a four-entry array (NUM_QUANT_TBLS), guarded only by a== nullptrcheck, so an out-of-range index reads a pointer past the array and dereferences the non-null garbage it finds.Trigger: set
cinfo.comp_info[0].quant_tbl_noaboveNUM_QUANT_TBLS - 1and calljpegli_start_compress. Under ASan this is an out-of-bounds read / SEGV atInitQuantizer, reached viajpegli_start_compress->InitCompress->InitQuantizer.Noticed comparing the encoder to libjpeg-turbo, which bounds the same value in
jcdctmgr.c(qtblno < 0 || qtblno >= NUM_QUANT_TBLS), and to the decoder DQT path, which already boundsquant_table_indexatNUM_QUANT_TBLS - 1. The fix adds the missing check in the central per-component validation loop, next to the existing sampling-factor check and matching the sibling DC/AC Huffman index checks inCopyHuffmanTable. Added a regression test that sets an out-of-rangequant_tbl_noand expects a clean error instead of the out-of-bounds access;error_handling_test,encode_api_testandtranscode_api_testall pass under ASan.Pull Request Checklist
./ci.sh lintfor automatic code formatting.