[php-src] PR #25783: Fix GH-25723: Avoid UAF and double-free in spl_autoload_unregister('spl_autoload_call')

From: Date: Thu, 26 Nov 2026 12:35:00 +0000
Subject: [php-src] PR #25783: Fix GH-25723: Avoid UAF and double-free in spl_autoload_unregister('spl_autoload_call')
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41048@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25783 Author: prateekbhujel spl_autoload_unregister('spl_autoload_call') previously called zend_hash_clean(spl_autoload_functions) directly. Because zend_hash_clean() invokes element destructors before clearing buckets or resetting nNumUsed, an autoloader object whose __destruct() re-enters spl_autoload_unregister() (on itself or on another autoloader still in the table) finds and deletes the bucket a second time, resulting in a use-after-free of the object and double-free of autoload_func_info. Re-entering spl_autoload_register() from such a destructor also silently dropped and leaked the newly registered loader. ### Fix Move the contents of spl_autoload_functions into a stack-local HashTable tmp, re-initialize spl_autoload_functions in place (zend_hash_init() + zend_hash_real_init_mixed()), and then call zend_hash_destroy(&tmp): - Keeps the spl_autoload_functions pointer intact for any active spl_perform_autoload() iteration (nNumUsed == 0, so iteration terminates cleanly). - Ensures destructors see an already-empty table: re-entrant spl_autoload_unregister() returns false, re-entrant spl_autoload_unregister('spl_autoload_call') is a no-op, re-entrant spl_autoload_register() persists without leaking, and exceptions thrown in __destruct() still finish destroying remaining detached entries cleanly. ### Merge-up note for PHP-8.6 / master In PHP-8.6, autoloader management moved to Zend/zend_autoload.c, where zend_autoload_clean_class_loaders() has the identical zend_hash_clean(zend_class_autoload_functions) call. Applying the same detach-and-destroy pattern there (re-initializing with zend_autoload_callback_zval_destroy) will make ext/spl/tests/gh25723.phpt pass on PHP-8.6 and master too. Closes GH-25723.

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