Xuanwo opened a new pull request, #8747:
URL: https://github.com/apache/opendal/pull/8747

   # Which issue does this PR close?
   
   N/A. This fixes two verified bugs in the C binding.
   
   # Rationale for this change
   
   `opendal_bytes::new` converted an empty `Buffer` to a `Vec`, whose dangling 
pointer (`0x1`) was stored in `opendal_bytes.data`. This violated the 
documented input contract that an empty buffer must have `data == NULL`, so an 
empty read result could not be passed back to `opendal_operator_write` or 
`opendal_writer_write`.
   
   `opendal_reader_seek` cast a negative `OPENDAL_SEEK_SET` offset to `u64`, 
wrapping it to `u64::MAX` and silently seeking instead of returning an error.
   
   # What changes are included in this PR?
   
   - Return `opendal_bytes { data: NULL, len: 0, capacity: 0 }` when converting 
an empty buffer, and clear all output fields after `opendal_bytes_free`.
   - Validate `OPENDAL_SEEK_SET` offsets with `u64::try_from` and return an 
`OPENDAL_UNEXPECTED` error for negative values while writing `0` to `*pos`.
   - Add Rust unit tests for empty and non-empty `opendal_bytes` 
conversion/free and for negative `OPENDAL_SEEK_SET`.
   - Add C++ gtest coverage asserting an empty read has `data == NULL`, 
round-trips into `opendal_operator_write`, and that a negative 
`OPENDAL_SEEK_SET` returns an error.
   
   # Are there any user-facing changes?
   
   Yes. Empty read results now have `data == NULL` as documented, so they can 
be passed back to the write APIs. Negative offsets with `OPENDAL_SEEK_SET` now 
return an error instead of wrapping to `u64::MAX`. There are no ABI or function 
signature changes.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - Harness: pi coding agent
   - Model: group/deepseek
   - Effort: max
   - Role: AI implemented the fixes and tests, ran the Rust and C/C++ 
verification, and prepared this PR. No unknowns affecting review.


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