Skip to content

Commit df2ceac

Browse files
cmb69smalyshev
authored andcommitted
Fix #81420: ZipArchive::extractTo extracts outside of destination
We need to properly detect and handle absolute paths in a portable way.
1 parent 521bd7c commit df2ceac

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
106106
return NULL;
107107
}
108108

109-
if (IS_SLASH(path[0])) {
110-
return path + 1;
109+
if (IS_ABSOLUTE_PATH(path, path_len)) {
110+
return path + COPY_WHEN_ABSOLUTE(path) + 1;
111111
}
112112

113113
i = path_len;

ext/zip/tests/bug81420.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #81420 (ZipArchive::extractTo extracts outside of destination)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("zip")) die("skip zip extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$zip = new ZipArchive();
10+
$zip->open(__DIR__ . "/bug81420.zip");
11+
$destination = __DIR__ . "/bug81420";
12+
mkdir($destination);
13+
$zip->extractTo($destination);
14+
var_dump(file_exists("$destination/nt1/zzr_noharm.php"));
15+
?>
16+
--CLEAN--
17+
<?php
18+
$destination = __DIR__ . "/bug81420";
19+
@unlink("$destination/nt1/zzr_noharm.php");
20+
@rmdir("$destination/nt1");
21+
@rmdir($destination);
22+
?>
23+
--EXPECT--
24+
bool(true)

ext/zip/tests/bug81420.zip

218 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)