100 Commits
Author SHA1 Message Date
Nathan Moin Vaziri 7b2387161c Version 4.2.2. 2026-06-30 09:44:28 -07:00
Nathan Moin Vaziri 131d59ba39 fix: reject symlink targets that escape extraction dir
Symlink archive entries had their stored target passed directly to
mz_os_make_symlink without checking containment, so a malicious
archive could create a link pointing outside the extraction root.

Add mz_path_is_symlink_target_safe to verify a link target resolves
within the destination directory, and apply it to both the UNIX1
extrafield and entry-content link targets. Reject symlink entries
outright when no destination base is set, since the target cannot be
validated without one.

Assisted-By: Claude Opus 4.8
2026-06-29 15:25:48 -07:00
Nathan Moin Vaziri 20fb0e3fdf test: always compile the codec-gated test sources
These test files were conditionally added to the test target by CMake,
so their in-source guards never ran in the excluded configurations.
Compile them unconditionally and let the ifdef guards select the tests.
test_compat.cc keeps its MZ_COMPAT gate in CMake since the compatibility
layer is only built then, but its compression requirement moves into the
source.

Assisted-By: Claude Opus 4.8
2026-06-24 10:48:53 -07:00
Nathan Moin Vaziri e6f15b4ae9 test: build stream compression tests only with compression
The stream tests compress then decompress, but the deflate path returns
MZ_SUPPORT_ERROR when built with MZ_ZIP_NO_COMPRESSION, so the round
trip cannot run. Guard the tests on that macro, and exclude only the
inflate-and-compare half when MZ_ZIP_NO_DECOMPRESSION is set.

