Merge branch 'PHP-8.0'

* PHP-8.0:
  Fix #80863: ZipArchive::extractTo() ignores references
This commit is contained in:
Christoph M. Becker 2021-05-07 19:22:51 +02:00
commit cc86f70de9
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 45 additions and 2 deletions

View file

@ -2728,7 +2728,6 @@ PHP_METHOD(ZipArchive, extractTo)
zend_string *files_str = NULL; zend_string *files_str = NULL;
HashTable *files_ht = NULL; HashTable *files_ht = NULL;
zval *zval_file = NULL;
php_stream_statbuf ssb; php_stream_statbuf ssb;
char *pathto; char *pathto;
size_t pathto_len; size_t pathto_len;
@ -2765,7 +2764,8 @@ PHP_METHOD(ZipArchive, extractTo)
RETURN_FALSE; RETURN_FALSE;
} }
for (i = 0; i < nelems; i++) { for (i = 0; i < nelems; i++) {
if ((zval_file = zend_hash_index_find(files_ht, i)) != NULL) { zval *zval_file;
if ((zval_file = zend_hash_index_find_deref(Z_ARRVAL_P(zval_files), i)) != NULL) {
switch (Z_TYPE_P(zval_file)) { switch (Z_TYPE_P(zval_file)) {
case IS_LONG: case IS_LONG:
break; break;

View file

@ -0,0 +1,43 @@
--TEST--
Bug #80863 (ZipArchive::extractTo() ignores references)
--SKIPIF--
<?php
if (!extension_loaded('zip')) die("skip zip extension not available");
?>
--FILE--
<?php
$archive = __DIR__ . "/bug80863.zip";
$zip = new ZipArchive();
$zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFromString("file1.txt", "contents");
$zip->addFromString("file2.txt", "contents");
$zip->close();
$target = __DIR__ . "/bug80683";
mkdir($target);
$files = [
"file1.txt",
"file2.txt",
];
// turn into references
foreach ($files as &$file);
$zip = new ZipArchive();
$zip->open($archive);
$zip->extractTo($target, $files);
var_dump(is_file("$target/file1.txt"));
var_dump(is_file("$target/file2.txt"));
?>
--EXPECT--
bool(true)
bool(true)
--CLEAN--
<?php
@unlink(__DIR__ . "/bug80863.zip");
$target = __DIR__ . "/bug80683";
@unlink("$target/file1.txt");
@unlink("$target/file2.txt");
@rmdir($target);
?>