[php-src] PHP-8.6: Fix phar_set_inode() using the zend_string header instead of the filename (#25768)

From: Date: Thu, 26 Nov 2026 10:02:49 +0000
Subject: [php-src] PHP-8.6: Fix phar_set_inode() using the zend_string header instead of the filename (#25768)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144206@lists.php.net to get a copy of this message
Author: Hohphu (hohphu8) Committer: Weilin Du (LamentXU123) Date: 2026-11-26T17:59:09+08:00 Commit: https://github.com/php/php-src/commit/dc4bfefdb1abbad851f02b3e280ff41314a00dfb Raw diff: https://github.com/php/php-src/commit/dc4bfefdb1abbad851f02b3e280ff41314a00dfb.diff Fix phar_set_inode() using the zend_string header instead of the filename (#25768) Copy the filename bytes when computing the inode for a Phar entry. Copying from the zend_string header can give entries with different, same-length filenames the same inode number. Add a regression test that checks the inodes after reopening the archive in a separate process. Closes #25768 Changed paths: A ext/phar/tests/phar_set_inode_collision.phpt M NEWS M ext/phar/phar_internal.h Diff: diff --git a/NEWS b/NEWS index 5a6f4f516620..aff63aeb7dbb 100644 --- a/NEWS +++ b/NEWS @@ -166,6 +166,8 @@ PHP NEWS for an empty set is modified). (Tomasz Kowalczyk) - Phar: + . Fixed Phar file stats using the string header instead of the entry + filename to compute the inode number. (Hohphu) . Fixed bug GH-25528 (Phar::setSignatureAlgorithm(): OpenSSL signing reads a freed private key). (Artem Ukrainskiy) diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 10e6a234edd9..4ea66f7b9f8b 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -425,7 +425,7 @@ static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */ } len2 = MIN(tmp_len - len1, ZSTR_LEN(entry->filename)); - memcpy(tmp + len1, entry->filename, len2); + memcpy(tmp + len1, ZSTR_VAL(entry->filename), len2); entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len); } diff --git a/ext/phar/tests/phar_set_inode_collision.phpt b/ext/phar/tests/phar_set_inode_collision.phpt new file mode 100644 index 000000000000..b3ec0ba471f9 --- /dev/null +++ b/ext/phar/tests/phar_set_inode_collision.phpt @@ -0,0 +1,53 @@ +--TEST-- +Phar: distinct same-length filenames in a phar archive should not collide on st_ino (phar_set_inode) +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +--FILE-- +<?php +$fname = __DIR__ . '/h13_inode_test.phar'; +@unlink($fname); + +$p = new Phar($fname); +$p['aaaaa.txt'] = '1'; +$p['bbbbb.txt'] = '2'; +$p['cccccc.txt'] = '3'; +unset($p); + +// Verify in a clean subprocess (-n) so PHAR_G(phar_fname_map) cache is not reused +$code = <<<'PHP' +$f = $argv[1]; +$a = stat("phar://$f/aaaaa.txt")["ino"]; +$b = stat("phar://$f/bbbbb.txt")["ino"]; +$c = stat("phar://$f/cccccc.txt")["ino"]; +var_dump($a > 0, $a !== $b, $a !== $c, $b !== $c); +PHP; + +$spec = [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], +]; +$proc = proc_open([PHP_BINARY, '-n', '-r', $code, '--', $fname], $spec, $pipes); +fclose($pipes[0]); +$stdout = stream_get_contents($pipes[1]); +$stderr = stream_get_contents($pipes[2]); +fclose($pipes[1]); +fclose($pipes[2]); +$rc = proc_close($proc); + +var_dump($rc === 0, $stderr === ''); +echo $stdout; +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/h13_inode_test.phar'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true)

« previous php.cvs (#144206) next »