AVRO-4344: [C] Reject out-of-range enum ordinal instead of returning an uninitialized pointer - #3948
Open
iemejia wants to merge 1 commit into
Open
AVRO-4344: [C] Reject out-of-range enum ordinal instead of returning an uninitialized pointer#3948iemejia wants to merge 1 commit into
iemejia wants to merge 1 commit into
Conversation
…an uninitialized pointer avro_schema_enum_get() called st_lookup() but ignored its return value, so for an index outside the schema's symbol range it returned an uninitialized stack value as a char *. The binary reader also passed the enum ordinal read from the input straight through without a range check, so a malformed or truncated container file could drive that path and a caller using the returned symbol name (e.g. avropipe calling strlen) would read through an indeterminate pointer and typically crash. - value-read.c: validate the decoded enum ordinal against the number of symbols and return EINVAL for an out-of-range value. - schema.c: avro_schema_enum_get() now returns NULL when st_lookup() fails. Adds test_avro_4344 covering a valid ordinal, an out-of-range positive ordinal, a negative ordinal, and avro_schema_enum_get() returning NULL. Reported by Mahdi Alhakim.
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
avro_schema_enum_get()(lang/c/src/schema.c) calledst_lookup()but ignored its return value:For an index outside the schema's symbol range,
st_lookup()leavesval.datauntouched, so the function returned an uninitialized stack value as achar *.The binary reader (
lang/c/src/value-read.c,AVRO_ENUMcase) also passed the enum ordinal read from the input straight through without a range check, so a malformed or truncated container file could drive that path. A caller that then uses the returned symbol name (e.g.avropipecallingstrlen()) reads through an indeterminate pointer and typically crashes withSIGSEGVon a defaultReleasebuild.Fix
avro_schema_enum_number_of_symbols()and returnEINVALfor an out-of-range value.avro_schema_enum_get()returnsNULLwhenst_lookup()fails, so it can never return an uninitialized pointer even if called directly.Tests
Adds
test_avro_4344(self-contained, no data file): a valid ordinal reads successfully; an out-of-range positive ordinal, a negative ordinal, andavro_schema_enum_get(schema, 99)are all handled cleanly (error /NULL). Verified the test fails without the fix and passes with it; the fulllang/csuite (28 tests) passes.JIRA: https://issues.apache.org/jira/browse/AVRO-4344
Reported by Mahdi Alhakim.