arib06 opened a new pull request, #3944: URL: https://github.com/apache/avro/pull/3944
## What is the purpose of the change `read_enum`, `read_union` and `skip_union` in `lang/ruby/lib/avro/io.rb` take the enum symbol index and the union branch index straight from untrusted serialized data and index `writers_schema.symbols` / `writers_schema.schemas` with no range check. Because Ruby arrays treat a negative subscript as an offset from the end, a crafted negative index (the zigzag byte `0x01` decodes 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 yields `nil` and later raises `NoMethodError`. The Python decoder already rejects these (AVRO-4296); this brings the Ruby SDK in line by validating `0 <= index < size` at the branch point and raising `Avro::AvroError`. ## Verifying this change This change added tests and can be verified as follows: - Added `test_enum_index_out_of_range` and `test_union_index_out_of_range` to `test/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, asserting `Avro::AvroError` is 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 - Does this pull request introduce a new feature? no -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
