Skip to content

fix: reject large values over the 2 GiB on-disk length cap - #479

Open
thweetkomputer wants to merge 2 commits into
mainfrom
fix/large-value-length-cap
Open

fix: reject large values over the 2 GiB on-disk length cap#479
thweetkomputer wants to merge 2 commits into
mainfrom
fix/large-value-length-cap

Conversation

@thweetkomputer

@thweetkomputer thweetkomputer commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

The very-large-value on-disk header encodes the length in 31 bits: bit 31 of word0 is the has-metadata flag and bits 30..0 hold actual_length (kLargeValueLengthMask = 0x7fffffff, i.e. 2 GiB − 1). WriteLargeValue cast the caller's value size (size_t) straight to uint32:

  • IoStringBuffer path: static_cast<uint32_t>(iosb->Size())
  • pinned path: static_cast<uint32_t>(size)

with only a debug-only assert in EncodeLargeValueContent guarding the cap. A value in [2 GiB, 4 GiB) sets the metadata flag and stores a wrong length; ≥ 4 GiB truncates outright. The segment-id array is sized from the true byte count, so the blob no longer matches what DecodeLargeValueHeader derives → every later read returns Corrupted, and a subsequent delete dereferences a disengaged optional (release UB).

Fix

EloqStore does not support values this large. Validate the length against kLargeValueLengthMask before the cast on both paths and return InvalidArgs when exceeded. The check runs before any memory is dereferenced.

Test

large_value_concurrency case: a pinned write with a declared length of 2 GiB (1 << 31) over a small real chunk returns InvalidArgs. Before the fix this asserts in EncodeLargeValueContent (debug) / silently corrupts the blob (release). All tests passed (5 assertions).

The very-large-value on-disk header encodes the length in 31 bits: bit 31
of word0 is the has-metadata flag and bits 30..0 hold actual_length
(kLargeValueLengthMask = 2 GiB - 1). WriteLargeValue cast the caller's
value size (size_t) straight to uint32 -- both the IoStringBuffer path
(iosb->Size()) and the pinned path (pinned->second) -- with only a
debug-only assert in EncodeLargeValueContent guarding the cap. A value in
[2 GiB, 4 GiB) set the metadata flag and stored a wrong length; >= 4 GiB
truncated outright. Either way the segment-id array no longer matches
what DecodeLargeValueHeader derives, so every subsequent read returns
Corrupted and a later delete dereferences a disengaged optional.

EloqStore does not support values this large. Validate the length against
kLargeValueLengthMask before the cast on both paths and return InvalidArgs
when it is exceeded. The check runs before any memory is dereferenced.

Adds a large_value_concurrency regression test: a pinned write with a
declared length of 2 GiB (over a small real chunk) returns InvalidArgs
instead of asserting/corrupting.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@thweetkomputer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 439615c9-5a37-4f9e-a6f5-4cb2a0233c99

📥 Commits

Reviewing files that changed from the base of the PR and between b6a60a7 and 5990aa9.

📒 Files selected for processing (1)
  • tests/large_value_concurrency.cpp

Walkthrough

Added a size-cap validation in BatchWriteTask::WriteLargeValue for both the IoStringBuffer and pinned-buffer large-value paths, rejecting values whose size exceeds kLargeValueLengthMask with KvError::InvalidArgs. Added a corresponding test verifying pinned writes over the 2 GiB cap fail as expected.

Changes

Large-value size validation

Layer / File(s) Summary
Size cap enforcement
src/tasks/batch_write_task.cpp
Adds checks in both large-value encoding paths (IoStringBuffer and pinned-buffer) to reject sizes exceeding kLargeValueLengthMask, returning KvError::InvalidArgs.
Oversized pinned write test
tests/large_value_concurrency.cpp
Adds a test case submitting a pinned write of length 1 << 31 and asserting the operation fails with InvalidArgs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: liangjchen

Poem

A rabbit checked the values twice,
"Too big!" I squeak, that's not so nice.
Two gigs and more shall not pass through,
InvalidArgs, the error true.
Hop, test, and cap — all snug and tight! 🐇✅

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: rejecting large values over the 2 GiB on-disk cap.
Description check ✅ Passed The description is mostly complete and includes the problem, fix, and regression test, but it omits the issue/RFC reference from the template.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/large-value-length-cap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant