[php-src] Issue #25093: ext/phar: out-of-bounds read/write in Phar::webPhar() 301 redirect (full path length used instead of basename)
| From: | cxxz16 | Date: | Sat, 31 Oct 2026 16:45:45 +0000 |
| Subject: | [php-src] Issue #25093: ext/phar: out-of-bounds read/write in Phar::webPhar() 301 redirect (full path length used instead of basename) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253956@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25093
Author: cxxz16
### Description
webPhar() 301 redirect: full-path length used instead of basename length
Category: heap-buffer-overflow READ + 1-byte WRITE of '\0'; CWE-125/CWE-787.
Context: non-CGI SAPI (e.g. php -S), request URI ending exactly at the phar
basename (no PATH_INFO), phar located in a nested directory; default stub
calls Phar::webPhar().
Observed: ASan reports heap-buffer-overflow READ of size 1 in
zim_Phar_webPhar (ext/phar/phar_object.c:770) under the cli-server SAPI;
the read address lands (fname_len - basename_len) bytes past the end of the
SAPI request_uri buffer (PoC: 15 bytes past, path /work/site/dir/app.phar).
Relevant source: ext/phar/phar_object.c:769-771
(tmp = strstr(path_info, basename) + fname_len; sa = *tmp; *tmp = '\0';),
restore at :783.
Source assessment: the offset should advance by the basename length but uses
the full server-side path length (fname_len); the mismatch equals the phar's
directory prefix length. The same function uses the correct
(fname_len - (basename - fname)) computation when building pt at :691.
Expected: advance by basename length.
[make_phar.php](https://github.com/user-attachments/files/34221682/make_phar.php)
[router.php](https://github.com/user-attachments/files/34221681/router.php)
[run.sh](https://github.com/user-attachments/files/34221684/run.sh)
[PHAR-05-webphar-oob.asan.txt](https://github.com/user-attachments/files/34221688/PHAR-05-webphar-oob.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
runs under the CLI development server (php -S with a router script).
```
### Operating System
_No response_