You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "iemejia (via GitHub)" <gi...@apache.org> on 2026/08/22 12:06:37 UTC

[PR] AVRO-4343: [perl] Fix broken decoder skip path used in schema resolution [avro]

iemejia opened a new pull request, #3947:
URL: https://github.com/apache/avro/pull/3947

   ## What
   
   Fixes the Perl `BinaryDecoder` **skip path**, which is exercised during schema resolution whenever the writer's record contains a field that is absent from the reader's schema (`decode_record` → `skip`). Three related defects, present since the initial Perl implementation (AVRO-974):
   
   1. **Absolute seek → silent data corruption.** `skip_bytes`/`skip_string`/`skip_fixed` did `$reader->seek($size, 0)` — whence `0` is `SEEK_SET` (absolute) rather than `SEEK_CUR`. Skipping a bytes/string/fixed field repositioned the reader to absolute offset `$size`, corrupting every subsequent field. (Masked in the existing test only because its skipped field was the last one.)
   2. **Crash when skipping an array/map field.** `skip_array`/`skip_map` invoked `skip_block(...)` as a plain sub, so `shift`ing `$class` misaligned `$reader` and the content callback, dying with *"Can't call method \"read\" on unblessed reference"*.
   3. **Broken negative-block-count handling.** `skip_block` seeked to a negative absolute offset and re-looped via `next` without re-reading the block count.
   
   ## Fix
   
   - Use relative (`SEEK_CUR`) skips in `skip_bytes`/`skip_string`/`skip_fixed`.
   - Reject negative bytes lengths and negative block sizes with `Avro::Schema::Error::Parse`.
   - Invoke `skip_block` as a method (`$class->skip_block`), fixing the argument alignment.
   - Handle negative block counts the same way as `decode_array`/`decode_map`: take the absolute value and consume the following block-size long.
   
   ## Tests
   
   Adds regression tests to `t/03_bin_decode.t` covering resolution that skips: a non-trailing `bytes` field, an `array` field, a `map` field, an `array` encoded with a **negative block count**, and rejection of a negative bytes length. Full existing Perl suite still passes (the pre-existing `04_datafile.t` failure is unrelated — a missing `IO::Compress` dependency).
   
   JIRA: https://issues.apache.org/jira/browse/AVRO-4343


-- 
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: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org