Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Jul 16, 2026

Copy link
Copy Markdown
Owner

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
@iliaal
iliaal force-pushed the fix/dba-cdb-length-bound branch from b1d3c2a to 32c2adc Compare July 17, 2026 00:49
@iliaal

iliaal commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#22778

@iliaal iliaal closed this Jul 17, 2026
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