MINOR: [ruby] reject out-of-range enum and union index in binary decoder - #3944
Open
arib06 wants to merge 1 commit into
Open
MINOR: [ruby] reject out-of-range enum and union index in binary decoder#3944arib06 wants to merge 1 commit into
arib06 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.
What is the purpose of the change
read_enum,read_unionandskip_unioninlang/ruby/lib/avro/io.rbtake the enum symbol index and the union branch index straight from untrusted serialized data and indexwriters_schema.symbols/writers_schema.schemaswith no range check. Because Ruby arrays treat a negative subscript as an offset from the end, a crafted negative index (the zigzag byte0x01decodes to-1) wraps to a valid but wrong symbol or branch and is decoded silently, which is a type confusion / stream desync rather than a decode failure. A positive out-of-range index yieldsniland later raisesNoMethodError. The Python decoder already rejects these (AVRO-4296); this brings the Ruby SDK in line by validating0 <= index < sizeat the branch point and raisingAvro::AvroError.Verifying this change
This change added tests and can be verified as follows:
test_enum_index_out_of_rangeandtest_union_index_out_of_rangetotest/test_io.rb, which feed the decoder crafted bytes with a negative index (-1, wraps to the last element) and a positive out-of-range index, assertingAvro::AvroErroris raised. Both tests fail on the unpatched decoder (the enum returns the wrong symbol, the union decodes the wrong branch) and pass with the fix.Documentation