ext/dba: bound CDB record lengths against the file size#179
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
The cdb handler passed 32-bit key and data lengths read from the file straight to zend_string_alloc(). On 32-bit a length near UINT32_MAX wraps the struct-size computation to a few bytes while the following read copies the trailing file data past it, overflowing the heap. Capture the file size at open and reject any record length that exceeds it before allocating, in the firstkey, nextkey and fetch handlers. Closes phpGH-22778
iliaal
force-pushed
the
fix/dba-cdb-length-bound
branch
from
July 17, 2026 00:49
b1d3c2a to
32c2adc
Compare
Owner
Author
|
Promoted upstream: php#22778 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cdb handler read the 32-bit key and data length fields from the file and passed them directly to zend_string_alloc(). On 32-bit a length near UINT32_MAX wraps the struct size to a few bytes while the following read copies the trailing file bytes past that allocation, a heap overflow reachable by opening a crafted .cdb (64-bit only OOMs). Capture the file size at open and reject any record length that exceeds it, in firstkey, nextkey and fetch. Reproducer: a 2048-byte header with a first-record key length of 0xFFFFFFFF plus trailing bytes segfaults dba_firstkey() on 32-bit.