Skip to content

Fix GH-20042: SEGV in array.c when error handler clobbers IAP object#6

Closed
iliaal wants to merge 1 commit intomasterfrom
fix/gh-20042-iap-object-clobber
Closed

Fix GH-20042: SEGV in array.c when error handler clobbers IAP object#6
iliaal wants to merge 1 commit intomasterfrom
fix/gh-20042-iap-object-clobber

Conversation

@iliaal
Copy link
Owner

@iliaal iliaal commented Mar 16, 2026

Summary

  • get_ht_for_iap() emits a deprecation for object IAP args, triggering the user error handler. If the handler clobbers the by-ref variable, the code reads a dead zval as an object pointer and segfaults.
  • After the deprecation, re-check that the zval is still IS_OBJECT. Return NULL if clobbered. All 6 callers (end/prev/next/reset/current/key) handle NULL gracefully.
  • Regression test covers all 6 functions.

Test plan

  • Original reporter's reproducer no longer crashes
  • ndossche's minimized reproducer no longer crashes
  • .phpt test FAILs on unpatched build, PASSes on patched
  • Full ext/standard/tests/array/ suite: 843/843 passed, 0 regressions

Fixes php#20042

get_ht_for_iap() emits a deprecation notice for object arguments,
which can trigger a user error handler that modifies the by-reference
variable. After the handler returns, the zval may no longer be an
object, causing a segfault when accessing it as one.

Re-check the zval type after emitting the deprecation and bail out
if it was clobbered.
@iliaal iliaal force-pushed the fix/gh-20042-iap-object-clobber branch from 520b5ff to 905cb37 Compare March 16, 2026 11:53
@iliaal
Copy link
Owner Author

iliaal commented Mar 16, 2026

Submitted upstream as php#21461

@iliaal iliaal closed this Mar 16, 2026
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.

SEGV array.c

1 participant