Skip to content

Commit

Permalink
Fix #81420: ZipArchive::extractTo extracts outside of destination
Browse files Browse the repository at this point in the history
We need to properly detect and handle absolute paths in a portable way.
  • Loading branch information
cmb69 authored and smalyshev committed Sep 21, 2021
1 parent 521bd7c commit df2ceac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
return NULL;
}

if (IS_SLASH(path[0])) {
return path + 1;
if (IS_ABSOLUTE_PATH(path, path_len)) {
return path + COPY_WHEN_ABSOLUTE(path) + 1;
}

i = path_len;
Expand Down
24 changes: 24 additions & 0 deletions ext/zip/tests/bug81420.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Bug #81420 (ZipArchive::extractTo extracts outside of destination)
--SKIPIF--
<?php
if (!extension_loaded("zip")) die("skip zip extension not available");
?>
--FILE--
<?php
$zip = new ZipArchive();
$zip->open(__DIR__ . "/bug81420.zip");
$destination = __DIR__ . "/bug81420";
mkdir($destination);
$zip->extractTo($destination);
var_dump(file_exists("$destination/nt1/zzr_noharm.php"));
?>
--CLEAN--
<?php
$destination = __DIR__ . "/bug81420";
@unlink("$destination/nt1/zzr_noharm.php");
@rmdir("$destination/nt1");
@rmdir($destination);
?>
--EXPECT--
bool(true)
Binary file added ext/zip/tests/bug81420.zip
Binary file not shown.

0 comments on commit df2ceac

Please sign in to comment.