[php-src] master: Merge branch 'PHP-8.6'
| From: | Weilin Du | Date: | Fri, 30 Oct 2026 18:03:41 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143022@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-10-31T01:57:50+08:00
Commit: https://github.com/php/php-src/commit/1a72e5f25423fa67c7ef6ff325a7c300e02b25a7
Raw diff: https://github.com/php/php-src/commit/1a72e5f25423fa67c7ef6ff325a7c300e02b25a7.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Regenerate stub file hash
Fix GH-8469: Phar::decompressFiles() keeps compressed contents (#25045)
Changed paths:
A ext/phar/tests/gh8469.phpt
M ext/phar/phar_object.c
M ext/zend_test/test_arginfo.h
M ext/zend_test/test_decl.h
M ext/zend_test/test_legacy_arginfo.h
Diff:
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index c45ae86a3fa5..d43dd4ca4f00 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -3107,6 +3107,30 @@ static int phar_set_compression(zval *zv, void *argument) /* {{{ */
}
/* }}} */
+typedef struct {
+ uint32_t compress;
+ char *error;
+} phar_compression_args;
+
+static int phar_decompress_for_compression_change(zval *zv, void *argument) /* {{{ */
+{
+ phar_entry_info *entry = (phar_entry_info *)Z_PTR_P(zv);
+ phar_compression_args *args = (phar_compression_args *)argument;
+ uint32_t current = entry->flags & PHAR_ENT_COMPRESSION_MASK;
+
+ if (entry->is_deleted || entry->is_dir || !current || current == args->compress) {
+ return ZEND_HASH_APPLY_KEEP;
+ }
+
+ /* phar_flush() would otherwise copy the old compressed bytes as the new contents */
+ if (FAILURE == phar_open_entry_fp(entry, &args->error, 0)) {
+ return ZEND_HASH_APPLY_STOP;
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
static int phar_test_compression(zval *zv, void *argument) /* {{{ */
{
const phar_entry_info *entry = Z_PTR_P(zv);
@@ -3133,9 +3157,18 @@ static int phar_test_compression(zval *zv, void *argument) /* {{{ */
}
/* }}} */
-static void pharobj_set_compression(HashTable *manifest, uint32_t compress) /* {{{ */
+static zend_result pharobj_set_compression(HashTable *manifest, uint32_t compress, char **error) /*
{{{ */
{
+ phar_compression_args args = { .compress = compress, .error = NULL };
+
+ zend_hash_apply_with_argument(manifest, phar_decompress_for_compression_change, &args);
+ if (args.error) {
+ *error = args.error;
+ return FAILURE;
+ }
+
zend_hash_apply_with_argument(manifest, phar_set_compression, &compress);
+ return SUCCESS;
}
/* }}} */
@@ -3326,7 +3359,11 @@ PHP_METHOD(Phar, compressFiles)
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%pS\" is persistent,
unable to copy on write", phar_obj->archive->fname);
RETURN_THROWS();
}
- pharobj_set_compression(&phar_obj->archive->manifest, flags);
+ if (FAILURE == pharobj_set_compression(&phar_obj->archive->manifest, flags, &error))
{
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s", error);
+ efree(error);
+ RETURN_THROWS();
+ }
phar_obj->archive->is_modified = 1;
phar_flush(phar_obj->archive, &error);
@@ -3365,7 +3402,11 @@ PHP_METHOD(Phar, decompressFiles)
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%pS\" is persistent,
unable to copy on write", phar_obj->archive->fname);
RETURN_THROWS();
}
- pharobj_set_compression(&phar_obj->archive->manifest, PHAR_ENT_COMPRESSED_NONE);
+ if (FAILURE == pharobj_set_compression(&phar_obj->archive->manifest,
PHAR_ENT_COMPRESSED_NONE, &error)) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s", error);
+ efree(error);
+ RETURN_THROWS();
+ }
}
phar_obj->archive->is_modified = 1;
diff --git a/ext/phar/tests/gh8469.phpt b/ext/phar/tests/gh8469.phpt
new file mode 100644
index 000000000000..ca34dca256cc
--- /dev/null
+++ b/ext/phar/tests/gh8469.phpt
@@ -0,0 +1,59 @@
+--TEST--
+GH-8469 (Phar::decompressFiles() and Phar::compressFiles() keep the old compressed contents)
+--EXTENSIONS--
+phar
+zlib
+bz2
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$contents = str_repeat('four score and seven years ago ', 10);
+
+foreach (['phar', 'phar.zip'] as $ext) {
+ $fname = __DIR__ . "/gh8469.$ext";
+ $phar = new Phar($fname);
+ $phar['a.txt'] = $contents;
+ $phar['b.txt'] = 'our fathers';
+ $phar->addEmptyDir('dir');
+
+ $phar->compressFiles(Phar::GZ);
+ $phar->compressFiles(Phar::BZ2);
+ var_dump($phar['a.txt']->isCompressed(Phar::BZ2));
+ var_dump($phar['a.txt']->getContent() === $contents);
+
+ var_dump($phar->decompressFiles());
+ var_dump($phar['a.txt']->isCompressed());
+ var_dump($phar['a.txt']->getContent() === $contents);
+ var_dump($phar['b.txt']->getContent());
+ unset($phar);
+
+ $phar = new Phar($fname);
+ var_dump($phar['a.txt']->getContent() === $contents);
+ var_dump(file_get_contents("phar://$fname/b.txt"));
+ unset($phar);
+}
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/gh8469.phar');
+@unlink(__DIR__ . '/gh8469.phar.zip');
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+string(11) "our fathers"
+bool(true)
+string(11) "our fathers"
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+string(11) "our fathers"
+bool(true)
+string(11) "our fathers"
diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h
index d6fa8896c42b..c2509001e45c 100644
--- a/ext/zend_test/test_arginfo.h
+++ b/ext/zend_test/test_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 55bb2e6d209ea4030e3edfd604fc5ce4d14267f0
+ * Stub hash: 55c444ca86bbbd773e43ddb6bd470efb371c45a4
* Has decl header: yes */
#include "zend_attributes.h"
diff --git a/ext/zend_test/test_decl.h b/ext/zend_test/test_decl.h
index 35e929d1a306..291f7ab87afb 100644
--- a/ext/zend_test/test_decl.h
+++ b/ext/zend_test/test_decl.h
@@ -1,8 +1,8 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 55bb2e6d209ea4030e3edfd604fc5ce4d14267f0 */
+ * Stub hash: 55c444ca86bbbd773e43ddb6bd470efb371c45a4 */
-#ifndef ZEND_TEST_DECL_55bb2e6d209ea4030e3edfd604fc5ce4d14267f0_H
-#define ZEND_TEST_DECL_55bb2e6d209ea4030e3edfd604fc5ce4d14267f0_H
+#ifndef ZEND_TEST_DECL_55c444ca86bbbd773e43ddb6bd470efb371c45a4_H
+#define ZEND_TEST_DECL_55c444ca86bbbd773e43ddb6bd470efb371c45a4_H
typedef enum zend_enum_ZendTestUnitEnum {
ZEND_ENUM_ZendTestUnitEnum_Foo = 1,
@@ -27,4 +27,4 @@ typedef enum zend_enum_ZendTestEnumWithInterface {
ZEND_ENUM_ZendTestEnumWithInterface_Bar = 2,
} zend_enum_ZendTestEnumWithInterface;
-#endif /* ZEND_TEST_DECL_55bb2e6d209ea4030e3edfd604fc5ce4d14267f0_H */
+#endif /* ZEND_TEST_DECL_55c444ca86bbbd773e43ddb6bd470efb371c45a4_H */
diff --git a/ext/zend_test/test_legacy_arginfo.h b/ext/zend_test/test_legacy_arginfo.h
index 9bb20c85e95a..d6e1f758e209 100644
--- a/ext/zend_test/test_legacy_arginfo.h
+++ b/ext/zend_test/test_legacy_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 55bb2e6d209ea4030e3edfd604fc5ce4d14267f0
+ * Stub hash: 55c444ca86bbbd773e43ddb6bd470efb371c45a4
* Has decl header: yes */
#include "zend_constants.h"