Skip to content

ext/pcre: fix duplicate MARK key in matches array#22029

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/ext-pcre-mark-named-collision
Open

ext/pcre: fix duplicate MARK key in matches array#22029
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/ext-pcre-mark-named-collision

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented May 12, 2026

Regression from d6cc31c: populate_subpat_array() now uses zend_hash_str_add_new for the (*MARK:name) directive, which skips the duplicate-key check. When a named capture is also called MARK, two buckets land in $matches.

Repro: preg_match('/(?P<MARK>[abc])(*MARK:value)/', "abc", $m);. Master gives count($m)==4 with a duplicate JSON key; PHP-8.4 gives 3. Restore the directive-overwrites-capture behavior that add_assoc_string_ex provided before the refactor.

When a named capture group is also called "MARK" and the pattern uses
the (*MARK:name) directive, populate_subpat_array() inserted two
buckets with the same string key into the matches array.
zend_hash_str_add_new skips the duplicate-key check, so the named
capture's MARK and the directive's MARK both landed in the table.

Switch to zend_hash_str_update so the directive's value overwrites
the capture's value, restoring the behavior that existed via
add_assoc_string_ex before d6cc31c.
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