Skip to content

fix(ecstore): bound compressed GetObject range reads - #9639

Merged
overtrue merged 9 commits into
mainfrom
houseme/fix-compressed-get-range-9582
Nov 26, 2026
Merged

overtrue merged 9 commits into
mainfrom
houseme/fix-compressed-get-range-9582

Conversation

@houseme

@houseme houseme commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Related Issues

Fixes #9582. Follow-up is tracked in rustfs/backlog#3372.

Summary of Changes

A legacy compression index could select a checkpoint after a valid early offset when it had more than 200 entries. Its reported total could also stop before the actual part end, causing some tail requests to scan from the start of a large part.

Plan unencrypted compressed ranges in logical bytes and read only the stored blocks between usable checkpoints or part boundaries. Encrypted and unencrypted compressed reads use the same response reader. It discards the remaining prefix in bounded, cooperatively scheduled chunks, streams the requested bytes into the caller buffer, and releases the source as soon as the range completes. Whole-object reads retain their strict length, checksum, and producer completion checks. Complete legacy index frames go directly to the legacy decoder. Framed and headerless S2 indexes share one payload decoder over borrowed bytes, avoiding reconstruction of a byte buffer for each headerless index. The legacy block decoder reuses its plaintext buffer across blocks. It applies the bounded codec and verifies decoded lengths and CRC before delivering bytes.

Verification

  • On the latest merged source tree (tested as 62026aa83d, pushed identically as edb2689f80), cargo test --locked --offline -p rustfs-ecstore --lib object_api::readers passed 76 tests, and the same selection with --features rio-v2,test-util passed 82. The affected Rio and Utils compression selectors passed 17 and 13 tests. Producer terminal and cancellation selectors passed 10 and 14 tests, and the three transitioned-compression and restore tests passed. Strict package Clippy, workspace formatting, the logging guard, the error ratchet and git diff --check passed.
  • An equal-sized block pair replaced the output allocation on the prior merged implementation, which failed the new regression. The refactor reused the allocation, returned both correct blocks and rejected a later checksum failure without modifying the caller's buffer. The earlier range-reader comparison recorded 65 source reads for a 512 KiB skip and 16-byte response, down from 32,769, and a direct 64 KiB read from a ready source.
  • The earlier product smoke test on 381a56f2fb reproduced both reported HTTP 416s against official 1.0.6 and verified 22 byte-exact HTTP 206 responses and one expected 416 on the fix. The latest merged tree has fresh Rio and ECStore integration evidence. End-to-end throughput and tail latency were not remeasured.

auto-testing regression coverage STOR-136 merged in rustfs/auto-testing#170, covering real status, response headers, byte content, and bounded reads on one disk.

Impact

Valid compressed ranges use bounded storage reads when their indexes allow it. The CPU path skips without depending on the size of the response buffer and avoids an intermediate copy of returned bytes. Existing stored formats are supported. If an index is missing or invalid, the covering part can still be read sequentially.

Additional Notes

Reviewed logical range and storage coordinates, historical index compatibility, codec and AEAD verification, producer cancellation, short reads, and tier fetching. The physical read window and codec validation rules are preserved by the reader refactor. The operation-count comparison measures reader work on a controlled source.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

CLA requirements are satisfied for this pull request.

houseme and others added 4 commits November 26, 2026 11:13
Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 854dd7d1eaad...420e022e1f4b (high risk tier; two-perspective review covering correctness, security, compatibility, concurrency/cancellation, and performance).

Findings

No findings.

