Skip to content

Fix crash on memory limit error before the opline is saved - #26073

Closed
jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-runtime-jit-save-opline
Closed

jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-runtime-jit-save-opline

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

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 after SAVE_OPLINE(). Before that, it can contain a leftover value from an earlier call:

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 as EG(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.

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.
@jorgsowa jorgsowa closed this in 42f2936 Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants