mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +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;
|
||||
size_t file_basename_len;
|
||||
int is_dir_only = 0;
|
||||
|
||||
if (file_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
if (file_len > 1 && file[file_len - 1] == '/') {
|
||||
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
|
||||
is_dir_only = 1;
|
||||
} 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 */
|
||||
if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
|
||||
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 */
|
||||
if (file[file_len - 1] == '/') {
|
||||
efree(file_dirname_fullpath);
|
||||
efree(file_basename);
|
||||
if (!is_dir_only) {
|
||||
efree(file_basename);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue