[php-src] master: Merge branch 'PHP-8.6'
| From: | Ilia Alshanetsky | Date: | Sun, 01 Nov 2026 15:19:22 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143157@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-01T10:12:18-05:00
Commit: https://github.com/php/php-src/commit/b8cca1cf7e333b3b77ef303c6af065a985b82de2
Raw diff: https://github.com/php/php-src/commit/b8cca1cf7e333b3b77ef303c6af065a985b82de2.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix GH-24531: Crash when flushing a renamed zip-based phar
Changed paths:
A ext/phar/tests/zip/gh24531.phpt
M ext/phar/zip.c
Diff:
diff --git a/ext/phar/tests/zip/gh24531.phpt b/ext/phar/tests/zip/gh24531.phpt
new file mode 100644
index 000000000000..44f9e1736060
--- /dev/null
+++ b/ext/phar/tests/zip/gh24531.phpt
@@ -0,0 +1,32 @@
+--TEST--
+GH-24531 (NULL pointer dereference when flushing a zip-based phar whose file was renamed)
+--EXTENSIONS--
+phar
+--INI--
+phar.readonly=0
+phar.require_hash=0
+--FILE--
+<?php
+$source = __DIR__ . '/gh24531.phar.zip';
+$target = __DIR__ . '/gh24531-renamed.phar.zip';
+
+$phar = new Phar($source);
+$phar->addFromString('first', 'first');
+unset($phar);
+
+rename($source, $target);
+
+try {
+ $phar = new Phar($source);
+ $phar->addFromString('second', 'second');
+} catch (PharException $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/gh24531.phar.zip');
+@unlink(__DIR__ . '/gh24531-renamed.phar.zip');
+?>
+--EXPECTF--
+PharException: phar zip flush of "%sgh24531.phar.zip" failed: unable to copy contents of
file "first" while creating zip-based phar "%sgh24531.phar.zip"
diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index b1cfd897fa6c..13c34d8a3b0f 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -1152,7 +1152,7 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /*
{{{
}
}
- if (!entry->is_dir && entry->compressed_filesize && SUCCESS !=
php_stream_copy_to_stream_ex(p->old, p->filefp, entry->compressed_filesize, NULL)) {
+ if (!entry->is_dir && entry->compressed_filesize && (!p->old || SUCCESS
!= php_stream_copy_to_stream_ex(p->old, p->filefp, entry->compressed_filesize, NULL))) {
spprintf(p->error, 0, "unable to copy contents of file \"%s\" while creating
zip-based phar \"%s\"", ZSTR_VAL(entry->filename),
ZSTR_VAL(entry->phar->fname));
return ZEND_HASH_APPLY_STOP;
}