Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strncpy filename_size #273

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down