Xuanwo opened a new issue, #8734:
URL: https://github.com/apache/opendal/issues/8734
## Summary
`Writer::copy_from` can write data out of order when the writer is
configured with `.chunk(N)` (exact chunking), silently corrupting the
destination object.
## Reproduction
```rust
let mut writer = op.writer_with("target").chunk(10).await?;
writer.write("XYZ").await?; // 3 bytes buffered
writer.copy_from("source", 0..20).await?; // source =
"0123456789abcdefghij"
writer.close().await?;
```
Expected target content: `XYZ0123456789abcdefghij`
Actual target content: `789abcdefgXYZ0123456hij`
## Root cause
In `WriteGenerator::write_chunk`, exact mode buffers bytes up to *and
including* `chunk_size` without flushing — the flush is deferred to the next
write or `close()`.
In `WriteGenerator::copy_from` (`core/core/src/types/context/write.rs`):
1. The boundary fill streams `chunk_size - buffer.len()` source bytes
through `write_chunk`, bringing the buffer to exactly `chunk_size` while
leaving it unflushed.
2. The `while remaining >= chunk_size` loop then issues
`self.w.copy_from(...)` directly on the underlying writer, ahead of the
still-queued buffered prefix.
3. The buffered prefix is flushed only later (by the trailing `stream_range`
or `close()`), so it lands after the natively copied part.
This violates the documented contract that interleaved `write`/`copy_from`
calls write in call order.
The inexact path (no `.chunk()`) is unaffected because `write_chunk` flushes
as soon as the buffer reaches `chunk_size`.
## Environment
- OpenDAL main (observed at a8fcf2235c)
--
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]