Skip to content

Fix potential integer overflow and unbounded allocation in ReadBlock#1305

Open
Noamismach wants to merge 1 commit intogoogle:mainfrom
Noamismach:patch-1
Open

Fix potential integer overflow and unbounded allocation in ReadBlock#1305
Noamismach wants to merge 1 commit intogoogle:mainfrom
Noamismach:patch-1

Conversation

@Noamismach
Copy link
Copy Markdown

Description

While reviewing the SSTable parsing logic, I noticed that the varint-decoded handle.size() in ReadBlock is cast to size_t and added to kBlockTrailerSize without prior bounds checking or overflow validation.

In scenarios where a corrupted or malformed .ldb file is read, an excessively large block size can trigger an integer overflow (n + kBlockTrailerSize < n), or force the new char[] allocator to request an enormous amount of heap memory, leading to an immediate std::bad_alloc abort (process crash).

Fix

This patch hardens the parser by:

  1. Adding an integer overflow guard before the trailer addition.
  2. Introducing a safe maximum block size cap (256MB) for both compressed and decompressed block payloads.
  3. Returning Status::Corruption instead of allowing the application to crash, ensuring higher robustness.

All existing tests pass successfully.

@Noamismach
Copy link
Copy Markdown
Author

Hi team,
Just a gentle ping on this PR. Let me know if there's anything else you need from my side to approve the workflows or if any adjustments are required for the patch.

Thanks!

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