[php-src] Issue #25092: ext/phar: double free in Phar::copy() on tar symlink entries

From: Date: Sat, 31 Oct 2026 16:43:14 +0000
Subject: [php-src] Issue #25092: ext/phar: double free in Phar::copy() on tar symlink entries
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253955@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25092 Author: cxxz16 ### Description Phar::copy(): symlink zend_string owned twice Category: double free (first invalid access reported as heap-use-after-free READ of the refcount); CWE-415. Context: PharData::copy() on a tar symlink entry (fp_type == PHAR_FP). Observed: ASan reports heap-use-after-free READ of size 4 in zend_string_release_ex (Zend/zend_string.h:411) from destroy_phar_manifest_entry_int (ext/phar/phar.c:378) during manifest destruction at request shutdown: the second release of the same 32-byte symlink zend_string. Relevant source: ext/phar/phar_object.c:3449 (memcpy of phar_entry_info without zend_string_addref on symlink); tar symlink entries set fp_type = PHAR_FP (ext/phar/tar.c:564) and skip phar_copy_entry_fp, so no later code path re-establishes exclusive ownership. Source assessment: the shallow copy leaves symlink shared between the old and new manifest entries with refcount unchanged; both entries release it. Expected: zend_string_copy() (or equivalent addref) for symlink in the copy path, as already done for metadata via phar_metadata_tracker_clone(). Evidence: asan/PHAR-04-copy-symlink-doublefree.asan.txt. PoC: poc/04-copy-symlink-doublefree/ (make_tar.py builds a tar with a SYMTYPE entry; poc.php calls $t->copy('l','l2')). Note: Phar::addLink() no longer exists on master, so the symlink entry is constructed externally. [PHAR-04-copy-symlink-doublefree.asan.txt](https://github.com/user-attachments/files/34221652/PHAR-04-copy-symlink-doublefree.asan.txt) [poc.php](https://github.com/user-attachments/files/34221655/poc.php) [make_tar.py](https://github.com/user-attachments/files/34221654/make_tar.py) ### 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 (#253955) next »