From 7b68f0aa98262fc7fc580633b01dbd2bd31a3af8 Mon Sep 17 00:00:00 2001 From: Jonathan Conder Date: Fri, 10 Mar 2023 10:06:17 +1300 Subject: [PATCH] Create parent directory before extracting symlink At least when using Info-ZIP 3.0, symlinks to both files and directories lack a trailing slash, so the second mz_path_remove_filename is unnecessary (and could break things if the parent directory doesn't precede the symlink in the file). If other implementations do add a trailing slash, the if statement should handle that. --- mz_zip_rw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mz_zip_rw.c b/mz_zip_rw.c index 39f98770..d1a74319 100644 --- a/mz_zip_rw.c +++ b/mz_zip_rw.c @@ -721,7 +721,9 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path) { /* If symbolic link then properly construct destination path and link path */ if (mz_zip_entry_is_symlink(reader->zip_handle) == MZ_OK) { mz_path_remove_slash(pathwfs); - mz_path_remove_filename(directory); + if (mz_zip_entry_is_dir(reader->zip_handle) == MZ_OK) { + mz_path_remove_filename(directory); + } } /* Create the output directory if it doesn't already exist */