Skip to content

Commit

Permalink
Replace MAX_PATH by MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- committed Oct 25, 2022
1 parent 9682501 commit fefb8d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ static const char *zip_basename(const char *name) {

static int zip_mkpath(char *path) {
char *p;
char npath[MAX_PATH + 1];
char npath[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE + 1];
int len = 0;
int has_device = HAS_DEVICE(path);

memset(npath, 0, MAX_PATH + 1);
memset(npath, 0, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE + 1);
if (has_device) {
// only on windows
npath[0] = path[0];
npath[1] = path[1];
len = 2;
}
for (p = path + len; *p && len < MAX_PATH; p++) {
for (p = path + len; *p && len < MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE; p++) {
if (ISSLASH(*p) && ((!has_device && len > 0) || (has_device && len > 2))) {
#if defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) || \
defined(__MINGW32__)
Expand Down Expand Up @@ -303,8 +303,8 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir,
void *arg) {
int err = 0;
mz_uint i, n;
char path[MAX_PATH + 1];
char symlink_to[MAX_PATH + 1];
char path[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE + 1];
char symlink_to[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE + 1];
mz_zip_archive_file_stat info;
size_t dirlen = 0, filename_size = MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE;
mz_uint32 xattr = 0;
Expand All @@ -313,14 +313,14 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir,
memset(symlink_to, 0, sizeof(symlink_to));

dirlen = strlen(dir);
if (dirlen + 1 > MAX_PATH) {
if (dirlen + 1 > MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE) {
return ZIP_EINVENTNAME;
}

memset((void *)&info, 0, sizeof(mz_zip_archive_file_stat));

#if defined(_MSC_VER)
strcpy_s(path, MAX_PATH, dir);
strcpy_s(path, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE, dir);
#else
strcpy(path, dir);
#endif
Expand All @@ -334,8 +334,8 @@ 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;
if (filename_size > MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - dirlen) {
filename_size = MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - dirlen;
}
// Get and print information about each file in the archive.
n = mz_zip_reader_get_num_files(zip_archive);
Expand Down Expand Up @@ -375,9 +375,9 @@ static int zip_archive_extract(mz_zip_archive *zip_archive, const char *dir,
#if defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) || \
defined(__MINGW32__)
#else
if (info.m_uncomp_size > MAX_PATH ||
if (info.m_uncomp_size > MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE ||
!mz_zip_reader_extract_to_mem_no_alloc(zip_archive, i, symlink_to,
MAX_PATH, 0, NULL, 0)) {
MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE, 0, NULL, 0)) {
err = ZIP_EMEMNOALLOC;
goto out;
}
Expand Down
4 changes: 0 additions & 4 deletions src/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ typedef long ssize_t; /* byte count or error */
#endif
#endif

#ifndef MAX_PATH
#define MAX_PATH 1024 /* # chars in a path name including NULL */
#endif

/**
* @mainpage
*
Expand Down

0 comments on commit fefb8d6

Please sign in to comment.