Skip to content

fix(encryption): reject trailing bytes after key metadata datum - #3225

Closed
xanderbailey wants to merge 1 commit into
apache:mainfrom
xanderbailey:xb/reject-trailing-key-metadata-bytes
Closed

xanderbailey wants to merge 1 commit into
apache:mainfrom
xanderbailey:xb/reject-trailing-key-metadata-bytes

Conversation

@xanderbailey

Copy link
Copy Markdown
Contributor

from_avro_datum reads a single datum from the reader and ignores anything after it, so StandardKeyMetadata::decode accepted a valid datum followed by arbitrary trailing bytes. Check the reader was exhausted and fail with DataInvalid otherwise.

Which issue does this PR close?

  • Closes #.

What changes are included in this PR?

Are these changes tested?

AI Disclosure

`from_avro_datum` reads a single datum from the reader and ignores anything
after it, so `StandardKeyMetadata::decode` accepted a valid datum followed by
arbitrary trailing bytes. Check the reader was exhausted and fail with
`DataInvalid` otherwise.

@blackmwk blackmwk 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.

Thanks @xanderbailey for this pr. Could you clarify what concrete issue this check fixes? Java’s RawDecoder.decode
(https://github.com/apache/iceberg/blob/c4784768b2f38c5a8c70d8e0e5a07f4302f9282f/core/src/main/java/org/apache/iceberg/data/avro/RawDecoder.java#L65)
reads one Avro datum without checking EOF, so this introduces stricter behavior than Java.

There is also a forward-compatibility concern: Java previously appended file_length to SCHEMA_V1 without changing the version byte
(apache/iceberg@11f3dcb). Ignoring trailing bytes lets older readers tolerate
appended fields; requiring EOF would prevent similar extensions.

I’d prefer preserving Java’s behavior unless there is a specific requirement or demonstrated bug that justifies this restriction.

@xanderbailey

xanderbailey commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

You are correct, this came up in a review of the python bindings but your point here is very solid. We should keep the current version. Thanks for taking a look @blackmwk

@xanderbailey

Copy link
Copy Markdown
Contributor Author

#3206 (review)

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.

2 participants