mirror of
https://github.com/php/php-src.git
synced 2024-12-11 10:54:47 +08:00
Fixed bug #70350: ZipArchive::extractTo allows for directory traversal when creating directories
This commit is contained in:
parent
ce2c67c8e8
commit
f9c2bf73ad
@ -174,7 +174,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
|
||||
|
||||
/* it is a directory only, see #40228 */
|
||||
if (path_cleaned_len > 1 && IS_SLASH(path_cleaned[path_cleaned_len - 1])) {
|
||||
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
|
||||
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, path_cleaned);
|
||||
is_dir_only = 1;
|
||||
} else {
|
||||
memcpy(file_dirname, path_cleaned, path_cleaned_len);
|
||||
|
33
ext/zip/tests/bug70350.phpt
Normal file
33
ext/zip/tests/bug70350.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
Bug #70350 (ZipArchive::extractTo allows for directory traversal when creating directories)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if(!extension_loaded('zip')) die('skip');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$dir = dirname(__FILE__)."/bug70350";
|
||||
mkdir($dir);
|
||||
$archive = new ZipArchive();
|
||||
$archive->open("$dir/a.zip",ZipArchive::CREATE);
|
||||
$archive->addEmptyDir("../down2/");
|
||||
$archive->close();
|
||||
|
||||
$archive2 = new ZipArchive();
|
||||
$archive2->open('a.zip');
|
||||
$archive2->extractTo($dir);
|
||||
$archive2->close();
|
||||
var_dump(file_exists("$dir/down2/"));
|
||||
var_dump(file_exists("../down2/"));
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
$dir = dirname(__FILE__)."/bug70350";
|
||||
rmdir("$dir/down2");
|
||||
unlink("$dir/a.zip");
|
||||
rmdir($dir);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(false)
|
Loading…
Reference in New Issue
Block a user