Lens Verdicts

  • Correctness: compressed_storage_window computes stored block windows strictly within validated part.size and part.actual_size bounds using checkpoint_at_or_before / checkpoint_at_or_after, falling back cleanly to (0, oi.size, req_off) on missing/invalid indexes or mismatched part bounds. Both rustfs_rio::DecompressReader and rustfs_rio_v2::DecompressReader (S2Decoder) terminate cleanly at block/chunk boundaries, and RangedDecompressReader now fails closed with UnexpectedEof on premature stream truncation while preserving whole-object HardLimitReader + StreamConsumer checks.
  • Security: Checked arithmetic guards offset and prediction decoding against signed overflow in both crates/rio/src/compress_index.rs and crates/rio-v2/src/s2_index.rs, read_uvarint rejects idx == 9 && byte > 1 before any shift overflow, and trailing bytes are rejected in both legacy and S2 index decoders.
  • Compatibility: Legacy framed (0x50) indexes, framed S2 (0x99) indexes, headerless S2 indexes, multipart ranges across part boundaries, and encrypted+compressed DARE offsets (get_encrypted_compressed_offsets) are preserved and covered by regression tests.
  • Concurrency & Performance: SkipReader yields cooperatively via tokio::task::coop::poll_proceed during large unindexed skips, RangedDecompressReader streams directly into caller buffers without an 8 KiB intermediate copy and drops the source immediately on range completion (unless new_draining is requested), and headerless S2 decoding borrows the payload without allocating a reframed buffer.

Verification & Check State

  • Fresh CI on rebased head 420e022e1f4b is currently running (CLA Check passed; Quick Checks and Test and Lint pending). Not merged yet because branch protection requires green Quick Checks and Test and Lint.

Verdict: Approve (ready for merge queue once CI completes).

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 854dd7d1eaad...edb2689f801a (high risk tier; re-reviewed delta 420e022e1f4b..edb2689f801a reusing unaffected evidence from the prior pass).

Findings

No findings.

Delta Review (edb2689f801a)

  • rustfs_utils::compress::decompress_block_into clears out on entry and again on error so unverified bytes never survive a failed decode while preserving buffer capacity for reuse; decompress_block_with_limit delegates to it with unchanged semantics.
  • rustfs_rio::DecompressReader delegates block verification to decode_block, validating the varint prefix, MAX_BLOCK_PLAINTEXT_LEN, non-empty length match, and CRC32 before exposing decoded plaintext (and before copying uncompressed blocks into output), clearing this.buffer and setting this.poisoned = true on any error.
  • Unit tests verify buffer reuse across equal-sized blocks, sticky poisoning on bad CRC, and clearing out on over-limit errors across codecs.

Verification & Check State

  • Fresh CI on edb2689f801a is currently running (CLA Check passed; Quick Checks and Test and Lint pending). Will merge once CI is green.

Verdict: Approve.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 854dd7d1eaad...a9d9a75edf3b (high risk tier; re-reviewed delta edb2689f801a..a9d9a75edf3b reusing unaffected evidence from the prior passes).

Findings

No findings.

Delta Review (a9d9a75edf3b)

  • rustfs/src/server/ssec_transport.rs replaces .collect() plus .len() with .count() in post_object_ssec_without_tls_increments_metric_and_warns_once to resolve the clippy::needless_collect lint on main without changing test semantics. Note that this 2-line test change overlaps with PR #9648 and PR #9637.

Verification & Check State

  • Fresh CI on a9d9a75edf3b is currently running (CLA Check passed; Quick Checks and Test and Lint pending). Will merge once CI is green.

Verdict: Approve.

houseme and others added 2 commits November 26, 2026 18:53
Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
@houseme
houseme requested a review from overtrue November 26, 2026 13:09

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewing 6ae3dadab3542f2bcc0bfdd5048972ff557e9e6d after merging main (4b0d6736d6f6): No findings.

Verification Summary

  • The net diff against main retains the previously reviewed compressed range-read changes cleanly, and the test update in rustfs/src/admin/handlers/account_permissions.rs strengthens IAM explicit-deny vs bucket-grant coverage without weakening any assertions.

@overtrue
overtrue merged commit 9a65ac9 into main Nov 26, 2026
25 checks passed
@overtrue
overtrue deleted the houseme/fix-compressed-get-range-9582 branch November 26, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disk compression: ranged GetObject fails (InvalidRange / InternalError) and tail ranges decompress the whole object

2 participants