Skip to content

ext/soap: to_xml_array() heap use-after-free with illegal iterator keys. - #22896

Open
devnexen wants to merge 2 commits into
php:PHP-8.4from
devnexen:gh22895
Open

ext/soap: to_xml_array() heap use-after-free with illegal iterator keys.#22896
devnexen wants to merge 2 commits into
php:PHP-8.4from
devnexen:gh22895

Conversation

@devnexen

Copy link
Copy Markdown
Member

Fix #22895

The return value of array_set_zval_key() was ignored, so when the key is not a legal array offset, e.g. MultipleIterator::key() returning an array, it threw and took no reference. The unconditional zval_ptr_dtor() then dropped the iterator's only reference to the borrowed value and the following Z_TRY_ADDREF_P() read freed memory.

Let array_set_zval_key() own its reference the way spl_iterator_to_array_apply() does, and stop iterating on failure.

Fix php#22895

The return value of array_set_zval_key() was ignored, so when the key is
not a legal array offset, e.g. MultipleIterator::key() returning an
array, it threw and took no reference. The unconditional zval_ptr_dtor()
then dropped the iterator's only reference to the borrowed value and the
following Z_TRY_ADDREF_P() read freed memory.

Let array_set_zval_key() own its reference the way
spl_iterator_to_array_apply() does, and stop iterating on failure.
@devnexen devnexen linked an issue Jul 27, 2026 that may be closed by this pull request
@devnexen
devnexen marked this pull request as ready for review July 27, 2026 05:14
Comment thread ext/soap/tests/bugs/gh22895.phpt Outdated
try {
$client->__soapCall('audit', [new SoapVar($iterator, SOAP_ENC_ARRAY)]);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), PHP_EOL;

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.

ext/soap: heap use-after-free while encoding a MultipleIterator

2 participants