Validate negative OCF block size before conversion#586
Merged
Conversation
1a83911 to
5f86c60
Compare
5f86c60 to
e868d41
Compare
martin-g
approved these changes
Jul 14, 2026
Contributor
|
I've expanded the check to the object count. As this would have duplicate error logic I've replaced |
Kriskras99
approved these changes
Jul 14, 2026
martin-g
reviewed
Jul 14, 2026
Contributor
|
Thank you for your contribution @MitNarodia! |
Contributor
Author
|
Thank you! I really appreciate the review and feedback. |
Open
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.
Summary
The OCF reader currently converts the block size from
i64tousizeusing an unchecked cast.This change validates the block size using
usize::try_from()before conversion and returns the existingConvertI64ToUsizeerror if a malformed negative block size is encountered.Motivation
The Java Avro implementation explicitly validates negative OCF block sizes before using them.
In the current Rust implementation, a negative block size is eventually rejected by
safe_len(), but only after the unchecked cast wraps the value tousize, resulting in aMemoryAllocationerror.While the malformed input is still rejected, the reported error reflects a failed memory allocation rather than the actual issue: invalid OCF block metadata. This change validates the block size immediately after it is read and returns a more precise error that directly reflects the malformed metadata, while preserving the behavior for valid inputs.
Testing
cargo test -p apache-avro --lib --tests --features derive