Skip to content

Fix integer overflow in DecodeEntry bounds check#1323

Open
M0oo0ry wants to merge 1 commit into
google:mainfrom
M0oo0ry:fix-integer-overflow-decodeentry
Open

Fix integer overflow in DecodeEntry bounds check#1323
M0oo0ry wants to merge 1 commit into
google:mainfrom
M0oo0ry:fix-integer-overflow-decodeentry

Conversation

@M0oo0ry
Copy link
Copy Markdown

@M0oo0ry M0oo0ry commented Apr 27, 2026

The bounds check in DecodeEntry() compares limit - p against
*non_shared + *value_length. Both operands of the addition are
uint32_t, so the sum can wrap around when their combined value
exceeds UINT32_MAX. When that happens the comparison passes
incorrectly and the function returns a pointer that may be past
limit, which callers then dereference during block iteration.

This change widens the comparison to uint64_t so the addition cannot
wrap. Behavior on valid blocks is unchanged.

Tested:

  • All ctest targets pass on Linux (leveldb_tests, c_test,
    env_posix_test).

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