Skip to content

fix(core): clamp chunk size of 0 to 1 for reader and writer - #8454

Open
Mola-maker wants to merge 1 commit into
apache:mainfrom
Mola-maker:fix/8452-chunk-zero
Open

Mola-maker wants to merge 1 commit into
apache:mainfrom
Mola-maker:fix/8452-chunk-zero

Conversation

@Mola-maker

Copy link
Copy Markdown
Contributor

Fixes #8452.

Summary

chunk(0) on a reader or writer previously produced broken behavior: reads silently returned empty, fetch and writes hung forever. This was because the existing max(1) guard in OpReader::with_chunk was bypassed by the public builders, which copied chunk into OpReader/OpWriter unclamped (unlike concurrent, which was clamped in the same conversion), and the writer path had no guard at all.

This PR clamps chunk to a minimum of 1 at all four construction points in core/core/src/raw/ops.rs (both From conversions and OpWriter::with_chunk), so chunk(0) behaves like chunk(1). Non-zero inputs are unaffected. Clamping follows the existing max(1) precedent for concurrent in the same conversion; happy to switch to rejecting 0 if maintainers prefer.

Tests

  • New regression tests: test_reader_read_with_chunk_zero, test_fetch_with_chunk_zero, test_writer_write_with_chunk_zero.
  • cargo test -p opendal-core --lib: 239 passed, 0 failed (baseline 236 + 3 new).
  • cargo clippy -p opendal-core --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • Reproduced all three symptoms on unmodified main before the fix (empty read, fetch hang, write hang); all three pass after the fix.

AI Usage: Harness: Muse; Model: Muse Spark; Effort: investigation and tests.

A chunk size of 0 used to flow into the read and write paths
unchanged: chunked reads produced 0-byte ranges and returned empty
data, fetch planning never advanced its offset, and chunked writes
never made progress. Clamp 0 to 1 at every OpReader/OpWriter
construction site, matching the existing max(1) handling of
OpReader::with_chunk and of concurrent requests, so a 0 chunk
behaves like the smallest valid chunk instead of hanging or
truncating data.

Add regression tests covering chunk(0) for read, fetch and write.
@Mola-maker
Mola-maker requested a review from Xuanwo as a code owner November 1, 2026 05:08
@github-actions github-actions Bot added core releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: chunk size 0 silently truncates reads to empty and hangs fetch/write

1 participant