[php-src] PR #21915: Fix GH-20482: heap use-after-free in ZEND_ASSIGN_DIM via re-entrant user output handler

From: Date: Thu, 30 Apr 2026 10:15:50 +0000
Subject: [php-src] PR #21915: Fix GH-20482: heap use-after-free in ZEND_ASSIGN_DIM via re-entrant user output handler
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35954@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21915 Author: lacatoire Fixes GH-20482. When ZEND_ASSIGN_DIM evaluates an undefined CV as the RHS, the warning emitted by zval_undefined_cv() can be routed through a user output handler (e.g. via ob_start with a small chunk size). The handler is allowed to run arbitrary PHP code, including reassigning the variable that holds the array we are writing to. That drops the array's last reference and zend_array_destroy frees its buckets while the VM still holds the previously-fetched variable_ptr, causing a UAF on the subsequent zend_assign_to_variable_ex. Mirrors the protection already used in the IS_UNUSED branch of ZEND_ASSIGN_DIM (and in slow_index_convert, see b594a95a2f6): temporarily addref the target HashTable around zval_undefined_cv() so the array survives the reentrant user code, then refetch the dimension address afterwards (the previous variable_ptr may have been invalidated even when the array survived, e.g. if user code added entries triggering a rehash). Marked as **draft** because I'd value maintainer eyes on the regen of zend_vm_execute.h and the choice to refetch variable_ptr rather than just protect via addref/delref like the IS_UNUSED branch (which doesn't pre-fetch the bucket). Regression test: Zend/tests/gh20482_assign_dim_uaf_output_handler.phpt.

« previous php.git-pulls (#35954) next »