Conversation
zv::Args stored a HashTable argument with a bare ZVAL_ARR, which types an immutable table (the shared zend_empty_array of a PHP [] literal or zv::Arr::empty()) as refcounted. When the argument vector reached a PHP method, the addref in zend_call_function() wrote into read-only memory (SIGBUS on macOS arm64, SIGSEGV on Linux). ForeachHandler hit this for a constant array without keys: its conditional holder tables stay empty and are handed to a PHP override of MutatingScope::addConditionalExpressions(). Wrap immutable tables as plain IS_ARRAY, like zv::Arr::adoptTable() and copyOfTable() do. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you! I got inspired by your PR and opened #6561. |
Member
|
BTW @zonuexe I'd love to hear how |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
zv::Args::set(zval *, HashTable *)stored a table argument with a bareZVAL_ARR. For an immutable table (the sharedzend_empty_arrayof a PHP[]literal orzv::Arr::empty()) this sets the refcounted type info, and when the argument vector reaches a PHP method throughpt_type_call(), the addref inzend_call_function()writes into read-only memory: SIGBUS on macOS arm64, SIGSEGV on Linux. This is the trap documented under "Zend-level gotchas" inturbo-ext/CLAUDE.md.The reachable path is
pt_mutating_scope_add_conditional_expressions(): when the scope's class overridesaddConditionalExpressions(), the holders go to the PHP method throughzv::Args.ForeachHandler's constant-array branch starts its holder tables aszv::Arr::empty()and passes them on still empty when the constant array has no keys (foreach ($a as $k => $v)with$abeingarray{}).The fix wraps immutable tables as plain
IS_ARRAY, the same idiomzv::Arr::adoptTable()andcopyOfTable()already use.With the
HashTable *overload ofzv::Args::set()temporarily deleted, the only instantiation that failed to compile was the one inpt_mutating_scope_add_conditional_expressions(), so this is the only affected call site. The other rawZVAL_ARRuses wrap freshly allocated tables or are read-only views that are never addref'ed.ForeachHandlerTestdrivesForeachHandler::processStmt()with aMutatingScopesubclass that records whataddConditionalExpressions()receives, once forarray{}and once for a one-key array. With the extension loaded, thearray{}case exits with 138 before this change; without the extension, both cases pass before and after. The turbo-run legs run the test suite with the extension loaded, so CI covers it there.Verified locally on macOS arm64 (PHP 8.5): strict build,
smoke.php(ALL OK),signature-parity.php,side-by-side.php,walk-trace.php --shards=8(identical), the full test suite with the extension loaded andRuntime::isShadowing()true (22235 tests OK), andmake phpstan. The second commit ismake bump-turbo.