Assisted-By: Claude Opus 4.8
2026-06-24 10:22:56 -07:00
Nathan Moin Vaziri 8c5f95cde7 test: don't run alternative data stream test on non-Windows platforms 2026-06-24 09:58:34 -07:00
Nathan Moin Vaziri 26b4619120 Version 4.2.1. 2026-04-27 12:23:18 -07:00
Nathan Moin Vaziri d195f3722e cmake: pick zstd and zlib-ng targets per BUILD_SHARED_LIBS
Both packages export separate static and shared imported targets, but
the find_package paths picked one variant unconditionally — zstd
preferred libzstd_static and zlib-ng always linked the shared zlib.
Building minizip-ng with BUILD_SHARED_LIBS=ON against a system zstd
that ships both variants therefore produced a libminizip.so with zstd
statically baked in (#983).
2026-04-27 12:22:37 -07:00
Nathan Moin Vaziri ea91a3c01b Version 4.2.0. 2026-04-26 18:54:36 -07:00
Nathan Moin Vaziri a6300c3b29 compat: add unzGetCurrentFileZStreamPos64 (#848)
Returns the absolute offset where the current entry's compressed
data begins, matching the original minizip API used by chromium and
other consumers. The position is already tracked internally via
entry_pos for STORE-method seek support, so this just exposes it.
2026-04-26 18:50:41 -07:00
Nathan Moin Vaziri 6b9defc73c mz_os: split file and link attribute getters (#797)
mz_os_get_file_attribs used lstat on POSIX and GetFileAttributesW
on Win32, both of which return the link's own attributes rather
than the target's. Callers that wanted to follow a symlink had no
way to ask for that, so mz_zip_writer_add_file produced followed
entries tagged ISLNK and readers that tried to recreate them as
symlinks.

Flip mz_os_get_file_attribs to stat on POSIX and to a CreateFile +
GetFileInformationByHandle path on Win32 when the entry is a
reparse point. Add mz_os_get_link_attribs preserving the original
lstat / GetFileAttributesW semantics. Update mz_zip_writer_add_file
to pick the right getter for each branch and to skip symlinks
cleanly when neither store_links nor follow_links is set.

Refs #797.
2026-04-26 18:40:25 -07:00
Nathan Moin Vaziri 3f23ed7a11 minizip: place erase temp on same filesystem when TMPDIR differs
minizip_erase rewrites the archive to a temp file under TMPDIR and
then renames it onto the source. rename(2) returns EXDEV across
filesystems, so when TMPDIR (e.g. /tmp) and the source live on
different mounts (a common conda-forge pattern), the rename fails
after the original was already moved aside to .bak — the next
operation that opens the archive sees no file and reports -111.

Add mz_os_path_same_fs() and have minizip_erase fall back on POSIX to
a same-dir temp when TMPDIR is on a different filesystem. POSIX uses
stat() st_dev comparison; Win32 uses _wstati64 for the parallel check
but the caller skips it under #ifndef _WIN32 because MoveFileExW with
MOVEFILE_COPY_ALLOWED already absorbs cross-volume rename internally.

Make the same-dir tmp filename unique (mz_ms_time suffix) and refuse
to clobber an existing leftover from a prior crash.

Refs #943.
2026-04-26 17:49:20 -07:00
Nathan Moin Vaziri ece5b06dcf test: skip AES-GCM test when build doesn't support it
The Apple crypto backend defaults MZ_TARGET_APPSTORE to 1, which
makes mz_crypt_aes_set_key return MZ_SUPPORT_ERROR for GCM mode
because the GCM CommonCrypto APIs are private and rejected by App
Store review. The test was hard-coded to expect MZ_OK and failed on
the default macOS build.

Skip the test when the runtime reports MZ_SUPPORT_ERROR; otherwise
proceed and verify correctness as before.
2026-04-25 01:24:48 -07:00
Nathan Moin Vaziri 483f0568b0 mz_os: skip symlink check at or above destination dir
mz_dir_has_unsafe_symlink walks every component of the destination
path and rejects any symlink with an absolute target. That's too
strict: when the user-chosen destination dir (or one of its ancestors)
happens to be a symlink, extracting into it gets rejected with -107.
The check only needs to police symlinks that appear strictly inside
the destination, since those could be zip-controlled.

Skip the symlink check when check_path is at or above base_path; let
the existing logic enforce on components below.

Fixes #943.
2026-04-25 01:21:33 -07:00
Nathan Moin Vaziri 8ec500fd38 cmake: rename MINIZIP_PUBLIC_LIB variable 2026-04-25 01:21:33 -07:00
Nathan Moin Vaziri b3bb871157 cmake: clean up and tighten comments 2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri c6fd0d701e cmake: skip find_dependency for PRIVATE deps when building shared
A shared minizip encapsulates its PRIVATE backend deps (bzip2, lzma, zstd,
iconv, ...) inside the .so/.dylib, and minizip-targets.cmake doesn't
reference them. Emitting find_dependency() for those backends in the
generated package config forces consumers of shared minizip to install
every backend just to call find_package(minizip), even when nothing
needs them.

Split MINIZIP_DEP_PKG into a PUBLIC list (always required, e.g. ZLIB
under MZ_COMPAT) and a private list emitted only when minizip is built
static. The static archive still requires all of them transitively.

Fixes #898.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 434593c8af cmake: remove bundled FindZLIB-NG module
find_package(ZLIB-NG QUIET CONFIG) reads zlib-ng's installed
zlib-ng-config.cmake and the matching zlib-ng-targets-<config>.cmake
files, so the bundled MODULE-mode finder is no longer consulted. The
upstream config knows the correct library names per build configuration
(including the -ngd debug suffix on MSVC), which the bundled finder
didn't.

Fixes #952.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 74609ad447 cmake: delegate OpenSSL pkg-config naming to Requires.private
Hard-coding "-lssl -lcrypto" in Libs.private breaks for LibreSSL (different
library names), MSVC import libraries, and custom build suffixes. Reference
openssl in Requires.private instead so the consumer's pkg-config delegates
to openssl.pc and resolves the correct library names locally.

Caught in PR review on #983.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 8aabaf214e cmake: link zlib PUBLIC when MZ_COMPAT exposes it in headers
compat/zip.h and compat/unzip.h reference zlib types and macros (ZEXPORT,
Z_DEFLATED, ...), so any consumer including those headers needs zlib's
INTERFACE_INCLUDE_DIRECTORIES on its include path. Linking via the imported
target keeps the install portable: find_dependency(ZLIB) on the consumer
recreates the target with the consumer's local paths, not the build host's.

Other backends are pure implementation details and stay PRIVATE.

Refs #914.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 6e97fbea09 cmake: only register found packages in MINIZIP_DEP_PKG
The list drives find_dependency() calls in the generated minizip-config.cmake,
so registering a package whose CMake config doesn't exist on the consumer
machine (PPMD, fetched BZip2/LibLZMA/zstd, etc.) makes find_package(minizip)
fail at configure time. Only register a package when it was located via
find_package, not when built from a fetched source tree (those targets are
already carried forward through install(EXPORT)).

Add Threads to MINIZIP_DEP_PKG when liblzma is fetched, since upstream xz's
exported target lists Threads::Threads in its INTERFACE_LINK_LIBRARIES and
the consumer's config has to recreate that imported target.

Refs #914.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 6a99a9533f cmake: link backend deps as PRIVATE and drop target_link_directories
Backend libraries (zlib, bzip2, lzma, zstd, openssl, iconv, frameworks)
are implementation details that don't appear in mz.h's public API, so
their linkage is PRIVATE rather than PUBLIC. For static minizip CMake
still propagates them transitively via INTERFACE_LINK_LIBRARIES_PRIVATE
when needed; for shared minizip they stay encapsulated and don't pollute
consumer link lines.

The target_link_directories call is no longer needed because every
imported target carries its own library directory; MINIZIP_LBD is
removed along with it.

Refs #914.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 1d5bc8d591 cmake: use -framework linker flags for CoreFoundation and Security
find_library returns SDK-absolute paths like
/Applications/Xcode.app/.../MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework
which get baked into INTERFACE_LINK_LIBRARIES on install and break
downstream consumers whose SDK lives at a different path. Pass the
frameworks as plain "-framework Foo" linker flags so each consumer's
own toolchain resolves them.

Refs #914.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri a3c6e8c02d cmake: use imported targets for compression and crypto backends
Replace raw ${FOO_LIBRARIES} / ${FOO_LIBRARY_DIRS} / ${FOO_INCLUDE_DIRS}
appends with imported target references so installed targets files don't
bake build-machine paths into INTERFACE_LINK_LIBRARIES. Affects ZLIB-NG,
ZLIB, BZip2, LibLZMA, ZSTD, OpenSSL, Iconv, and libbsd. Drops the
pkg-config-first paths for LZMA/ZSTD/OpenSSL since find_package now
provides portable imported targets across CMake 3.14+.

Refs #914.
2026-04-25 00:43:12 -07:00
Nathan Moin Vaziri 9826cbd435 Version 4.1.2. 2026-04-24 22:50:35 -07:00
Nathan Moin Vaziri c7c6ea74fb cmake: remove duplicate source include dir 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 0a7ddd02dc cmake: use target_link_options instead of set_target_properties 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 31049d44e8 cmake: fix comment for check_function_exists calls 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 322c161a2f cmake: don't check ZLIB_COMPAT before it is set in MZ_FETCH_LIBS 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 597ee06152 cmake: fix formatting before HOMEPAGE_URL 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 96f1134432 cmake: remove unnecessary include dirs for test binaries 2026-04-24 22:49:28 -07:00
Nathan Moin Vaziri 84f3b20390 cmake: generate mz_config.h in build directory 2026-04-24 22:01:02 -07:00
Nathan Moin Vaziri 37adbba1d1 Version 4.1.1. 2026-04-22 21:10:20 -07:00
Nathan Moin Vaziri c37440f253 Build libc++ with MSAN instrumentation for gtest_minizip
gtest_minizip fails under MSAN with use-of-uninitialized-value in
std::basic_string's small-string-optimization union during static
TEST() registration, because system libstdc++ (and Ubuntu's libc++)
are not built with MSAN. We follow zlib-ng's approach.
2026-04-22 20:59:10 -07:00
Nathan Moin Vaziri ad05efe8e1 Upload all coverage reports at once 2026-04-22 20:59:10 -07:00
Nathan Moin Vaziri ced107ccc6 Implement MSAN_OPTIONS env variable in build workflow. 2026-04-22 20:59:10 -07:00
Nathan Moin Vaziri 4d9088de97 Force-fetch compression libraries so they are MSAN instrumented
System libz on Ubuntu is not built with MSAN, which produced
use-of-uninitialized-value reports in mz_stream_os_write when
flushing bytes that came out of zlib's deflate (the internal state
buffer is malloc'd and written by uninstrumented code).

Set MZ_FORCE_FETCH_LIBS=ON so zlib-ng, bzip2, liblzma and zstd are
built from source with the project's MSAN flags. This mirrors what
the Windows MSVC job already does for unrelated reasons.
2026-04-22 20:59:10 -07:00
Nathan Moin Vaziri 3ffb8de0fd Disable OpenSSL to avoid libcrypto false positives for MSAN
System libcrypto on Ubuntu is not built with MSAN, so calls into
OPENSSL_init_crypto (via EVP_MD_fetch and EVP_MAC_fetch in
mz_crypt_openssl.c) produced ~130 use-of-uninitialized-value reports
in BIO_new_file and OBJ_obj2txt for buffers allocated inside the
uninstrumented library.

Disable MZ_OPENSSL for the MSAN job so the built-in crypto path
is used instead, which is instrumented along with the rest of the
project sources.
2026-04-22 20:59:10 -07:00
Nathan Moinvaziri 27cdb50b66 Use python from setup-python action. 2026-03-18 17:18:46 -07:00
Nathan MoinvaziriandClaude Opus 4.6 af59994a45 Fix integer overflow in split stream write for disk sizes > 2GB
The bytes_avail variable was declared as int32_t and the 64-bit result
of (disk_size - total_out_disk) was cast to int32_t, causing truncation
and wraparound for split sizes exceeding INT32_MAX (~2GB). This resulted
in MZ_STREAM_ERROR when creating archives with split sizes above ~50GB.

Changed bytes_avail to int64_t and removed the truncating cast.

Fixes #961

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 19:14:32 -07:00
Nathan Moinvaziri b6bf9914db Add cmake subdirectory support to clone_repo macro for zstd. 2026-03-02 16:59:55 -08:00
Nathan Moinvaziri 9975579a7f Sync sanitizer detection CMake with zlib-ng. 2026-03-02 12:31:38 -08:00
Nathan Moinvaziri db034d5618 Remove redundant MZ_ZLIB_FLAVORS variable and validation check 2026-02-18 10:27:25 -08:00
Nathan Moinvaziri 9c32106827 Fix for older versions of CMake without FetchContent EXCLUDE_FROM_ALL 2026-02-09 15:04:50 -08:00
Nathan Moinvaziri 41ad65fc10 Add TearDown cleanup for compat test temp files 2026-02-03 14:17:11 -08:00
Nathan Moinvaziri c8c49425fc Add TearDown cleanup for encrypt test temp files 2026-02-03 13:47:39 -08:00
Nathan Moinvaziri 0574b3b815 Allocate symlink buffers on first use 2026-01-30 10:03:21 -08:00
Nathan Moinvaziri 32747dc514 Use fixed buffer size for symlink target instead of path length 2026-01-27 09:31:40 -08:00
Nathan Moinvaziri 9963dd30c5 Add buffer overflow check in mz_os_read_symlink function #944 2026-01-27 09:29:49 -08:00
Nathan Moinvaziri 0fa77a3861 Resolve alias targets to their real targets for installation
This should fix CMake on Windows failing.
2026-01-27 09:13:59 -08:00
Nathan Moinvaziri 185667ebff Move symlink safety check before overwrite callback in zip extract #945 2026-01-27 08:42:54 -08:00
Nathan Moinvaziri cf4b58e17e Version 4.1.0. 2026-01-21 13:52:59 -08:00
Nathan Moinvaziri 5a3c62cf70 Fix arbitrary file write vulnerability via temp file symlink #938 2026-01-21 13:48:10 -08:00
Nathan Moinvaziri bb282ace22 Fixed arbitrary file write vulnerability via symlinks. #936 2026-01-21 13:48:10 -08:00
Nathan Moinvaziri d214437dd8 Use unsigned int instead of uint32_t in crypt.h for max compat. #897 2025-07-25 18:54:22 -07:00
Nathan Moinvaziri f3ed731e27 Version 4.0.10. 2025-05-04 21:36:06 -04:00
Nathan Moinvaziri e9ab17807e Remove old ubuntu CI run 2025-05-04 21:31:47 -04:00
Nathan Moinvaziri 95ba7abdd2 Version 4.0.9. 2025-04-05 11:07:02 -07:00
Nathan Moinvaziri aa33f4c25e Don't use Z_ERRNO if zlib not included. #852 2025-04-05 11:00:59 -07:00
Nathan Moinvaziri 581a403078 Fix default branch name in lint workflow. 2025-04-02 08:00:44 -07:00
Nathan Moinvaziri 4f571d6e38 Add lint workflow for clang-format 2025-03-25 08:04:19 -07:00
Nathan Moinvaziri 55db144e03 Version 4.0.8. 2025-01-08 10:12:15 -08:00
Nathan Moinvaziri 3bced613bc Move zlib include to zip/unzip headers like org minizip. 2024-11-11 10:56:18 -08:00
Nathan Moinvaziri 2c51fa719e Clang-format style changes. 2024-11-01 16:37:57 -07:00
Nathan Moinvaziri 7df56f7cc8 Split compat layer into different source files #806 2024-10-30 18:11:27 -04:00
Nathan Moinvaziri cc14474b37 Move mz_compat to compat folder. 2024-10-30 18:11:27 -04:00
Nathan Moinvaziri 0bf8db3cff Fixed GCC warnings about path_length reuse in strncat. 2024-10-30 18:11:27 -04:00
Nathan Moinvaziri 6946ba67d0 Fixed disk spanning failures due to changes in #799.
At the end of a disk, we return any bytes read before proceeding to
the next disk. This allows us to return MZ_EXIST_ERROR when the next
disk is not found.
2024-10-30 13:01:47 -04:00
Nathan Moinvaziri 9aeff7bc29 Fixed whitespace in mz_stream_split_open_disk. 2024-10-23 11:28:07 -07:00
Nathan Moinvaziri 0ee98b6909 Check version when verifying password for pkcrypt. #800 2024-10-18 12:01:40 -07:00
Nathan Moinvaziri fe5fedc365 Version 4.0.7. 2024-06-15 09:21:44 -07:00
Nathan Moinvaziri bfc8f6c9e1 Added definition for zipOpenNewFileInZip64 for backwards compat #787 2024-06-15 09:16:27 -07:00
Nathan Moinvaziri b887f8104b Rename cli instead of lib for VS conflicts to prevent linker error. #778 2024-06-07 19:48:35 -07:00
Nathan Moinvaziri 1ddb23dfc0 Clean up casing in CMake. 2024-06-07 19:48:03 -07:00
Nathan Moinvaziri a64aa8bb4b Only setup python when codecov is enabled. 2024-06-07 19:27:28 -07:00
Nathan Moinvaziri 51ab7c599d Fix macos-latest not properly locating OpenSSL. 2024-06-07 19:27:00 -07:00
Nathan Moinvaziri 2f380cbbbf Upgrade to GoogleTest Framework v1.13.0. 2024-06-07 19:26:12 -07:00
Nathan Moinvaziri 71334463b2 Turn off building shared libraries in CI. 2024-06-01 20:05:05 -07:00
Nathan Moinvaziri 437d2f0e4d Use default version of gcovr. 2024-06-01 19:55:15 -07:00
Nathan Moinvaziri 8a00c0e9fb Disable zlib-ng tests. 2024-06-01 18:30:05 -07:00
Nathan Moinvaziri d3bc79cd0d Cancel CI jobs when newer HEAD commit available. 2024-06-01 16:48:10 -07:00
Nathan Moinvaziri f1e9f85777 Reorder branches in readme after making develop default branch. 2024-06-01 16:46:30 -07:00
Nathan Moinvaziri db940ff659 Fixed zlib-ng build error about installing zlibstatic alias. 2024-06-01 16:44:53 -07:00
Nathan Moinvaziri 1e402d2c2a Rename minizip_cmd to minizip_cli. 2024-06-01 16:44:30 -07:00
Nathan Moinvaziri 4cec116210 Version 4.0.6. 2024-06-01 14:10:39 -07:00
Nathan Moinvaziri 07db361a6e Fixed listing empty zip file. #756 2024-06-01 14:09:47 -07:00
Nathan Moinvaziri 288b2e249e Revert "Add empty directories to zip file. #756"
This reverts commit 168f9ffee7.
2024-06-01 13:59:23 -07:00
Nathan Moinvaziri c7ed3c8e4c Update liblzma repository to GitHub. 2024-06-01 13:39:36 -07:00
Nathan Moinvaziri 0725402ff1 Switch to using zlib-ng stable.
zlib's CMake is just fucked up for far too long.
2024-06-01 13:27:20 -07:00
Nathan Moinvaziri 5aec551bf7 Fixed zstd master branch no longer working. 2024-04-01 09:44:11 -07:00
Nathan Moinvaziri 990f512941 Added permissions needed for codeql-action v3. 2024-03-06 08:54:18 -08:00
Nathan Moinvaziri d26500513c Target develop branch for dependabot updates. 2024-03-05 19:36:27 -08:00
Nathan Moinvaziri 3eed562ef0 Version 4.0.5. 2024-03-05 19:30:16 -08:00
Nathan Moinvaziri 552b4831da Keep github actions up-to-date 2024-02-22 16:11:07 -08:00
Nathan Moinvaziri 168f9ffee7 Add empty directories to zip file. #756 2024-02-16 18:56:15 -08:00
Nathan Moinvaziri 0c3a741b36 Remove left over signing code from v3. 2024-02-16 18:32:53 -08:00
Nathan Moinvaziri 4bd8ebc090 Use correct version needed to extract for BZIP2. #763 2024-02-16 18:25:00 -08:00
Nathan Moinvaziri 32f91ade14 Add packaging status badge to readme. 2024-01-13 16:46:52 -08:00
Nathan Moinvaziri a7d612adf2 Use hexadecimal prefix for MZ_VERSION_BUILD. #758 2024-01-04 10:05:59 -08:00
Nathan Moinvaziri 13b01a74a4 Version 4.0.4. 2023-12-29 07:05:05 -08:00
Nathan Moinvaziri bacf5122ac Fixed compat layer structures layout and types. #749 2023-12-17 09:45:33 -08:00