From d294768cadb4614f01a12e86d75fdc55a038daea Mon Sep 17 00:00:00 2001 From: 7c00 Date: Sat, 29 Jun 2024 05:25:21 +0000 Subject: [PATCH] Fix permissions to work with unzip --- src/miniz.h | 1 + test/CMakeLists.txt | 13 +++++++++++++ test/test_permissions.c | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/miniz.h b/src/miniz.h index cd864831..cdacedea 100644 --- a/src/miniz.h +++ b/src/miniz.h @@ -8367,6 +8367,7 @@ static mz_bool mz_zip_writer_create_central_dir_header( (void)pZip; memset(pDst, 0, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_SIG_OFS, MZ_ZIP_CENTRAL_DIR_HEADER_SIG); + MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, 0x031E); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_NEEDED_OFS, method ? 20 : 0); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_BIT_FLAG_OFS, bit_flags); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_METHOD_OFS, method); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fc8bb1df..1ed3089c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,6 +41,19 @@ add_sanitizers(${test_entry_out}) set(test_permissions_out test_permissions.out) add_executable(${test_permissions_out} test_permissions.c) target_link_libraries(${test_permissions_out} zip) +if(LINUX OR UNIX) + find_program(UNZIP_PROGRAM unzip) + if(UNZIP_PROGRAM) + message(STATUS "Found unzip: ${UNZIP_PROGRAM}") + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR + "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") + target_compile_definitions(${test_permissions_out} + PRIVATE UNZIP_PROGRAM="${UNZIP_PROGRAM}" + ) + endif() + endif() +endif() add_test(NAME ${test_permissions_out} COMMAND ${test_permissions_out}) add_sanitizers(${test_permissions_out}) diff --git a/test/test_permissions.c b/test/test_permissions.c index 487ff089..0f2a9af8 100644 --- a/test/test_permissions.c +++ b/test/test_permissions.c @@ -66,6 +66,17 @@ MU_TEST(test_exe_permissions) { mu_assert_int_eq(0, MZ_FILE_STAT(XFILE, &file_stats)); mu_assert_int_eq(XMODE, file_stats.st_mode); + +#ifdef UNZIP_PROGRAM + remove(XFILE); + + char command[128]; + sprintf(command, "%s %s", UNZIP_PROGRAM, ZIPNAME); + mu_assert_int_eq(0, system(command)); + + mu_assert_int_eq(0, MZ_FILE_STAT(XFILE, &file_stats)); + mu_assert_int_eq(XMODE, file_stats.st_mode); +#endif } MU_TEST(test_read_permissions) {