From 114d9d46fdbdad55b37705190a8625f4ab5fa81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Podg=C3=B3rski?= Date: Fri, 5 Aug 2022 12:31:20 +0200 Subject: [PATCH] strncpy filename_size (#273) --- src/zip.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/zip.c b/src/zip.c index 13ed5bc..f3da8f5 100644 --- a/src/zip.c +++ b/src/zip.c @@ -306,7 +306,7 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir, char path[MAX_PATH + 1]; char symlink_to[MAX_PATH + 1]; mz_zip_archive_file_stat info; - size_t dirlen = 0; + size_t dirlen = 0, filename_size = MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE; mz_uint32 xattr = 0; memset(path, 0, sizeof(path)); @@ -334,6 +334,9 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir, ++dirlen; } + if (filename_size > MAX_PATH - dirlen) { + filename_size = MAX_PATH - dirlen; + } // Get and print information about each file in the archive. n = mz_zip_reader_get_num_files(zip_archive); for (i = 0; i < n; ++i) { @@ -349,11 +352,12 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir, err = ZIP_EINVENTNAME; goto out; } + #if defined(_MSC_VER) - strncpy_s(&path[dirlen], MAX_PATH - dirlen, info.m_filename, - MAX_PATH - dirlen); + strncpy_s(&path[dirlen], filename_size, info.m_filename, + filename_size); #else - strncpy(&path[dirlen], info.m_filename, MAX_PATH - dirlen); + strncpy(&path[dirlen], info.m_filename, filename_size); #endif err = zip_mkpath(path); if (err < 0) {