Repository navigation
Conversation
The memory limit error reads EX(opline) for its line number. At function entry it is uninitialized with global register VMs and JIT-compiled callers, so an allocation before SAVE_OPLINE() dereferenced garbage. Fall back to the first line of the function when EX(opline) does not point into the frame's opcodes.
iliaal
approved these changes
Dec 4, 2026
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.
What it fixes
PHP can segfault instead of printing "Allowed memory size exhausted" when it hits the memory limit right at the start of a function call.
The error message looks up the current line number through
EX(opline). That field only holds a valid value afterSAVE_OPLINE(). Before that, it can contain a leftover value from an earlier call:CONCATfast path),INIT_FCALL(likely the cause of SEGV zend_execute_API.c runtime error: member access within misaligned address 0x000000000002 for type 'const zend_op' #22521).PHP then dereferences that pointer and crashes. GCC builds, JIT-compiled code and the 8.5+ VM all hit this, on both the soft and hard memory limit. The existing guard from GH-9933 only caught a NULL opline, not a leftover pointer.
Why this fix
zend_get_executed_lineno()now uses the opline only if it points inside the current function's opcodes, or is one of the engine's special oplines such asEG(exception_op). Otherwise it falls back to the function's first line.The memory limit can be hit wherever memory is allocated, and many of those places run before
SAVE_OPLINE(). Adding saves one site at a time has already been tried (GH-18899, GH-24337, GH-18289) and missed cases. Checking at the single place that reads the opline covers all of them, and valid code takes the same path as before.Related to GH-22521 and #22524.