Skip to content

ext/dba: bound CDB record lengths against the file size#22778

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/dba-cdb-length-bound
Open

ext/dba: bound CDB record lengths against the file size#22778
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/dba-cdb-length-bound

Conversation

@iliaal

@iliaal iliaal commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant