Skip to content

Stdlib: preg_match past-end offset binds empty $matches (#25313) - #25342

Merged
PurHur merged 1 commit into
masterfrom
agent/advanced-stdlib-25313-preg-offset-past-end
Jul 30, 2026
Merged

Stdlib: preg_match past-end offset binds empty $matches (#25313)#25342
PurHur merged 1 commit into
masterfrom
agent/advanced-stdlib-25313-preg-offset-past-end

Conversation

@PurHur

@PurHur PurHur commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • When preg_match / preg_match_all $offset is past the subject, php-src still initializes $matches to [] while returning false + PREG_INTERNAL_ERROR.
  • VM: VmPregPure fills []; binders write when the engine produced an array (null sentinel preserves compile-failure leave-untouched).
  • JIT: PregJitHelper::matchExArgv stores empty HT on past-end; PregMatchRuntime fail path writes it when present.

Closes #25313

Test plan

  • Zend/VM/JIT match on test/repro/maintainer_gap_preg_match_offset_past_end.php
  • vendor/bin/phpunit --filter preg_match_offset_past_end — OK (2 tests)
  • AOT segfault on this surface is pre-existing (not introduced here)

php-src reference

  • ext/pcre/php_pcre.cphp_pcre_pce_execute() early return still initializes $matches

Made with Cursor

Match php-src: when $offset exceeds the subject length, return false
with PREG_INTERNAL_ERROR but still initialize by-ref $matches to [].
VM binders and JIT matchEx bridges updated; compile failures still
leave $matches untouched.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 4d311a1 into master Jul 30, 2026
1 check failed
@PurHur
PurHur deleted the agent/advanced-stdlib-25313-preg-offset-past-end branch July 30, 2026 10:53
PurHur added a commit that referenced this pull request Jul 30, 2026
Re-emit DateTime/timezone, DOM, and Preg helper TUs after #25340/#25341/#25342
so check-helper-runtime-prelink --strict and release-readiness stay green.

Closes #25347

Co-authored-by: PurHur <PurHur@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Regression: preg_match()/preg_match_all() offset past subject — Zend empty $matches array, VM null (ext/pcre/php_pcre.c)

1 participant