Skip to content

Commit 57918b1

Browse files
committed
Fix #80863: ZipArchive::extractTo() ignores references
We need to cater to references, when traversing the files to extract. While we're at it, we move the `zval_file` declaration into a narrower scope. Closes GH-6959.
1 parent 8deadfa commit 57918b1

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ PHP NEWS
4040
- XMLReader:
4141
. Fixed bug #73246 (XMLReader: encoding length not checked). (cmb)
4242

43+
- Zip:
44+
. Fixed bug #80863 (ZipArchive::extractTo() ignores references). (cmb)
45+
4346
06 May 2021, PHP 7.4.19
4447

4548
- PDO_pgsql:

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,6 @@ static ZIPARCHIVE_METHOD(extractTo)
26162616

26172617
zval *self = ZEND_THIS;
26182618
zval *zval_files = NULL;
2619-
zval *zval_file = NULL;
26202619
php_stream_statbuf ssb;
26212620
char *pathto;
26222621
size_t pathto_len;
@@ -2653,7 +2652,8 @@ static ZIPARCHIVE_METHOD(extractTo)
26532652
RETURN_FALSE;
26542653
}
26552654
for (i = 0; i < nelems; i++) {
2656-
if ((zval_file = zend_hash_index_find(Z_ARRVAL_P(zval_files), i)) != NULL) {
2655+
zval *zval_file;
2656+
if ((zval_file = zend_hash_index_find_deref(Z_ARRVAL_P(zval_files), i)) != NULL) {
26572657
switch (Z_TYPE_P(zval_file)) {
26582658
case IS_LONG:
26592659
break;

ext/zip/tests/bug80863.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #80863 (ZipArchive::extractTo() ignores references)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zip')) die("skip zip extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$archive = __DIR__ . "/bug80863.zip";
10+
11+
$zip = new ZipArchive();
12+
$zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
13+
$zip->addFromString("file1.txt", "contents");
14+
$zip->addFromString("file2.txt", "contents");
15+
$zip->close();
16+
17+
$target = __DIR__ . "/bug80683";
18+
mkdir($target);
19+
20+
$files = [
21+
"file1.txt",
22+
"file2.txt",
23+
];
24+
// turn into references
25+
foreach ($files as &$file);
26+
27+
$zip = new ZipArchive();
28+
$zip->open($archive);
29+
$zip->extractTo($target, $files);
30+
var_dump(is_file("$target/file1.txt"));
31+
var_dump(is_file("$target/file2.txt"));
32+
?>
33+
--EXPECT--
34+
bool(true)
35+
bool(true)
36+
--CLEAN--
37+
<?php
38+
@unlink(__DIR__ . "/bug80863.zip");
39+
$target = __DIR__ . "/bug80683";
40+
@unlink("$target/file1.txt");
41+
@unlink("$target/file2.txt");
42+
@rmdir($target);
43+
?>

0 commit comments

Comments
 (0)