[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Sun, 01 Nov 2026 11:31:56 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143127@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-11-01T12:31:21+01:00 Commit: https://github.com/php/php-src/commit/628fb1f591f56e02de6889983ca190fe81c5ab6b Raw diff: https://github.com/php/php-src/commit/628fb1f591f56e02de6889983ca190fe81c5ab6b.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix deprecation warn in test Fix GH-25092: Double free in Phar::copy() on link and mounted entries Changed paths: A ext/phar/tests/gh25092.phpt M NEWS M ext/phar/phar_object.c M sapi/cli/tests/gh9670.phpt Diff: diff --git a/NEWS b/NEWS index b3f5587be64b..fdfbe3380224 100644 --- a/NEWS +++ b/NEWS @@ -231,6 +231,8 @@ PHP NEWS (Lazizbek Ergashev) . Fixed bug GH-25091 (UAF in phar rename() when source and destination are equal). (Lazizbek Ergashev) + . Fixed bug GH-25092 (Double free in Phar::copy() on link and + mounted entries). (Lazizbek Ergashev) - Phpdbg: . Fix wrong command names. (ndossche, Weilin Du) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index e9f35dfd050c..c0285390ba4e 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -3559,9 +3559,23 @@ PHP_METHOD(Phar, copy) newentry.filename = zend_string_copy(new_file); newentry.fp_refcount = 0; + if (newentry.link) { + newentry.link = estrdup(newentry.link); + } + + if (newentry.tmp) { + newentry.tmp = estrdup(newentry.tmp); + } + if (oldentry->fp_type != PHAR_FP) { if (FAILURE == phar_copy_entry_fp(oldentry, &newentry, &error)) { zend_string_release(newentry.filename); + if (newentry.link) { + efree(newentry.link); + } + if (newentry.tmp) { + efree(newentry.tmp); + } php_stream_close(newentry.fp); zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); diff --git a/ext/phar/tests/gh25092.phpt b/ext/phar/tests/gh25092.phpt new file mode 100644 index 000000000000..604094d76362 --- /dev/null +++ b/ext/phar/tests/gh25092.phpt @@ -0,0 +1,62 @@ +--TEST-- +GH-25092 (Double free in Phar::copy() on link and mounted entries) +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +--FILE-- +<?php +function tar_symlink($name, $target) { + $h = str_pad($name, 100, "\0"); + $h .= "0000777\0"; + $h .= "0000000\0"; + $h .= "0000000\0"; + $h .= "00000000000\0"; + $h .= "00000000000\0"; + $h .= str_repeat(' ', 8); + $h .= '2'; + $h .= str_pad($target, 100, "\0"); + $h .= "ustar\0" . "00"; + $h = str_pad($h, 512, "\0"); + + $sum = 0; + for ($i = 0; $i < 512; $i++) { + $sum += ord($h[$i]); + } + return substr_replace($h, sprintf("%06o\0 ", $sum), 148, 8); +} + +$tar = __DIR__ . '/gh25092.tar'; +file_put_contents($tar, tar_symlink('l', 'a') . str_repeat("\0", 1024)); + +$t = new PharData($tar); +$t->copy('l', 'l2'); +unset($t); + +$t = new PharData($tar); +var_dump(isset($t['l']), isset($t['l2'])); +unset($t); + +$phar = __DIR__ . '/gh25092.phar'; +file_put_contents(__DIR__ . '/gh25092.txt', 'hello'); + +$p = new Phar($phar); +$p->addFromString('x.txt', 'x'); +$p->setStub('<?php __HALT_COMPILER(); ?>'); +unset($p); + +$p = new Phar($phar); +Phar::mount('phar://' . $phar . '/m.txt', __DIR__ . '/gh25092.txt'); +$p->copy('m.txt', 'c.txt'); +var_dump(isset($p['c.txt'])); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh25092.tar'); +@unlink(__DIR__ . '/gh25092.phar'); +@unlink(__DIR__ . '/gh25092.txt'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/sapi/cli/tests/gh9670.phpt b/sapi/cli/tests/gh9670.phpt index 2df588db372c..a84bc9713f06 100644 --- a/sapi/cli/tests/gh9670.phpt +++ b/sapi/cli/tests/gh9670.phpt @@ -9,7 +9,7 @@ include "skipif.inc"; $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); -foreach (explode("\n", $php -n -h) as $line) { +foreach (explode("\n", shell_exec("$php -n -h")) as $line) { if (preg_match('/^ -[Cq] /', $line)) { echo $line, "\n"; }

« previous php.cvs (#143127) next »