mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
- MFB: #40228, ZipArchive::extractTo does create empty directories
recursively
This commit is contained in:
parent
db22b925bf
commit
1a78358460
3 changed files with 41 additions and 11 deletions
|
@ -101,23 +101,28 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
|
||||||
|
|
||||||
char *file_basename;
|
char *file_basename;
|
||||||
size_t file_basename_len;
|
size_t file_basename_len;
|
||||||
|
int is_dir_only = 0;
|
||||||
|
|
||||||
if (file_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb)) {
|
if (file_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(file_dirname, file, file_len);
|
if (file_len > 1 && file[file_len - 1] == '/') {
|
||||||
|
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
|
||||||
dir_len = php_dirname(file_dirname, file_len);
|
is_dir_only = 1;
|
||||||
|
|
||||||
if (dir_len > 0) {
|
|
||||||
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);
|
|
||||||
} else {
|
} else {
|
||||||
len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
|
memcpy(file_dirname, file, file_len);
|
||||||
|
|
||||||
|
dir_len = php_dirname(file_dirname, file_len);
|
||||||
|
|
||||||
|
if (dir_len > 0) {
|
||||||
|
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file_dirname);
|
||||||
|
} else {
|
||||||
|
len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
php_basename(file, file_len, NULL, 0, &file_basename, (unsigned int *)&file_basename_len TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
php_basename(file, file_len, NULL, 0, &file_basename, &file_basename_len TSRMLS_CC);
|
|
||||||
|
|
||||||
/* let see if the path already exists */
|
/* let see if the path already exists */
|
||||||
if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
|
if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
|
||||||
ret = php_stream_mkdir(file_dirname_fullpath, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
|
ret = php_stream_mkdir(file_dirname_fullpath, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
|
||||||
|
@ -131,7 +136,9 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
|
||||||
/* it is a standalone directory, job done */
|
/* it is a standalone directory, job done */
|
||||||
if (file[file_len - 1] == '/') {
|
if (file[file_len - 1] == '/') {
|
||||||
efree(file_dirname_fullpath);
|
efree(file_dirname_fullpath);
|
||||||
efree(file_basename);
|
if (!is_dir_only) {
|
||||||
|
efree(file_basename);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
ext/zip/tests/bug40228.phpt
Normal file
23
ext/zip/tests/bug40228.phpt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #40228 (extractTo does not create recursive empty path)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("zip")) print "skip"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$dest = dirname(__FILE__);
|
||||||
|
$arc_name = $dest . "/bug40228.zip";
|
||||||
|
$zip = new ZipArchive;
|
||||||
|
$zip->open($arc_name, ZIPARCHIVE::CREATE);;
|
||||||
|
$zip->extractTo($dest);
|
||||||
|
if (is_dir($dest . '/test/empty')) {
|
||||||
|
echo "Ok\n";
|
||||||
|
rmdir($dest . '/test/empty');
|
||||||
|
rmdir($dest . '/test');
|
||||||
|
} else {
|
||||||
|
echo "Failed.\n";
|
||||||
|
}
|
||||||
|
echo "Done\n";
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Ok
|
||||||
|
Done
|
BIN
ext/zip/tests/bug40228.zip
Normal file
BIN
ext/zip/tests/bug40228.zip
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue