reject out-of-range enum index in read_value#3814
Open
rootvector2 wants to merge 1 commit into
Open
Conversation
the enum branch in read_value stored the wire index without range-checking it against the symbol count, so an out-of-range value reached avro_schema_enum_get and produced an uninitialized pointer read; mirror the union discriminant check.
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.
What is the purpose of the change
read_valuereads an enum's symbol index from the wire withread_longand stores it throughavro_value_set_enumwithout checking it against the schema's symbol count, so a negative or out-of-range index from an untrusted Avro file or datum is kept as-is and later reachesavro_schema_enum_get, where anst_lookupmiss leaves the returnedchar *uninitialized and the json writer dereferences it. The union branch directly above already range-checks its discriminant, and the C++ValidatingDecoderdoes the same for enums, so apply the matching check and returnEINVALbefore the bad index is stored.Verifying this change
This change added tests and can be verified as follows:
test_avro_valuesenum test to read an out-of-range symbol index ({0xC6, 0x01}against a 4-symbol enum); it fails on the unpatched tree and passes with the fix, and the fullctestsuite stays greenDocumentation