← Back to Pull requests

Fix minizip packaging, large-file detection, and EOCD lookup #1375

Open
bmehta001 opened this pull request with 455 lines diff across 11 files
View on GitHub
bmehta001 bmehta001 commented on Nov 06, 2026 13:27 UTC
Author

This fixes six related minizip build, packaging, and archive-reading issues:

  • Export both include and include/minizip for installed shared/static targets, so consumers can include the installed zip.h and unzip.h without source-tree header paths.

  • Put minizip in pkg-config Libs and zlib plus optional BZip2 in Libs.private, preserving static link order; expose the installed header directory in Cflags.

  • Use minizip's own version variables for the standalone library version and SONAME (libminizip.so.1).

  • Probe fopen64 under _LARGEFILE64_SOURCE=1, matching library compilation rather than selecting USE_FILE32API on glibc. Preserve and restore the caller's CMake check state.

  • Treat the installed package's BZip2 setting as a normal variable, not a consumer cache option. Switching installations must discover the selected package's actual dependencies, including when a stale cache contains the opposite setting.

  • Validate classic EOCD candidates before accepting signature bytes in a reverse scan: require the complete 22-byte header and a declared comment length ending at EOF. Continue scanning past invalid candidates, retaining the rule that a ZIP64 locator must immediately precede the real classic EOCD.
  • Regression coverage extends the existing installed-consumer test and adds shared/static archive tests for classic/ZIP64 read and append, self-extracting prefixes, truncated false EOCD signatures, mismatched comment lengths, scan-window boundaries, maximum-length comments, and file callback seeks beyond 4 GiB. The archive and stale-dependency regressions failed on both Windows and Linux before the production fixes.

    Validation:

  • Standalone CMake/CTest: 11/11 Windows x64 (Visual Studio 2026), 11/11 Linux GCC with BZip2 OFF, and 11/11 Linux GCC with BZip2 ON.

  • Integrated zlib + minizip CMake/CTest: 24/24 Windows, 28/28 Linux with BZip2 ON.

  • Reconfigured and built the same installed consumer OFF -> ON -> OFF without clearing its cache; the OFF installation also configures with BZip2 discovery disabled.

  • Linux now detects fopen64, and neither shared nor static builds select USE_FILE32API.

  • No tests were skipped or filtered in these passing suites. Existing negative-component tests still fail for the intended missing-component reason.

  • Spelling checks and git diff --check pass. A 32-bit Linux runtime was not exercised because the local multilib CRT is unavailable.
  • Earlier validation also verified libminizip.so.1 and actual pkg-config --static consumers in both BZip2 configurations.

    Diff: 455 lines (+432 / -23) across 11 files Reviewer: Vollstrecker Review duration: 13338m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.54) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.54 · 455 lines diff across 11 files
    0.54
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.366
    Real PR Conversation Timeline
    17 items
    Vollstrecker Vollstrecker commented on Nov 06, 2026 14:12 UTC
    Contributor

    Where's the meaning in creating installed_headers.c? The test compiles zip.c which already includes zip.h, if the include-path doesn't match that one fails no matter of unzip.h would be found.

    And you do this in find_package_test which operates only on the installed tree, there are no references to the sourcetree (if you find some, that needs to be corrected).

    For the interface $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/minizip>) should be enough as this is the only place headers are installed. But I guess the moving of the headers was intended to end up in stuff like #include "minizip/zip.h" which would mean the BUILD_INTERFACE and the source itself would need adjustments. @madler: What was the intention?

    For the version: Correct.

    For pkgconfig: Nothing I know enough about to judge.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 14:45 UTC
    Code Review
    contrib/minizip/test/CMakeLists.txt:1
    @@ -1,3 +1,28 @@
    +foreach(variant IN ITEMS shared static)
    +    if(variant STREQUAL "shared" AND MINIZIP_BUILD_SHARED)
    +        set(library MINIZIP::minizip)
    +    elseif(variant STREQUAL "static" AND MINIZIP_BUILD_STATIC)
    +        set(library MINIZIP::minizipstatic)
    +    else()
    +        continue()
    +    endif()
    +
    +    set(target minizip_archive_${variant})
    +    add_executable(${target} archive-test.c)
    +    target_link_libraries(${target} PRIVATE ${library})
    +    target_compile_definitions(${target}
    +        PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
    +    if(WIN32 AND variant STREQUAL "shared")
    +        add_custom_command(TARGET ${target} POST_BUILD
    +            COMMAND ${CMAKE_COMMAND} -E copy_if_different
    +                $<TARGET_FILE:MINIZIP::minizip> $<TARGET_FILE_DIR:${target}>

    Why do you start copying files around instead of using a function to modify the environment of the test like demonstrated in /test/CMakeLists.txt Lines 1-14 which would be reuseable if more tests are added?

    bmehta001 bmehta001 commented on Nov 06, 2026 14:47 UTC
    Author

    Fixed the new archive test's Cygwin runtime setup in 1230746093dbe71e3f981d0b83d7fe2671bb2cf3: Cygwin also needs the shared minizip/zlib DLLs beside the test executable, despite WIN32 being false. No test was disabled or weakened.

    The new Cygwin job now passes 26/26 tests, including both archive regressions: https://github.com/madler/zlib/actions/runs/42235455471/job/127951741676

    The focused shared/static archive tests also remain passing on Windows VS 2026 and Linux after this platform-condition correction.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 14:50 UTC
    Code Review
    contrib/minizip/test/find_package_test.cmake.in:1
    @@ -8,6 +8,14 @@ project(
     option(MINIZIP_BUILD_SHARED "" @MINIZIP_BUILD_SHARED@)
     option(MINIZIP_BUILD_STATIC "" @MINIZIP_BUILD_STATIC@)
     
    +# Simulate a consumer cache left by a package with the opposite feature setting.
    +if(@MINIZIP_ENABLE_BZIP2@)
    +    set(minizip_HAS_BZIP2 OFF CACHE BOOL "" FORCE)
    +else()
    +    set(minizip_HAS_BZIP2 ON CACHE BOOL "" FORCE)
    +    set(CMAKE_DISABLE_FIND_PACKAGE_BZip2 TRUE)
    +endif()
    +

    It's not some optional feature, if minizip is compiled with bzip2 bzip2 is required, otherwise presence of bzip2 is irrelevant. Simulating a user do weird stuff gives no benefit.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 14:55 UTC
    Code Review
    contrib/minizip/CMakeLists.txt:1
    @@ -39,6 +39,7 @@ include(CheckSymbolExists)
     include(CheckIncludeFile)
     include(CMakePackageConfigHelpers)
     include(CheckTypeSize)
    +include(CMakePushCheckState)

    As the docs say, this module can be used in find-modules to preserve the env they where called in. Needed because these modules get included. This file here is either toplevel or used via add_subdirectory, so this changes nothing in behaviour and just adds lines.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 14:58 UTC
    Code Review
    contrib/minizip/minizipConfig.cmake.in:1
    @@ -1,11 +1,7 @@
     set(_MINIZIP_supported_components "shared" "static")
     include(CMakeFindDependencyMacro)
     
    -set(minizip_HAS_BZIP2

    It's intended to be in the cache. If minizip is searched in a subdir, the normal var wouldn't propagate to the parentdir so users can't check there if minizip supports bzip2. As bzip2 could be found in by previous searched dep, checking for that doesn't tell the user anything about the abilities of minizip.

    Vollstrecker Vollstrecker commented on Nov 06, 2026 15:00 UTC
    Reviewer

    I guess now you start to mix things.

    bmehta001 bmehta001 commented on Nov 06, 2026 18:26 UTC
    Author

    Follow-up 057660cc generates configuration-specific pkg-config metadata from actual library filenames, fixing static-only Windows/MinGW names and Debug postfixes. Added an installed pkg-config link consumer and explicit static-only mingw64 CI coverage. Locally validated shared/static and static-only Linux builds with BZip2 OFF/ON, Windows VS 2026 package suites, and a native Windows static consumer compiled/linked/run using actual pkg-config --msvc-syntax output. The new MinGW job will provide validation on that exact toolchain.

    bmehta001 bmehta001 commented on Nov 06, 2026 18:32 UTC
    Author

    Exact-toolchain validation is now green on 057660cc: MSys mingw64 passed all 30 standard tests and all 4 selected static-only tests (including both pkg-config configure/build tests). The job log confirms the static build produces libminizips.a and libzs.a and the installed metadata consumer links successfully. Cygwin also passed. Job: https://github.com/madler/zlib/actions/runs/42270706157/job/128074202848

    bmehta001 bmehta001 commented on Nov 06, 2026 18:41 UTC
    Author

    The new pkg-config consumer exposed a failure on OpenBSD, where BZip2 was found under /usr/local/lib. Follow-up 5107ca28 adds imported dependency search directories and resolves BZip2 filenames per configuration; the consumer no longer adds zlib library directories outside the metadata. Windows native MSVC and all four Linux mixed/static-only BZip2 OFF/ON variants pass. OpenBSD now uses --output-on-failure so any remaining failure is visible. Awaiting the new exact-platform CI results.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 18:42 UTC
    Code Review
    contrib/minizip/CMakeLists.txt:1
    @@ -309,6 +310,69 @@ if(MINIZIP_BUILD_STATIC)
             PRIVATE MINIZIP::minizipstatic)
     endif(MINIZIP_BUILD_STATIC)
     
    +if(MINIZIP_BUILD_SHARED OR MINIZIP_BUILD_STATIC)

    Superflous as it's a complicated way to say if(BUILD_NOTHING)

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 18:49 UTC
    Code Review
    contrib/minizip/CMakeLists.txt:1
    @@ -309,6 +310,69 @@ if(MINIZIP_BUILD_STATIC)
             PRIVATE MINIZIP::minizipstatic)
     endif(MINIZIP_BUILD_STATIC)
     
    +if(MINIZIP_BUILD_SHARED OR MINIZIP_BUILD_STATIC)
    +    if(MINIZIP_BUILD_SHARED)
    +        set(MINIZIP_PC_TARGET MINIZIP::minizip)
    +        set(MINIZIP_PC_ZLIB_TARGET ZLIB::ZLIB)
    +        set(MINIZIP_PC_ZLIB_COMPONENT shared)
    +    else()
    +        set(MINIZIP_PC_TARGET MINIZIP::minizipstatic)
    +        set(MINIZIP_PC_ZLIB_TARGET ZLIB::ZLIBSTATIC)
    +        set(MINIZIP_PC_ZLIB_COMPONENT static)
    +    endif()
    +    set(MINIZIP_PC_LIBRARY "$<TARGET_LINKER_FILE_BASE_NAME:${MINIZIP_PC_TARGET}>")
    +    set(MINIZIP_PC_ZLIB_LIBRARY
    +        "$<TARGET_LINKER_FILE_BASE_NAME:${MINIZIP_PC_ZLIB_TARGET}>")
    +    get_target_property(_minizip_zlib_imported ${MINIZIP_PC_ZLIB_TARGET} IMPORTED)
    +    if(_minizip_zlib_imported)

    If built completely from that source the target is not imported. What happens then?

    bmehta001 bmehta001 commented on Nov 06, 2026 18:52 UTC
    Author

    Follow-up c16e80b9 also exports non-system zlib include directories: minizip public headers include zlib.h. Removed find_package(ZLIB) and all manual dependency path injection from the pkg-config consumer. Reproduced native MSVC C1083 before the fix; afterward the consumer compiles, links and runs using only actual pkg-config compiler/linker flags. All five Linux consumer configurations pass. This strengthens the regression instead of masking the missing headers.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 18:53 UTC
    Code Review
    contrib/minizip/CMakeLists.txt:1
    @@ -309,6 +310,69 @@ if(MINIZIP_BUILD_STATIC)
             PRIVATE MINIZIP::minizipstatic)
     endif(MINIZIP_BUILD_STATIC)
     
    +if(MINIZIP_BUILD_SHARED OR MINIZIP_BUILD_STATIC)
    +    if(MINIZIP_BUILD_SHARED)
    +        set(MINIZIP_PC_TARGET MINIZIP::minizip)
    +        set(MINIZIP_PC_ZLIB_TARGET ZLIB::ZLIB)
    +        set(MINIZIP_PC_ZLIB_COMPONENT shared)
    +    else()
    +        set(MINIZIP_PC_TARGET MINIZIP::minizipstatic)
    +        set(MINIZIP_PC_ZLIB_TARGET ZLIB::ZLIBSTATIC)
    +        set(MINIZIP_PC_ZLIB_COMPONENT static)
    +    endif()
    +    set(MINIZIP_PC_LIBRARY "$<TARGET_LINKER_FILE_BASE_NAME:${MINIZIP_PC_TARGET}>")
    +    set(MINIZIP_PC_ZLIB_LIBRARY
    +        "$<TARGET_LINKER_FILE_BASE_NAME:${MINIZIP_PC_ZLIB_TARGET}>")
    +    get_target_property(_minizip_zlib_imported ${MINIZIP_PC_ZLIB_TARGET} IMPORTED)
    +    if(_minizip_zlib_imported)
    +        # Imported targets do not expose their filename through the base-name expression.
    +        set(MINIZIP_PC_ZLIB_LIBRARY "")
    +        set(_minizip_configs NOCONFIG ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
    +        list(REMOVE_DUPLICATES _minizip_configs)
    +        get_target_property(_minizip_imported_configs
    +                            ${MINIZIP_PC_ZLIB_TARGET} IMPORTED_CONFIGURATIONS)
    +        foreach(_minizip_config IN LISTS _minizip_configs)
    +            string(TOUPPER "${_minizip_config}" _minizip_upper)
    +            get_target_property(_minizip_file ${MINIZIP_PC_ZLIB_TARGET}
    +                                LOCATION_${_minizip_upper})
    +            get_target_property(_minizip_mapped ${MINIZIP_PC_ZLIB_TARGET}
    +                                MAP_IMPORTED_CONFIG_${_minizip_upper})
    +            if(NOT _minizip_mapped)
    +                set(_minizip_mapped "")
    +            endif()
    +            foreach(_minizip_import IN ITEMS ${_minizip_mapped}
    +                    ${_minizip_upper} NOCONFIG ${_minizip_imported_configs})
    +                string(TOUPPER "${_minizip_import}" _minizip_import)
    +                get_target_property(_minizip_implib ${MINIZIP_PC_ZLIB_TARGET}
    +                                    IMPORTED_IMPLIB_${_minizip_import})
    +                if(_minizip_implib)
    +                    set(_minizip_file "${_minizip_implib}")
    +                    break()
    +                endif()
    +            endforeach()
    +            get_filename_component(_minizip_name "${_minizip_file}" NAME_WE)
    +            if(CMAKE_STATIC_LIBRARY_PREFIX)
    +                string(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" ""
    +                       _minizip_name "${_minizip_name}")
    +            endif()
    +            if(_minizip_config STREQUAL "NOCONFIG")
    +                set(_minizip_config "")
    +            endif()
    +            string(APPEND MINIZIP_PC_ZLIB_LIBRARY
    +                "$<$<CONFIG:${_minizip_config}>:${_minizip_name}>")
    +        endforeach()
    +    endif()
    +    set(MINIZIP_PC_LIBS_PRIVATE "-l${MINIZIP_PC_ZLIB_LIBRARY}")
    +    if(MINIZIP_ENABLE_BZIP2)
    +        string(APPEND MINIZIP_PC_LIBS_PRIVATE " -lbz2")
    +    endif(MINIZIP_ENABLE_BZIP2)
    +    set(LIBMINIZIP_PC ${minizip_BINARY_DIR}/$<CONFIG>/minizip.pc)
    +    configure_file(${minizip_SOURCE_DIR}/minizip.pc.txt
    +                   ${minizip_BINARY_DIR}/minizip.pc.in @ONLY)
    +    file(GENERATE OUTPUT ${LIBMINIZIP_PC}
    +                  INPUT ${minizip_BINARY_DIR}/minizip.pc.in)
    +endif()

    This whole block basically tries to find the name of installed zlib. It's a complex block to adjust for systems that insist on using different names. This whole system is designed to have consistent naming everwhere, if anyone wants to rename them it's basically their problem to take to adjust the naming everywhere.

    Vollstrecker Vollstrecker commented on code on Nov 06, 2026 18:55 UTC
    Code Review
    contrib/minizip/CMakeLists.txt:1
    @@ -161,7 +160,8 @@ if(MINIZIP_BUILD_SHARED)
         target_include_directories(${ZLIB_CONTRIB_PREFIX}libminizip
             PUBLIC
                 $<BUILD_INTERFACE:${minizip_SOURCE_DIR}>
    -            $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
    +            $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>

    Depending on what @madler intended with this change only one of those 2 lines it needed.

    Should it be #include "zip.h" or #include "minizip/zip.h"?

    Vollstrecker Vollstrecker commented on Nov 06, 2026 18:58 UTC
    Reviewer

    It seems that you just commit what the copilot in vcpkg tells you to adjust this project to their (strange) way of doing thing without even reading comments.

    Reviewers
    Assignees
    bmehta001 bmehta001
    Labels
    risk: low confidence: 89.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 54.3% (MEDIUM) · Higher = larger blast radius
    54.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.5% · Lower = rushed or shallow review
    89.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.7% · Safe to merge
    5.7%
    Repository