Commit graph

2408 commits

Author SHA1 Message Date
krleejihyeong
7d2917b47f
Fix dangling pointer in mz_zip_set_comment() to prevent double-free/UAF (#1031)
Some checks failed
Build / Ubuntu Clang No Bzip2 (push) Failing after 5s
Build / Ubuntu Clang Compress Only (push) Failing after 4s
Build / Ubuntu Clang Decompress Only (push) Failing after 3s
Build / Ubuntu Clang ICU (push) Failing after 2s
Build / Ubuntu Clang No LZMA (push) Failing after 2s
Build / Ubuntu Clang OpenSSL (push) Failing after 2s
Build / Ubuntu Clang No Encryption (push) Failing after 2s
Build / Ubuntu Clang No Pkcrypt (push) Failing after 2s
Build / Ubuntu Clang No Ppmd (push) Failing after 2s
Build / Ubuntu Clang No Winzip AES (push) Failing after 2s
Build / Ubuntu Clang No Zlib (push) Failing after 2s
Build / Ubuntu Clang No Zstd (push) Failing after 2s
Build / Ubuntu Clang (push) Failing after 2s
Build / Ubuntu GCC (push) Failing after 2s
Build / Ubuntu GCC ASAN (push) Failing after 2s
Build / Ubuntu GCC UBSAN (push) Failing after 2s
Build / Ubuntu GCC OSB (push) Failing after 2s
Build / Ubuntu Clang MSAN (push) Failing after 2s
CodeQL / Analyze (push) Failing after 2s
Build / Windows GCC Code Coverage (push) Has been cancelled
Build / macOS Xcode LibCompression (push) Has been cancelled
Build / macOS Xcode OpenSSL (push) Has been cancelled
Build / macOS Xcode Code Coverage (push) Has been cancelled
Build / Windows MSVC (push) Has been cancelled
Build / Ubuntu 22 Clang (push) Has been cancelled
Build / Ubuntu 22 Clang 11 (push) Has been cancelled
Build / macOS Xcode (push) Has been cancelled
Build / Upload Coverage Reports (push) Has been cancelled
zip->comment was freed before validating the new comment length.
When the new comment exceeds UINT16_MAX, the function returned early
without resetting zip->comment to NULL, leaving a dangling pointer
that mz_zip_close() would later free again (double-free / UAF).
2026-08-22 20:53:20 -07:00
Nathan Moin Vaziri
13fee4ade0
Simplify logic for setting comment in mz_zip. 2026-08-22 20:39:50 -07:00
krleejihyeong
6872bc23ca
Fix comment leak in mz_zip_read_cd() (#1032)
zip->comment was overwritten with a newly malloc'd buffer without
freeing any previously allocated comment, leaking memory if the zip
handle already had a comment set (e.g. on a repeated mz_zip_open()
call on the same handle).
2026-08-22 20:39:50 -07:00
dc8531deb7
ppmd: fix memory leak (#1030) 2026-08-06 21:47:01 -07:00
dependabot[bot]
0bc12cea19 build(deps): bump actions/setup-python from 6 to 7
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-31 18:21:27 -07:00
dependabot[bot]
4587bf361a build(deps): bump github/codeql-action from 4 to 4.37.3
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4 to 4.37.3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v4...v4.37.3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.37.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-31 17:51:58 -07:00
Sergey Markelov
6eab58f20b crypt: macos: fix: mz_crypt_aes_{encrypt,decrypt}_final with NULL in buf
`CCCryptorGCMEncrypt()` and `CCCryptorGCMDecrypt()` returned kCCParamError
(-4300).
2026-07-13 22:21:02 -07:00
Brad Smith
d805b1b079 fix: warning: format specifies type 'unsigned long' but the argument has type 'time_t'
mz_os_posix.c:409:61: warning: format specifies type 'unsigned long' but the argument
has type 'time_t' (aka 'long long') [-Wformat]
  409 |     result = snprintf(path, max_path, "%s/%lux", temp_path, time(NULL));
      |                                           ~~~               ^~~~~~~~~~
      |                                           %lld
1 warning generated.
2026-07-13 11:01:14 -07:00
tbeu
04c976d369 #597 Allow recover flag to read zips with >65535 entries missing zip64 EOCD
When number_entry in the standard EOCD is UINT16_MAX, the reader looks for a zip64 EOCD record. If not found, it returned MZ_FORMAT_ERROR even when the recover flag was set.
2026-07-07 09:22:25 -07:00
tbeu
b59f684429 #998 Add MZ_ICU option for string encoding conversion
Add ICU as an alternative backend to libiconv using ucnv_convert.
ICU is detected via CMake's FindICU module on non-Windows platforms.
Add CI build configuration for ICU in GitHub Actions.
2026-07-06 22:45:39 -07:00
tbeu
cde8b2f81b #997 Fix resource leaks 2026-07-05 17:17:39 -07:00
pmas
dfa766eb53 Update to use upstream 7zip version 26.02 2026-07-01 08:37:05 -07:00
dependabot[bot]
2ac3cd2555 build(deps): bump actions/checkout from 6 to 7
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-30 18:46:04 -07:00
dependabot[bot]
3e598214eb build(deps): bump actions/cache from 5 to 6
Bumps [actions/cache](https://github.com/actions/cache) from 5 to 6.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-30 18:45:53 -07:00
dependabot[bot]
e8c1d2d0af build(deps): bump codecov/codecov-action from 6 to 7
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 6 to 7.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v6...v7)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-30 18:45:40 -07:00
Paul Marquess
bf7aa90bcd Update to use upstream 7zip version 26.01 2026-06-30 09:47:47 -07:00
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
Sergei
181642d2f8 test: improve: validate cipher bytes after encryption
The independent cipher bytes (encrypted text) are gotten on a 3rd party site.
2026-06-26 15:34:49 -07:00
Sergei
dbdb1059d0 fix: mz_crypt_aes_set_*_key for GCM on OpenSSL
AES-GCM block size is 128 bits but IV size is 96+ bits.
2026-06-25 07:09:28 -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
Ren yiwei
ff303ab67d docs: update memory stream test link 2026-06-21 12:10:19 -07:00
Sergei
d69cb0a539 fix: warning: '=': narrowing conversion, possible loss of data 2026-05-16 12:32:12 -07:00
dependabot[bot]
947848cb1a build(deps): bump actions/upload-artifact from 6 to 7
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-30 18:00:14 -07:00
dependabot[bot]
55c760e5b1 build(deps): bump actions/download-artifact from 7 to 8
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7 to 8.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v7...v8)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-30 17:58:14 -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
Benjamin Buch
9a92170979 cmake: rename target files to avoid overwrite of PACKAGE_VERSION 2026-04-24 22:49:28 -07:00
Andrew Patterson
288b7f1d4b cmake: install crypt.h if using compatability mode #862 2026-04-24 22:49:28 -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