Skip to content

fix(aot): stabilize explode() indexed string reads#318

Merged
PurHur merged 1 commit into
masterfrom
fix/aot-explode-hashtable-string-ownership
May 19, 2026
Merged

fix(aot): stabilize explode() indexed string reads#318
PurHur merged 1 commit into
masterfrom
fix/aot-explode-hashtable-string-ownership

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented May 19, 2026

Summary

  • Fix intermittent free(): invalid pointer when AOT code uses explode(...)[n] (e.g. second line of test/fixtures/aot/cases/explode.phpt).
  • Pin the packed hashtable across __hashtable__readStringAt, return an owned string via __string__separate, and copy before __value__writeString so hashtable entries are never stolen.

Root cause

Temporary explode() hashtables could be freed before indexed string reads finished. __value__writeString could also take ownership of pointers still stored in the table.

Test output (Docker php-compiler:22.04-dev, LLVM at /opt/llvm9)

./script/docker-ci-local.sh  # harness: tar-pipe when bind-mount empty

=== AotTest ===
OK (44 tests, 52 assertions)

=== explode.phpt stress (stdin compile, 20 runs) ===
failures: 0/20

(Baseline before fix: ~25–35% failure rate on the same stress loop.)

Test plan

  • php vendor/bin/phpunit test/aot/AotTest.php in Docker
  • 20× manual compile/run of explode.phpt FILE section
  • ./script/docker-ci-local.sh full suite (recommended before merge)

Made with Cursor

explode() PHPT failed intermittently with free(): invalid pointer when
reading explode(...)[0] inline: the hashtable could be freed before
__hashtable__readStringAt ran. Pin the table across readStringAt, return
an owned copy via __string__separate, and separate before __value__writeString.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur merged commit 353cf1f into master May 19, 2026
1 check failed
@PurHur PurHur deleted the fix/aot-explode-hashtable-string-ownership branch May 19, 2026 18:44
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