Skip to content

Fix integer overflow OOB reads in Block::DecodeEntry and ReadBlock - #1353

Open
smoke-wolf wants to merge 1 commit into
google:mainfrom
smoke-wolf:fix-block-readblock-oob
Open

smoke-wolf wants to merge 1 commit into
google:mainfrom
smoke-wolf:fix-block-readblock-oob

Conversation

@smoke-wolf

Copy link
Copy Markdown

Summary

Two integer overflow bugs in the SST table reader allow crafted SST files to trigger heap-buffer-overflow reads. Both confirmed under AddressSanitizer.

Bug 1: uint32 overflow in DecodeEntry (table/block.cc:71)

The bounds check static_cast<uint32_t>(limit - p) < (*non_shared + *value_length) wraps when non_shared + value_length exceeds 2^32. A crafted entry with non_shared=50, value_length=0xFFFFFFD0 wraps the sum to 2, bypasses the check, then key_.append(p, 50) reads 50 bytes from a buffer with only 5 remaining.

Fix: Check each field sequentially against remaining space instead of summing.

Bug 2: size_t overflow in ReadBlock (table/format.cc:78)

new char[n + kBlockTrailerSize] wraps when handle.size() is near SIZE_MAX, allocating a tiny buffer. Then data[n] at line 102 reads at offset ~SIZE_MAX.

Fix: Cap block size at 64MB and check for arithmetic overflow before allocation.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Sep 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@smoke-wolf
smoke-wolf force-pushed the fix-block-readblock-oob branch from 686c38f to 2041ddb Compare September 2, 2026 08:09
DecodeEntry: the bounds check (limit - p) < (non_shared + value_length)
used uint32_t addition which wraps on overflow, allowing a crafted block
entry to bypass the check and cause an out-of-bounds read in
ParseNextKey. Fix by checking each field sequentially against the
remaining space.

ReadBlock: n + kBlockTrailerSize can overflow size_t when handle.size()
is near SIZE_MAX, causing an undersized allocation followed by an OOB
read at data[n]. Fix by rejecting unreasonable block sizes and
checking for arithmetic overflow before allocation.

Both bugs are reachable via crafted SST files and confirmed under
AddressSanitizer.
@smoke-wolf
smoke-wolf force-pushed the fix-block-readblock-oob branch from 2041ddb to be43045 Compare September 2, 2026 08:12
@smoke-wolf

smoke-wolf commented Sep 2, 2026 •

Copy link
Copy Markdown
Author

Discovered by Maliq Barnard. ASAN-confirmed integer overflow → heap-buffer-overflow in Block::DecodeEntry (uint32 wrap) and ReadBlock (size_t wrap) via crafted SST files.

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