Skip to content

ext/xml: Use zend_string_safe_realloc() for cdata concatenation.#22056

Open
devnexen wants to merge 1 commit into
php:PHP-8.4from
devnexen:xml_character_data_handler_fix
Open

ext/xml: Use zend_string_safe_realloc() for cdata concatenation.#22056
devnexen wants to merge 1 commit into
php:PHP-8.4from
devnexen:xml_character_data_handler_fix

Conversation

@devnexen
Copy link
Copy Markdown
Member

The previous code computed Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value) as a plain size_t addition before passing the result to zend_string_extend(), which can wrap on 32-bit and lead to a heap overflow in the following strncpy(). Switch to zend_string_safe_realloc() so the size computation is bounds-checked.

The previous code computed `Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value)`
as a plain `size_t` addition before passing the result to
zend_string_extend(), which can wrap on 32-bit and lead to a heap
overflow in the following strncpy(). Switch to zend_string_safe_realloc()
so the size computation is bounds-checked.
@devnexen
Copy link
Copy Markdown
Member Author

if you think I should target master due to the difficulty to actually trigger it on 32 bits, I won't object.

@devnexen devnexen marked this pull request as ready for review May 15, 2026 17:41
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