[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | ndossche | Date: | Sun, 01 Nov 2026 10:59:32 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143119@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-11-01T11:59:18+01:00
Commit: https://github.com/php/php-src/commit/3cfaeecdb500d7cf2861721ff6ceebc6cd20f089
Raw diff: https://github.com/php/php-src/commit/3cfaeecdb500d7cf2861721ff6ceebc6cd20f089.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
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 NEWS
M ext/phar/stream.c
Diff:
diff --git a/NEWS b/NEWS
index 9004019b3a59..52aee8b6eb10 100644
--- a/NEWS
+++ b/NEWS
@@ -157,6 +157,10 @@ PHP NEWS
compressed contents after changing compression). (Raphael Paez)
. Fixed bug GH-24740 (Oversized tar metadata exhausts the memory limit).
(Lazizbek Ergashev)
+ . Fixed bug GH-25090 (UAF in phar rename() of an entry with metadata).
+ (Lazizbek Ergashev)
+ . Fixed bug GH-25091 (UAF in phar rename() when source and destination
+ are equal). (Lazizbek Ergashev)
- Reflection:
. Fixed bug GH-21768 (Assertion failure in ReflectionProperty::isReadable()
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"