Skip to content

reject out-of-range enum index in read_value#3814

Open
rootvector2 wants to merge 1 commit into
apache:mainfrom
rootvector2:enum-index-bounds-check
Open

reject out-of-range enum index in read_value#3814
rootvector2 wants to merge 1 commit into
apache:mainfrom
rootvector2:enum-index-bounds-check

Conversation

@rootvector2

Copy link
Copy Markdown

What is the purpose of the change

read_value reads an enum's symbol index from the wire with read_long and stores it through avro_value_set_enum without 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 reaches avro_schema_enum_get, where an st_lookup miss leaves the returned char * uninitialized and the json writer dereferences it. The union branch directly above already range-checks its discriminant, and the C++ ValidatingDecoder does the same for enums, so apply the matching check and return EINVAL before the bad index is stored.

Verifying this change

This change added tests and can be verified as follows:

  • extended the test_avro_values enum 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 full ctest suite stays green

Documentation

  • Does this pull request introduce a new feature? no

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.
@github-actions github-actions Bot added the C label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant