Skip to content

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

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

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

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@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.
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented May 12, 2026

Submitted upstream as php#22029. Closing.

@iliaal iliaal closed this May 12, 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