Skip to content

Fix panic on out-of-bounds SSTable sparse index offsets#113

Merged
mweiden merged 1 commit into
mainfrom
claude/audit-fix-1-sstable-offset-bounds
Jun 9, 2026
Merged

Fix panic on out-of-bounds SSTable sparse index offsets#113
mweiden merged 1 commit into
mainfrom
claude/audit-fix-1-sstable-offset-bounds

Conversation

@mweiden

@mweiden mweiden commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Problem

SsTable::get slices the mmap/raw buffer directly with an offset taken from the sparse index (&mmap[offset as usize..], sstable.rs:190/200). The index is loaded from the separately stored .meta protobuf with no validation, so a corrupt or stale meta file — or a .tbl truncated by a partial write — can carry an offset past EOF. The next read of an affected key panics and crashes the server.

Fix

Treat an out-of-range offset as a stale index: fall back to scanning the table from the start (mmap.get(offset..).unwrap_or(&mmap[..])). Lookups stay correct (no false negatives from a bad index) and never panic. Both the local mmap path and the remote-storage fallback path are covered.

Tests

  • out_of_bounds_index_offset_does_not_panic: corrupts the in-memory index with u64::MAX offsets and verifies lookups still succeed via the fallback scan.
  • out_of_bounds_index_offset_remote_storage_does_not_panic: same, through a storage wrapper that hides local_path() to exercise the remote read path.

Found by codebase audit (high severity: remote-crash DoS via corrupt metadata).

https://claude.ai/code/session_01CJXWjB9ERGgV6B9mRqrdM9


Generated by Claude Code

A corrupt or stale .meta file (or a truncated .tbl after a partial
write) could contain index offsets past the end of the data file.
SsTable::get sliced the mmap/raw buffer with that offset directly,
panicking and crashing the server on the next read of the affected key.

Treat an out-of-range offset as a stale index and fall back to scanning
the table from the start, so lookups stay correct without panicking.

https://claude.ai/code/session_01CJXWjB9ERGgV6B9mRqrdM9
@mweiden
mweiden merged commit 89bd1e0 into main Jun 9, 2026
1 check passed
@mweiden
mweiden deleted the claude/audit-fix-1-sstable-offset-bounds branch June 9, 2026 22:15
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.

2 participants