Skip to content

Fix phar_set_inode() using zend_string header instead of filename - #25768

Closed
hohphu8 wants to merge 1 commit into
php:PHP-8.5from
hohphu8:fix-phar-set-inode-zstr-val
Closed

hohphu8 wants to merge 1 commit into
php:PHP-8.5from
hohphu8:fix-phar-set-inode-zstr-val

Conversation

@hohphu8

@hohphu8 hohphu8 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

phar_set_inode() in ext/phar/phar_internal.h passes entry->filename to memcpy(). Since phar_entry_info.filename is a zend_string * in PHP 8.5, this copies from the start of the zend_string struct (header) rather than from the filename characters:

memcpy(tmp + len1, entry->filename, len2);

As a result the inode is not derived from the actual filename, and entries with same-length names can end up with the same st_ino. The fix is to copy from ZSTR_VAL(entry->filename).

Adds a regression test (ext/phar/tests/phar_set_inode_collision.phpt) that checks distinct entries get distinct inodes. It fails before the fix and passes after. I ran it on PHP-8.5 NTS debug and ZTS builds, and the full ext/phar/tests/ passes.

Targeting PHP-8.5 because filename is still a char * in PHP-8.4 (not affected).

Note: I found this through source inspection with an automated/LLM-assisted tool, then reproduced and verified it myself.

Since entry->filename was converted to zend_string* in PHP 8.5, phar_set_inode() copied from the zend_string struct
      header instead of ZSTR_VAL(entry->filename), causing distinct same-length filenames (<= 24 bytes) to collide on st_ino.
@hohphu8
hohphu8 requested a review from LamentXU123 as a code owner November 26, 2026 03:53
Copilot AI balanced review requested due to automatic review settings November 26, 2026 03:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my god wtf /(ㄒoㄒ)/~~

LamentXU123 added a commit that referenced this pull request Nov 26, 2026
* PHP-8.6:
  Fix phar_set_inode() using the zend_string header instead of the filename (#25768)
realFlowControl pushed a commit to realFlowControl/php-src that referenced this pull request Nov 26, 2026
* PHP-8.5:
  Fix phar_set_inode() using the zend_string header instead of the filename (php#25768)
arnaud-lb added a commit to hohphu8/php-src that referenced this pull request Nov 26, 2026
* PHP-8.6:
  Fix stale string metadata in sodium_add() and sodium_increment() (php#25775)
  Sync `session.upload_progress.enabled` default in `php.ini-{development,production}` (php#25743)
  ext/pgsql: fix pg_fetch_object() JIT crash when constructor keeps $this
  Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (php#25777)
  Fix phar_set_inode() using the zend_string header instead of the filename (php#25768)
  Fix phpGH-25360: ZipArchive assertion when error handler throws at shutdown (php#25361)
@hohphu8
hohphu8 deleted the fix-phar-set-inode-zstr-val branch November 26, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants