Skip to content

ext/phar: out-of-bounds read/write in Phar::webPhar() 301 redirect (full path length used instead of basename) #25093

Closed

Description

@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
router.php
run.sh

PHAR-05-webphar-oob.asan.txt

PHP Version

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

Activity

  1. added 2 commits that reference this issue on Nov 2, 2026
    2ff2085
    722feed
  2. added a commit that references this issue on Nov 2, 2026
    36c80e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions