MitNarodia opened a new pull request, #586:
URL: https://github.com/apache/avro-rs/pull/586

   ### Summary
   
   The OCF reader currently converts the block size from `i64` to `usize` using 
an unchecked cast.
   
   This change validates the block size using `usize::try_from()` before 
conversion and returns the existing `ConvertI64ToUsize` error 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 to 
`usize`, resulting in a `MemoryAllocation` error.
   
   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
   
   - Added a regression test covering a negative OCF block size.
   - Verified that the existing test suite passes with:
   
   ```bash
   cargo test -p apache-avro --lib --tests --features derive
   ```


-- 
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]

Reply via email to