strncpy filename_size
Fixes https://github.com/kuba--/zip/issues/272
This won't solve the problem since the maximum path length is 260 symbols. MAX_PATH restrictions apply until Windows 10 version 1607
as a solution I can suggest this code:
/* Note: MAX_PATH restrictions apply until Windows 10 version 1607 */ #if defined(_WIN32) # define MAX_FILE_PATH 256 #else # define MAX_FILE_PATH 512 #endif enum { /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */ MZ_ZIP_MAX_IO_BUF_SIZE = 8 * 1024, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = MAX_FILE_PATH, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512 };
But this is totally not related to the issue which you came across.
MAX_PATH on windows < 10 is a one thing, but you got an error related to strncpy which potentially can copy more than array size.
...Moreover lets take a look step by step:
we need a minimum of filename_size (which by default is MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE (512)) and MAX_PATH - dirlen.
if (filename_size > MAX_PATH - dirlen) {
filename_size = MAX_PATH - dirlen;
}
MAX_PATH is defined in zip.h as follows:
#ifndef MAX_PATH
#define MAX_PATH 1024 /* # chars in a path name including NULL */
#endif
So if you are on windows where MAX_PATH is defined as 256, then it should work, because dirlen cannot be > MAX_PATH (because function returns ZIP_EINVENTNAME if (dirlen + 1 > MAX_PATH) )
MAX_PATHis defined inzip.has follows:#ifndef MAX_PATH #define MAX_PATH 1024 /* # chars in a path name including NULL */ #endif
MAX_PATH is declared inside minwindef.h. I think that's what causes the problem.
MAX_PATHis defined inzip.has follows:#ifndef MAX_PATH #define MAX_PATH 1024 /* # chars in a path name including NULL */ #endifMAX_PATH is declared inside minwindef.h. I think that's what causes the problem.
What problem exactly?
In this case (https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/minwindef.h#L60), just include zip.h after windows' headers.
this did not solve the problem, I tried to build it as an independent library and the ide tells me that MAX_PATH is defined in minwindef.h.
it seems strange to me that when compiling without the -DCMAKE_BUILD_TYPE=Release, it does not give such an error.