[php-src] Issue #25091: ext/phar: use-after-free in phar_wrapper_rename() when source and destination are identical

From: Date: Sat, 31 Oct 2026 16:36:01 +0000
Subject: [php-src] Issue #25091: ext/phar: use-after-free in phar_wrapper_rename() when source and destination are identical
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253954@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25091 Author: cxxz16 ### Description phar_wrapper_rename() with from == to: source entry destroyed in place, then dereferenced Category: heap-use-after-free READ; CWE-416. Context: rename() of a phar:// entry onto its own name. Observed: ASan reports heap-use-after-free READ of size 8 in phar_open_entry_fp (ext/phar/util.c:810), reached through phar_copy_entry_fp (util.c:745) from phar_wrapper_rename (ext/phar/stream.c:883). The freed 160-byte region is the source phar_entry_info. Relevant source: ext/phar/stream.c:880-883 (zend_hash_str_update_mem on the same key destroys the stored entry via destroy_phar_manifest_entry / pefree, ext/phar/phar.c:389-394, before phar_copy_entry_fp(source, ...) runs with source pointing at it). Source assessment: with identical from/to keys, the manifest update destructs the very entry that source still references; no same-key guard exists on this path. Expected: bail out or take a reference when from == to. [poc.php](https://github.com/user-attachments/files/34221525/poc.php) [PHAR-03-rename-self-uaf.asan.txt](https://github.com/user-attachments/files/34221531/PHAR-03-rename-self-uaf.asan.txt) ### PHP Version ```plain Component: ext/phar in php-src master, commit b9ea38ef639f5b9bbb67d27834be9c52b922520b (cloned 2026-10-21). PHP: 8.7.0-dev (cli), NTS. Platform: Linux x86-64 (Ubuntu 22.04 container, Docker). Sanitizer: AddressSanitizer (-fsanitize=address -g -O1). Configure: --disable-all --enable-cli --enable-phar --with-zlib --without-pcre-jit. Recorded runtime environment: USE_ZEND_ALLOC=0 ZEND_DONT_UNLOAD_MODULES=1 ASAN_OPTIONS=abort_on_error=0:detect_leaks=0 write-path tests additionally: php -d phar.readonly=0 ``` ### Operating System _No response_

« previous php.bugs (#253954) next »