Skip to content

ext/pcre: preg_replace() use-after-free when __toString() destroys an… - #23221

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

ext/pcre: preg_replace() use-after-free when __toString() destroys an…#23221
devnexen wants to merge 1 commit into
php:PHP-8.4from
devnexen:preg_replace_fixes

Conversation

@devnexen

Copy link
Copy Markdown
Member

… array argument.

Fix #23204

Follow-up on GH-23207.

preg_replace() has a frameless handler, so the pattern, replacement and subject arrays reached _preg_replace_common() with a refcount of one. Stringifying an entry runs __toString(), which freed arData under the iterator or rehashed it in place. Taking a reference on each table for the duration of the read keeps it alive and turns a mutation into a separation.

… array argument.

Fix php#23204

Follow-up on phpGH-23207.

preg_replace() has a frameless handler, so the pattern, replacement and
subject arrays reached _preg_replace_common() with a refcount of one.
Stringifying an entry runs __toString(), which freed arData under the
iterator or rehashed it in place. Taking a reference on each table for
the duration of the read keeps it alive and turns a mutation into a
separation.
@devnexen
devnexen marked this pull request as ready for review August 11, 2026 21:24
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