[php-src] master: Merge branch 'PHP-8.6'

From: Date: Sun, 01 Nov 2026 10:59:33 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143121@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-11-01T11:59:22+01:00 Commit: https://github.com/php/php-src/commit/03fbd466ea788295ae1616e54dceceac29bb6024 Raw diff: https://github.com/php/php-src/commit/03fbd466ea788295ae1616e54dceceac29bb6024.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix GH-25091: UAF in phar rename() when source and destination are equal Fix GH-25090: UAF in phar rename() of an entry with metadata Changed paths: A ext/phar/tests/gh25090.phpt A ext/phar/tests/gh25091.phpt M ext/phar/stream.c Diff: diff --git a/ext/phar/stream.c b/ext/phar/stream.c index ef8b153b7e94..86ec22e719fe 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -865,6 +865,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from url_from, url_to); return 0; } + if (zend_string_equals(resource_from->path, resource_to->path)) { + php_url_free(resource_from); + php_url_free(resource_to); + return 1; + } /* transfer all data over to the new entry */ memcpy((void *) &new, (void *) entry, sizeof(phar_entry_info)); /* mark the old one for deletion */ @@ -873,6 +878,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from ZVAL_UNDEF(&entry->metadata_tracker.val); entry->symlink = NULL; entry->tmp = NULL; + entry->metadata_tracker.str = NULL; source = entry; /* add to the manifest, and then store the pointer to the new guy in entry diff --git a/ext/phar/tests/gh25090.phpt b/ext/phar/tests/gh25090.phpt new file mode 100644 index 000000000000..4860e5abfe5e --- /dev/null +++ b/ext/phar/tests/gh25090.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-25090 (Use-after-free in phar_wrapper_rename() with entry metadata) +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +--FILE-- +<?php +$fname = __DIR__ . '/gh25090.phar'; +$phar = new Phar($fname); +$phar['a'] = 'x'; +$phar['a']->setMetadata(['k' => 'v']); +rename('phar://' . $fname . '/a', 'phar://' . $fname . '/b'); +$phar['c'] = 'y'; +var_dump($phar['b']->getMetadata()); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh25090.phar'); +?> +--EXPECT-- +array(1) { + ["k"]=> + string(1) "v" +} diff --git a/ext/phar/tests/gh25091.phpt b/ext/phar/tests/gh25091.phpt new file mode 100644 index 000000000000..3df6c7940eba --- /dev/null +++ b/ext/phar/tests/gh25091.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-25091: Use-after-free in rename() when source and destination are the same entry +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +--FILE-- +<?php +$fname = __DIR__ . '/gh25091.phar'; + +$phar = new Phar($fname); +$phar['a'] = 'contents'; +unset($phar); + +var_dump(rename('phar://' . $fname . '/a', 'phar://' . $fname . '/a')); +var_dump(file_get_contents('phar://' . $fname . '/a')); +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh25091.phar'); +?> +--EXPECT-- +bool(true) +string(8) "contents"

« previous php.cvs (#143121) next »