fix off-by-one quant table index check in jpegli_add_quant_table#241
Open
rootvector2 wants to merge 1 commit into
Open
fix off-by-one quant table index check in jpegli_add_quant_table#241rootvector2 wants to merge 1 commit into
rootvector2 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.
Description
jpegli_add_quant_tablebounds-checks the caller-suppliedwhich_tblwithwhich_tbl > NUM_QUANT_TBLSinstead of>=, sowhich_tbl == NUM_QUANT_TBLS(4) slips through and the function then indexesquant_tbl_ptrs[4], one past the four-entry array. Injpeg_compress_structthat read aliasesq_scale_factor[0], whichjpegli_set_defaultsinitializes to 100, so the== nullptrcheck is skipped and 64 coefficients get written through(JQUANT_TBL*)100. Reachable through both this entry point and the libjpeg-compatiblejpeg_add_quant_tablewrapper.Noticed comparing this setter to the decoder's DQT path (
decode_marker.cc,JPEG_VERIFY_INPUT(quant_table_index, 0, NUM_QUANT_TBLS - 1)) and to libjpeg'sjcparam.c, both of which bound the index atNUM_QUANT_TBLS - 1. The fix matches that. Added a regression test that calls the setter withNUM_QUANT_TBLSand expects a clean error rather than the out-of-bounds access.Pull Request Checklist
./ci.sh lintfor automatic code formatting.