Skip to content

fix(avro): bound Cython decoder input - #3955

Open
akashchamp wants to merge 1 commit into
apache:mainfrom
akashchamp:fix/avro-decoder-bounds
Open

fix(avro): bound Cython decoder input#3955
akashchamp wants to merge 1 commit into
apache:mainfrom
akashchamp:fix/avro-decoder-bounds

Conversation

@akashchamp

Copy link
Copy Markdown

Closes #3952.

Rationale for this change

The Cython Avro decoder advanced raw pointers using encoded lengths and continuation bytes without checking the end of its owned buffer. This change bounds every varint decode and payload/read/skip advance, preserves the cursor when a varint cannot be fully decoded, and reports malformed input as EOFError. It also keeps Avro negative-length handling aligned with the pure Python decoder.

Are these changes tested?

  • make lint
  • Focused compiled-decoder suite: tests/avro/test_decoder.py — 68 passed.
  • Supported unit suite: 4,111 passed and 5 skipped; three Hive GSSAPI tests were excluded because the remote host lacks krb5-config and the optional native kerberos extension.
  • Manual compiled-decoder validation confirmed that an unterminated varint, an in-buffer overlong varint, and a truncated payload each raise EOFError without advancing the cursor past valid input. A valid integer and bytes payload still decode successfully.

Are there any user-facing changes?

Yes. Malformed input handled by the Cython Avro decoder now fails with EOFError instead of reading past the buffer. Valid input behavior is unchanged.

@kevinjqliu
kevinjqliu marked this pull request as draft September 12, 2026 02:23
@kevinjqliu
kevinjqliu marked this pull request as ready for review September 12, 2026 02:24
Copilot AI lite review requested due to automatic review settings September 12, 2026 02:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues remain.

Pull request overview

This PR hardens the Cython Avro decoder against malformed and truncated input while preserving valid decoding behavior.

Changes:

  • Bounds varint decoding and preserves the cursor on incomplete input.
  • Validates read, skip, and payload advances.
  • Raises EOFError for malformed input and adds regression coverage.
File summaries
File Description
tests/avro/test_decoder.py Adds malformed-input and negative-length coverage.
pyiceberg/avro/decoder_fast.pyx Applies buffer bounds checks throughout decoding.
pyiceberg/avro/decoder_basic.c Implements safe, bounded varint decoding.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cython Avro decoder reads past the buffer end on malformed input

2 participants