[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
| From: | ndossche | Date: | Sun, 01 Nov 2026 10:59:30 +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-143120@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-11-01T11:58:26+01:00
Commit: https://github.com/php/php-src/commit/bec9a009fd62db735eb91a1a37766e187a69f36a
Raw diff: https://github.com/php/php-src/commit/bec9a009fd62db735eb91a1a37766e187a69f36a.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
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 557d2a3783d9..201799f9b569 100644
--- a/NEWS
+++ b/NEWS
@@ -226,6 +226,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)
- Phpdbg:
. Fix wrong command names. (ndossche, Weilin Du)
diff --git a/ext/phar/stream.c b/ext/phar/stream.c
index 6cf3d61f8697..7cb417926e3e 100644
--- a/ext/phar/stream.c
+++ b/ext/phar/stream.c
@@ -838,12 +838,18 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char
*url_from
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to
\"%s\" from extracted phar archive, source has been deleted", 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 */
entry->is_deleted = 1;
entry->fp = NULL;
ZVAL_UNDEF(&entry->metadata_tracker.val);
+ entry->metadata_tracker.str = NULL;
entry->link = entry->tmp = NULL;
source = 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"