AOT: fix multi-arg sprintf/printf segfault — bypass broken NestedJIT pack path - #32601
Merged
Merged
Conversation
…pack path
Multi-arg sprintf("%d-%d", 3, 4) and printf("%s/%s", "a1", "b2") segfaulted
in AOT because the NestedJIT pack path (phpc_pack_argv_serialize → SprintfJitHelper)
returned null, causing echo of a null __string__* pointer (#31963 class).
The single-arg fast path via libc snprintf (SprintfSnprintfRuntime::formatOneArg)
worked correctly. This extends the same approach to multi-arg: at compile time
we know the arg count and types, so JitSprintf::format() now emits a direct
snprintf(buf, size, fmt, typed1, typed2, ...) call, extracting each arg as the
correct C type (i64 for longs, double for floats, char* for strings).
JitPrintf::format() for multi-arg now delegates to JitSprintf::formatWithFmt()
and echoes the result, instead of going through __compiler_printf's bridge.
Verified:
- aot-smoke: 8/8 (no regressions)
- differential-sweep --aot: e05_sprintf.php now passes (was DIFF/segfault)
- No new failures in sweep vs pre-change baseline
Closes #31968 (child)
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
sprintf("%d-%d", 3, 4)andprintf("%s/%s", "a1", "b2")segfaulted in AOT because the NestedJIT pack path (phpc_pack_argv_serialize→SprintfJitHelper) returned null, causing echo of a null__string__*pointer (AOT: float→string conversion crashes — printf/number_format/json_encode/serialize/strval all segfault on floats #31963 class).snprintf(SprintfSnprintfRuntime::formatOneArg) worked correctly. This extends the same approach to multi-arg: at compile time we know the arg count and types, soJitSprintf::format()now emits a directsnprintf(buf, size, fmt, typed1, typed2, ...)call, extracting each arg as the correct C type (i64 for longs, double for floats, char* for strings).JitPrintf::format()for multi-arg now delegates toJitSprintf::formatWithFmt()and echoes the result, instead of going through__compiler_printf's bridge.Closes #31968 (child: multi-arg sprintf/printf)
Verification
e05_sprintf.phpnow passes (was DIFF/segfault on master)sprintf("%d-%d", 3, 4)→3-4✓ (unaffected, uses VmSprintf)Not covered: full compliance suite (VMTest/JITTest),
--strictself-hostTest plan
./script/aot-smoke.sh— 8/8./script/differential-sweep.sh --aot— e05_sprintf fixed, no regressionssprintf("%d-%d", 3, 4)→3-4,printf("%s/%s\n", "a1", "b2")→a1/b2Made with Cursor