[minizip] Updated from v2.10.5 to minizip-ng 3.0.0.

As of 3.0.0, the minizip fork is now called minizip-ng.

https://github.com/zlib-ng/minizip-ng
This commit is contained in:
David Korth 2021-02-17 18:38:19 -05:00
parent b3859eb353
commit 7d302b51c9
72 changed files with 699 additions and 989 deletions

View File

@ -264,7 +264,7 @@ ENDIF(USE_INTERNAL_LZ4)
IF(USE_INTERNAL_LZO)
SET(EXTLIB_BUILD "${EXTLIB_BUILD} - MiniLZO\n")
ENDIF(USE_INTERNAL_LZO)
SET(EXTLIB_BUILD "${EXTLIB_BUILD} - minizip\n")
SET(EXTLIB_BUILD "${EXTLIB_BUILD} - minizip-ng\n")
SET(EXTLIB_BUILD "${EXTLIB_BUILD} - inih\n")
IF(USE_INTERNAL_XML)
SET(EXTLIB_BUILD "${EXTLIB_BUILD} - TinyXML2\n")

10
extlib/CMakeLists.txt vendored
View File

@ -123,7 +123,7 @@ IF(USE_INTERNAL_ZSTD)
SET_EXTLIB_PROPERTIES(zstdstatic)
ENDIF(USE_INTERNAL_ZSTD)
# MiniZip
# minizip-ng
SET(SKIP_INSTALL_LIBRARIES ON)
SET(SKIP_INSTALL_ALL ON)
SET(BUILD_SHARED_LIBS OFF)
@ -145,12 +145,12 @@ SET(MZ_ICONV OFF)
SET(MZ_SIGNING OFF)
SET(MZ_COMPRESS_ONLY OFF)
SET(MZ_DECOMPRESS_ONLY OFF)
SET(MZ_BUILD_TEST ON) # Allow manually building test executables.
SET(MZ_BUILD_UNIT_TEST OFF)
SET(MZ_BUILD_FUZZ_TEST OFF)
SET(MZ_BUILD_TESTS ON) # Allow manually building test executables.
SET(MZ_BUILD_UNIT_TESTS OFF)
SET(MZ_BUILD_FUZZ_TESTS OFF)
SET(MZ_CODE_COVERAGE OFF)
SET(MZ_FILE32_API OFF)
ADD_SUBDIRECTORY(minizip)
ADD_SUBDIRECTORY(minizip-ng)
SET_EXTLIB_PROPERTIES(minizip)
SET_EXTLIB_PROPERTIES(minigzip_cmd)
SET_EXTLIB_PROPERTIES(minizip_cmd)

View File

@ -1,6 +1,6 @@
#***************************************************************************
# Copyright (C) 2017-2020 Nathan Moinvaziri
# https://github.com/nmoinvaz/minizip
# https://github.com/zlib-ng/minizip-ng
# Copyright (C) 2016 Matthias Schmieder
# schmieder.matthias@gmail.com
#***************************************************************************
@ -11,29 +11,36 @@ message(STATUS "Using CMake version ${CMAKE_VERSION}")
# rom-properties: Disabled these options.
IF(0)
# Compatibility options
option(MZ_COMPAT "Enables compatibility layer" ON)
# Compression library options
option(MZ_ZLIB "Enables ZLIB compression" ON)
option(MZ_BZIP2 "Enables BZIP2 compression" ON)
option(MZ_LZMA "Enables LZMA & XZ compression" ON)
option(MZ_ZSTD "Enables ZSTD compression" ON)
option(MZ_FETCH_LIBS "Enables fetching third-party libraries if not found" ON)
option(MZ_LIBCOMP "Enables Apple compression" ${APPLE})
option(MZ_FETCH_LIBS "Enables fetching third-party libraries if not found" ${WIN32})
option(MZ_FORCE_FETCH_LIBS "Enables fetching third-party libraries always" OFF)
# Encryption support options
option(MZ_PKCRYPT "Enables PKWARE traditional encryption" ON)
option(MZ_WZAES "Enables WinZIP AES encryption" ON)
option(MZ_LIBCOMP "Enables Apple compression" OFF)
option(MZ_OPENSSL "Enables OpenSSL for encryption" OFF)
option(MZ_LIBBSD "Enable libbsd crypto random" ON)
option(MZ_BRG "Enables Brian Gladman's encryption library" OFF)
option(MZ_ICONV "Enables iconv for string encoding conversion" ON)
option(MZ_OPENSSL "Enables OpenSSL for encryption" ${UNIX})
option(MZ_LIBBSD "Enable libbsd crypto random" ${UNIX})
option(MZ_SIGNING "Enables zip signing support" ON)
# Character conversion options
option(MZ_ICONV "Enables iconv for string encoding conversion" ON)
# Code generation options
option(MZ_COMPRESS_ONLY "Only support compression" OFF)
option(MZ_DECOMPRESS_ONLY "Only support decompression" OFF)
option(MZ_BUILD_TEST "Builds minizip test executable" OFF)
option(MZ_BUILD_UNIT_TEST "Builds minizip unit test project" OFF)
option(MZ_BUILD_FUZZ_TEST "Builds minizip fuzzer executables" OFF)
option(MZ_CODE_COVERAGE "Builds with code coverage flags" OFF)
option(MZ_FILE32_API "Builds using posix 32-bit file api" OFF)
# Build and continuous integration options
option(MZ_BUILD_TESTS "Builds minizip test executable" OFF)
option(MZ_BUILD_UNIT_TESTS "Builds minizip unit test project" OFF)
option(MZ_BUILD_FUZZ_TESTS "Builds minizip fuzzer executables" OFF)
option(MZ_CODE_COVERAGE "Builds with code coverage flags" OFF)
# Package management options
set(MZ_PROJECT_SUFFIX "" CACHE STRING "Project name suffix for package managers")
mark_as_advanced(MZ_FILE32_API MZ_PROJECT_SUFFIX)
ENDIF(0)
@ -44,20 +51,35 @@ IF(MZ_ZSTD)
include_directories(${ZSTD_INCLUDE_DIRS})
ENDIF(MZ_ZSTD)
# Backwards compatibility
if(DEFINED MZ_BUILD_TEST)
set(MZ_BUILD_TESTS ${MZ_BUILD_TEST})
endif()
if(DEFINED MZ_BUILD_UNIT_TEST)
set(MZ_BUILD_UNIT_TESTS ${MZ_BUILD_UNIT_TEST})
endif()
if(DEFINED MZ_BUILD_FUZZ_TEST)
set(MZ_BUILD_FUZZ_TESTS ${MZ_BUILD_FUZZ_TEST})
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 OLD)
endif()
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
# ZLIB_ROOT - Parent directory of zlib installation
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation
enable_language(C)
# Minizip library version
set(VERSION "2.10.5")
# Library version
set(VERSION "3.0.0")
# Minizip api version
set(SOVERSION "2.5")
# API version
set(SOVERSION "3.0")
include(CheckLibraryExists)
include(CheckSymbolExists)
@ -180,12 +202,23 @@ macro(clone_repo name url)
endmacro()
if(MZ_LIBCOMP)
# Use Apple libcompression
list(APPEND MINIZIP_DEF -DHAVE_LIBCOMP)
list(APPEND MINIZIP_SRC mz_strm_libcomp.c)
list(APPEND MINIZIP_HDR mz_strm_libcomp.h)
list(APPEND MINIZIP_LIB compression)
elseif(MZ_ZLIB)
if(APPLE)
# Use Apple libcompression
list(APPEND MINIZIP_DEF -DHAVE_LIBCOMP)
list(APPEND MINIZIP_SRC mz_strm_libcomp.c)
list(APPEND MINIZIP_HDR mz_strm_libcomp.h)
list(APPEND MINIZIP_LIB compression)
# Disable zlib as libcompression is preferred
set(MZ_ZLIB OFF)
else()
message(STATUS "LibCompression not supported on the current platform")
set(MZ_LIBCOMP OFF)
endif()
endif()
if(MZ_ZLIB)
# Check if zlib is present
if(NOT MZ_FORCE_FETCH_LIBS)
find_package(ZLIB QUIET)
@ -216,15 +249,19 @@ elseif(MZ_ZLIB)
list(APPEND MINIZIP_DEP zlib)
endif()
else()
message(FATAL_ERROR "ZLIB not found")
message(STATUS "ZLIB library not found")
set(MZ_ZLIB OFF)
endif()
list(APPEND MINIZIP_DEF -DHAVE_ZLIB)
if(ZLIB_COMPAT)
list(APPEND MINIZIP_DEF -DZLIB_COMPAT)
if(MZ_ZLIB)
list(APPEND MINIZIP_DEF -DHAVE_ZLIB)
if(ZLIB_COMPAT)
list(APPEND MINIZIP_DEF -DZLIB_COMPAT)
endif()
list(APPEND MINIZIP_SRC mz_strm_zlib.c)
list(APPEND MINIZIP_HDR mz_strm_zlib.h)
endif()
list(APPEND MINIZIP_SRC mz_strm_zlib.c)
list(APPEND MINIZIP_HDR mz_strm_zlib.h)
endif()
if(MZ_BZIP2)
@ -266,12 +303,16 @@ if(MZ_BZIP2)
list(APPEND MINIZIP_DEP bzip2)
list(APPEND MINIZIP_INC lib/bzip2)
else()
message(FATAL_ERROR "BZip2 not found")
message(STATUS "BZip2 library not found")
set(MZ_BZIP2 OFF)
endif()
list(APPEND MINIZIP_DEF -DHAVE_BZIP2)
list(APPEND MINIZIP_SRC mz_strm_bzip.c)
list(APPEND MINIZIP_HDR mz_strm_bzip.h)
if(MZ_BZIP2)
list(APPEND MINIZIP_DEF -DHAVE_BZIP2)
list(APPEND MINIZIP_SRC mz_strm_bzip.c)
list(APPEND MINIZIP_HDR mz_strm_bzip.h)
endif()
endif()
if(MZ_LZMA)
@ -304,12 +345,16 @@ if(MZ_LZMA)
list(APPEND MINIZIP_DEP liblzma)
list(APPEND MINIZIP_LIB ${LIBLZMA_TARGET})
else()
message(FATAL_ERROR "LZMA not found")
message(STATUS "LibLZMA library not found")
set(MZ_LZMA OFF)
endif()
list(APPEND MINIZIP_DEF -DHAVE_LZMA -DLZMA_API_STATIC)
list(APPEND MINIZIP_SRC mz_strm_lzma.c)
list(APPEND MINIZIP_HDR mz_strm_lzma.h)
if(MZ_LZMA)
list(APPEND MINIZIP_DEF -DHAVE_LZMA -DLZMA_API_STATIC)
list(APPEND MINIZIP_SRC mz_strm_lzma.c)
list(APPEND MINIZIP_HDR mz_strm_lzma.h)
endif()
endif()
if(MZ_ZSTD)
@ -333,7 +378,7 @@ if(MZ_ZSTD)
list(APPEND MINIZIP_LBD ${ZSTD_LIBRARY_DIRS})
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lzstd")
else()
elseif(MZ_FETCH_LIBS)
clone_repo(zstd https://github.com/facebook/zstd)
# Don't automatically add all targets to the solution
@ -346,11 +391,24 @@ if(MZ_ZSTD)
list(APPEND MINIZIP_DEP libzstd_shared)
endif()
list(APPEND MINIZIP_LIB ${ZSTD_TARGET})
else()
message(STATUS "ZSTD library not found")
set(MZ_ZSTD OFF)
endif()
list(APPEND MINIZIP_DEF -DHAVE_ZSTD)
list(APPEND MINIZIP_SRC mz_strm_zstd.c)
list(APPEND MINIZIP_HDR mz_strm_zstd.h)
if(MZ_ZSTD)
list(APPEND MINIZIP_DEF -DHAVE_ZSTD)
list(APPEND MINIZIP_SRC mz_strm_zstd.c)
list(APPEND MINIZIP_HDR mz_strm_zstd.h)
endif()
endif()
if(NOT MZ_LIBCOMP AND NOT MZ_ZLIB AND NOT MZ_ZSTD AND NOT MZ_BZIP2 AND NOT MZ_LZMA)
message(STATUS "Compression not supported due to missing libraries")
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_DECOMPRESSION)
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_COMPRESSION)
endif()
if(MZ_OPENSSL)
@ -374,6 +432,10 @@ if(MZ_OPENSSL)
if(OPENSSL_INCLUDE_DIRS)
list(APPEND MINIZIP_INC ${OPENSSL_INCLUDE_DIRS})
endif()
else()
message(STATUS "OpenSSL library not found")
set(MZ_OPENSSL OFF)
endif()
endif()
@ -382,15 +444,13 @@ if(WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
list(APPEND MINIZIP_DEF -D_CRT_SECURE_NO_DEPRECATE)
list(APPEND MINIZIP_SRC mz_os_win32.c mz_strm_os_win32.c)
if(MZ_PKCRYPT OR MZ_WZAES)
if(NOT MZ_BRG)
if(NOT MZ_OPENSSL AND NOT OPENSSL_FOUND)
list(APPEND MINIZIP_SRC mz_crypt_win32.c)
endif()
# GCC doesn't support #pragma lib
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
list(APPEND MINIZIP_LIB crypt32.lib)
endif()
if(MZ_PKCRYPT OR MZ_WZAES OR MZ_SIGNING)
if(NOT MZ_OPENSSL)
message(STATUS "Using CryptoAPI")
list(APPEND MINIZIP_SRC mz_crypt_win32.c)
list(APPEND MINIZIP_LIB crypt32.lib)
endif()
endif()
endif()
@ -403,29 +463,106 @@ if(UNIX)
list(APPEND STDLIB_DEF -D_POSIX_C_SOURCE=200112L)
list(APPEND MINIZIP_SRC mz_os_posix.c mz_strm_os_posix.c)
if((MZ_PKCRYPT OR MZ_WZAES) AND NOT (MZ_OPENSSL AND OPENSSL_FOUND))
if(MZ_PKCRYPT OR MZ_WZAES OR MZ_SIGNING)
if(NOT MZ_OPENSSL)
if(APPLE)
message(STATUS "Using CoreFoundation Framework")
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
if(APPLE AND NOT MZ_BRG)
message(STATUS "Using CoreFoundation Framework")
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
list(APPEND MINIZIP_LIB ${COREFOUNDATION_LIBRARY})
list(APPEND MINIZIP_LIB ${COREFOUNDATION_LIBRARY})
message(STATUS "Using Security Framework")
find_library(SECURITY_LIBRARY Security)
message(STATUS "Using Security Framework")
find_library(SECURITY_LIBRARY Security)
list(APPEND MINIZIP_LIB ${SECURITY_LIBRARY})
list(APPEND MINIZIP_LFG "-Wl,-F/Library/Frameworks")
list(APPEND MINIZIP_LIB ${SECURITY_LIBRARY})
list(APPEND MINIZIP_LFG "-Wl,-F/Library/Frameworks")
check_include_file(CommonCrypto/CommonCrypto.h COMMONCRYPTO_FOUND)
if(COMMONCRYPTO_FOUND)
message(STATUS "Using CommonCrypto")
check_include_file(CommonCrypto/CommonCrypto.h COMMONCRYPTO_FOUND)
if(COMMONCRYPTO_FOUND)
list(APPEND MINIZIP_SRC mz_crypt_apple.c)
list(APPEND MINIZIP_SRC mz_crypt_apple.c)
set(MZ_LIBBSD OFF)
else()
message(STATUS "CommonCrypto library not found")
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO)
if(MZ_WZAES)
message(STATUS "WinZIP AES support requires CommonCrypto or OpenSSL")
set(MZ_WZAES OFF)
endif()
if(MZ_SIGNING)
message(STATUS "Signing support requires CommonCrypto or OpenSSL")
set(MZ_SIGNING OFF)
endif()
endif()
else()
message(STATUS "CommonCrypto not found, using BRG instead")
set(MZ_BRG TRUE)
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO)
if(MZ_WZAES)
message(STATUS "WinZIP AES support requires OpenSSL")
set(MZ_WZAES OFF)
endif()
if(MZ_SIGNING)
message(STATUS "Signing support requires OpenSSL")
set(MZ_SIGNING OFF)
endif()
endif()
if(MZ_PKCRYPT AND NOT MZ_WZAES)
# Check to see which random generation functions we have
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
if(HAVE_GETRANDOM)
list(APPEND MINIZIP_DEF -DHAVE_GETRANDOM)
endif()
check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF)
if(HAVE_ARC4RANDOM_BUF)
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM_BUF)
else()
check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM)
if(HAVE_ARC4RANDOM)
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM)
endif()
endif()
if(APPLE)
# Requires _DARWIN_C_SOURCE for arcrandom functions
list(APPEND MINIZIP_DEF -D_DARWIN_C_SOURCE)
endif()
if(MZ_LIBBSD AND NOT HAVE_ARC4RANDOM_BUF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBBSD libbsd)
if(LIBBSD_FOUND)
check_library_exists("${LIBBSD_LIBRARIES}" "arc4random_buf"
"${LIBBSD_LIBRARY_DIRS}" HAVE_LIBBSD_ARC4RANDOM_BUF)
if(HAVE_LIBBSD_ARC4RANDOM_BUF)
list(APPEND MINIZIP_DEF -DHAVE_LIBBSD -DHAVE_ARC4RANDOM_BUF)
list(APPEND MINIZIP_INC ${LIBBSD_INCLUDE_DIRS})
list(APPEND MINIZIP_LIB ${LIBBSD_LIBRARIES})
list(APPEND MINIZIP_LBD ${LIBBSD_LIBRARY_DIRS})
link_directories(${LIBBSD_LIBRARY_DIRS})
endif()
else()
set(MZ_LIBBSD OFF)
endif()
else()
set(MZ_LIBBSD OFF)
endif()
if(NOT MZ_LIBBSD AND NOT HAVE_GETRANDOM AND NOT HAVE_ARC4RANDOM_BUF AND NOT HAVE_ARC4RANDOM)
message(WARNING "Low quality entropy function used for encryption")
endif()
endif()
else()
set(MZ_BRG TRUE)
endif()
endif()
@ -447,8 +584,13 @@ if(UNIX)
set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -liconv")
else()
message(WARNING "Limited encoding support due to disabled or missing iconv")
message(STATUS "Character encoding support requires iconv")
set(MZ_ICONV OFF)
endif()
else()
set(MZ_LIBBSD OFF)
set(MZ_ICONV OFF)
endif()
# Setup predefined macros
@ -458,24 +600,15 @@ endif()
if(MZ_DECOMPRESS_ONLY)
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_COMPRESSION)
endif()
if(MZ_FILE32_API)
list(APPEND MINIZIP_DEF -DMZ_FILE32_API)
endif()
# Determine if signing is supported
if(NOT MZ_PKCRYPT AND NOT MZ_WZAES)
list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_ENCRYPTION)
message(STATUS "Signing not supported when encryption is disabled")
set(MZ_SIGNING OFF)
endif()
if(MZ_BRG OR (MZ_OPENSSL AND NOT OPENSSL_FOUND))
message(STATUS "Signing not supported with current configuration")
set(MZ_SIGNING OFF)
endif()
if(MZ_SIGNING)
list(APPEND MINIZIP_DEF -DMZ_ZIP_SIGNING)
endif()
if(MZ_FILE32_API)
list(APPEND MINIZIP_DEF -DMZ_FILE32_API)
endif()
# Include traditional PKWare encryption
if(MZ_PKCRYPT)
@ -491,97 +624,11 @@ if(MZ_WZAES)
list(APPEND MINIZIP_HDR mz_strm_wzaes.h)
endif()
# Include Brian Gladman's crypto library
if(MZ_BRG)
if(NOT MZ_FETCH_LIBS)
message(FATAL_ERROR "AES and SHA libraries not found")
endif()
clone_repo(aes https://github.com/BrianGladman/aes)
clone_repo(sha https://github.com/BrianGladman/sha)
set(BRG_AES_SRC
lib/aes/brg_endian.h
lib/aes/brg_types.h
lib/aes/aescrypt.c
lib/aes/aeskey.c
lib/aes/aestab.c
lib/aes/aes_ni.c)
set(BRG_AES_HDR
lib/aes/aes.h
lib/aes/aesopt.h
lib/aes/aestab.h
lib/aes/aes_ni.h)
set(BRG_SHA_SRC
lib/sha/hmac.c
lib/sha/sha1.c
lib/sha/sha2.c)
set(BRG_SHA_HDR
lib/sha/brg_endian.h
lib/sha/brg_types.h
lib/sha/hmac.h
lib/sha/sha1.h
lib/sha/sha2.h)
add_library(aes STATIC ${BRG_AES_SRC} ${BRG_AES_HDR})
add_library(sha STATIC ${BRG_SHA_SRC} ${BRG_SHA_HDR})
# Check to see which random generation functions we have
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
if(HAVE_GETRANDOM)
list(APPEND MINIZIP_DEF -DHAVE_GETRANDOM)
endif()
check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF)
if(HAVE_ARC4RANDOM_BUF)
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM_BUF)
else()
check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM)
if(HAVE_ARC4RANDOM)
list(APPEND MINIZIP_DEF -DHAVE_ARC4RANDOM)
endif()
endif()
if(APPLE)
# Requires _DARWIN_C_SOURCE for arcrandom functions
list(APPEND MINIZIP_DEF -D_DARWIN_C_SOURCE)
endif()
if(MZ_LIBBSD AND NOT HAVE_ARC4RANDOM_BUF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBBSD libbsd)
if(LIBBSD_FOUND)
check_library_exists("${LIBBSD_LIBRARIES}" "arc4random_buf"
"${LIBBSD_LIBRARY_DIRS}" HAVE_LIBBSD_ARC4RANDOM_BUF)
if(HAVE_LIBBSD_ARC4RANDOM_BUF)
list(APPEND MINIZIP_DEF -DHAVE_LIBBSD -DHAVE_ARC4RANDOM_BUF)
list(APPEND MINIZIP_INC ${LIBBSD_INCLUDE_DIRS})
list(APPEND MINIZIP_LIB ${LIBBSD_LIBRARIES})
list(APPEND MINIZIP_LBD ${LIBBSD_LIBRARY_DIRS})
link_directories(${LIBBSD_LIBRARY_DIRS})
endif()
else()
set(MZ_LIBBSD FALSE)
endif()
else()
set(MZ_LIBBSD FALSE)
endif()
list(APPEND MINIZIP_SRC mz_crypt_brg.c)
list(APPEND MINIZIP_INC lib/aes lib/sha)
list(APPEND MINIZIP_DEP aes sha)
endif()
# Include compatibility layer
if(MZ_COMPAT)
set(COMPAT_HEADER "\
/* file.h -- Compatibility layer shim\n\
part of the MiniZip project\n\n\
part of the minizip-ng project\n\n\
This program is distributed under the terms of the same license as zlib.\n\
See the accompanying LICENSE file for the full text of the license.\n\
*/\n\n\
@ -724,7 +771,7 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
endif()
# Build test executables
if(MZ_BUILD_TEST)
if(MZ_BUILD_TESTS)
if(MZ_ZLIB AND NOT MZ_LIBCOMP)
add_executable(minigzip_cmd minigzip.c)
set_target_properties(minigzip_cmd PROPERTIES OUTPUT_NAME minigzip)
@ -759,7 +806,7 @@ if(MZ_BUILD_TEST)
ENDIF(0) # rom-properties
endif()
if(MZ_BUILD_TEST AND MZ_BUILD_UNIT_TEST)
if(MZ_BUILD_TESTS AND MZ_BUILD_UNIT_TESTS)
enable_testing()
# Can't disable zlib testing so ctest tries to run zlib example app
@ -899,7 +946,7 @@ if(MZ_BUILD_TEST AND MZ_BUILD_UNIT_TEST)
endif()
#Build fuzzer executables
if(MZ_BUILD_FUZZ_TEST)
if(MZ_BUILD_FUZZ_TESTS)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
enable_language(CXX)
@ -941,28 +988,33 @@ endif()
# rom-properties: Disabled FeatureSummary.
IF(0)
# Compatibility options
add_feature_info(MZ_COMPAT MZ_COMPAT "Enables compatibility layer")
# Compression library options
add_feature_info(MZ_ZLIB MZ_ZLIB "Enables ZLIB compression")
add_feature_info(MZ_BZIP2 MZ_BZIP2 "Enables BZIP2 compression")
add_feature_info(MZ_LZMA MZ_LZMA "Enables LZMA & XZ compression")
add_feature_info(MZ_ZSTD MZ_ZSTD "Enables ZSTD compression")
add_feature_info(MZ_LIBCOMP MZ_LIBCOMP "Enables Apple compression")
add_feature_info(MZ_FETCH_LIBS MZ_FETCH_LIBS "Enables fetching third-party libraries if not found")
add_feature_info(MZ_FORCE_FETCH_LIBS MZ_FORCE_FETCH_LIBS "Enables fetching third-party libraries always")
# Encryption support options
add_feature_info(MZ_PKCRYPT MZ_PKCRYPT "Enables PKWARE traditional encryption")
add_feature_info(MZ_WZAES MZ_WZAES "Enables WinZIP AES encryption")
add_feature_info(MZ_LIBCOMP MZ_LIBCOMP "Enables Apple compression")
add_feature_info(MZ_OPENSSL MZ_OPENSSL "Enables OpenSSL for encryption")
add_feature_info(MZ_LIBBSD MZ_LIBBSD "Build with libbsd for crypto random")
add_feature_info(MZ_BRG MZ_BRG "Enables Brian Gladman's encryption library")
add_feature_info(MZ_ICONV MZ_ICONV "Enables iconv string encoding conversion library")
add_feature_info(MZ_SIGNING MZ_SIGNING "Enables zip signing support")
# Character conversion options
add_feature_info(MZ_ICONV MZ_ICONV "Enables iconv string encoding conversion library")
# Code generation options
add_feature_info(MZ_COMPRESS_ONLY MZ_COMPRESS_ONLY "Only support compression")
add_feature_info(MZ_DECOMPRESS_ONLY MZ_DECOMPRESS_ONLY "Only support decompression")
add_feature_info(MZ_BUILD_TEST MZ_BUILD_TEST "Builds minizip test executable")
add_feature_info(MZ_BUILD_UNIT_TEST MZ_BUILD_UNIT_TEST "Builds minizip unit test project")
add_feature_info(MZ_BUILD_FUZZ_TEST MZ_BUILD_FUZZ_TEST "Builds minizip fuzzer executables")
add_feature_info(MZ_CODE_COVERAGE MZ_CODE_COVERAGE "Builds with code coverage flags")
add_feature_info(MZ_FILE32_API MZ_FILE32_API "Builds using posix 32-bit file api")
# Build and continuous integration options
add_feature_info(MZ_BUILD_TESTS MZ_BUILD_TESTS "Builds minizip test executable")
add_feature_info(MZ_BUILD_UNIT_TESTS MZ_BUILD_UNIT_TESTS "Builds minizip unit test project")
add_feature_info(MZ_BUILD_FUZZ_TESTS MZ_BUILD_FUZZ_TESTS "Builds minizip fuzzer executables")
add_feature_info(MZ_CODE_COVERAGE MZ_CODE_COVERAGE "Builds with code coverage flags")
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES INCLUDE_QUIET_PACKAGES)
ENDIF(0) # rom-properties

View File

@ -1,12 +1,11 @@
# minizip 2.10.5
# minizip-ng 3.0.0
minizip is a zip manipulation library written in C that is supported on Windows, macOS, and Linux.
minizip-ng is a zip manipulation library written in C that is supported on Windows, macOS, and Linux.
[![Master Branch Status](https://github.com/nmoinvaz/minizip/workflows/CI/badge.svg)](https://github.com/nmoinvaz/minizip/actions)
[![Master Branch Status](https://github.com/zlib-ng/minizip-ng/workflows/CI/badge.svg)](https://github.com/zlib-ng/minizip-ng/actions)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/minizip.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:minizip)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/53d48ca8fec549f4a8b39cf95cba6ad6)](https://www.codacy.com/manual/nmoinvaz/minizip?utm_source=github.com&utm_medium=referral&utm_content=nmoinvaz/minizip&utm_campaign=Badge_Grade)
[![CodeFactor](https://www.codefactor.io/repository/github/nmoinvaz/minizip/badge)](https://www.codefactor.io/repository/github/nmoinvaz/minizip)
[![License: Zlib](https://img.shields.io/badge/license-zlib-lightgrey.svg)](https://github.com/nmoinvaz/minizip/blob/master/LICENSE)
[![License: Zlib](https://img.shields.io/badge/license-zlib-lightgrey.svg)](https://github.com/zlib-ng/minizip-ng/blob/master/LICENSE)
[![codecov.io](https://codecov.io/github/nmoinvaz/minizip/coverage.svg?branch=dev)](https://codecov.io/github/nmoinvaz/minizip/)
Developed and maintained by Nathan Moinvaziri.
@ -15,20 +14,17 @@ Developed and maintained by Nathan Moinvaziri.
|Name|Description|
|:-|:-|
|[master](https://github.com/nmoinvaz/minizip/tree/master)|Modern rewrite that includes more advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. Compatibility layer provided for older versions.|
|[dev](https://github.com/nmoinvaz/minizip/tree/dev)|Latest development code|
|[1.2](https://github.com/nmoinvaz/minizip/tree/1.2)|Drop-in replacement for zlib's minizip that includes WinZip AES encryption, disk splitting, I/O buffering and some additional fixes.|
|[1.1](https://github.com/nmoinvaz/minizip/tree/1.1)|Original minizip as of zlib 1.2.11.|
|[master](https://github.com/zlib-ng/minizip-ng/tree/master)|Most recent release.|
|[dev](https://github.com/zlib-ng/minizip-ng/tree/dev)|Latest development code.|
|[1.2](https://github.com/zlib-ng/minizip-ng/tree/1.2)|Old changes to original minizip that includes WinZip AES encryption, disk splitting, I/O buffering and some additional fixes. Not ABI compatible with original minizip.|
|[1.1](https://github.com/zlib-ng/minizip-ng/tree/1.1)|Original minizip as of zlib 1.2.11.|
## History
Minizip was originally developed by [Gilles Vollant](https://www.winimage.com/zLibDll/minizip.html) in 1998. It was first included in the zlib distribution as an additional code contribution starting in zlib 1.1.2. Since that time, it has been continually improved upon and contributed to by many people. The original [project](https://github.com/madler/zlib/tree/master/contrib/minizip) can still be found in the zlib distribution that is maintained by Mark Adler.
My work with the minizip library started in 2006 when I fixed a few bugs I found and submitted them to
Gilles Vollant. In 2010, I implemented WinZip AES encryption, disk splitting, and
I/O buffering that were necessary for another project I was working on. Shortly after, I created this public repository
so I could share my improvements with the community. In early 2017, I began the work to refactor and rewrite
the library as version 2 because it had become difficult to maintain and code readability suffered over the years.
The motivation behind this repository has been the need for new features and bug fixes to the original library which had
not been maintained for a long period of time. The code has been largely refactored and rewritten in order to help improve maintainability and readability. A compatibility layer has been provided for consumers of the original minizip library.
## Features
@ -76,37 +72,34 @@ cmake --build .
| MZ_BZIP2 | Enables BZIP2 compression | ON |
| MZ_LZMA | Enables LZMA & XZ compression | ON |
| MZ_ZSTD | Enables ZSTD compression | ON |
| MZ_FETCH_LIBS | Enables fetching third-party libraries if not found | ON |
| MZ_LIBCOMP | Enables Apple compression | APPLE |
| MZ_FETCH_LIBS | Enables fetching third-party libraries if not found | WIN32 |
| MZ_FORCE_FETCH_LIBS | Enables fetching third-party libraries always | OFF |
| MZ_PKCRYPT | Enables PKWARE traditional encryption | ON |
| MZ_WZAES | Enables WinZIP AES encryption | ON |
| MZ_LIBCOMP | Enables Apple compression | OFF |
| MZ_OPENSSL | Enables OpenSSL encryption | OFF |
| MZ_LIBBSD | Builds with libbsd crypto random | ON |
| MZ_BRG | Enables Brian Gladman's library | OFF |
| MZ_ICONV | Enables iconv encoding conversion | ON |
| MZ_OPENSSL | Enables OpenSSL encryption | UNIX |
| MZ_LIBBSD | Builds with libbsd crypto random | UNIX |
| MZ_SIGNING | Enables zip signing support | ON |
| MZ_ICONV | Enables iconv encoding conversion | ON |
| MZ_COMPRESS_ONLY | Only support compression | OFF |
| MZ_DECOMPRESS_ONLY | Only support decompression | OFF |
| MZ_BUILD_TEST | Builds minizip test executable | OFF |
| MZ_BUILD_UNIT_TEST | Builds minizip unit test project | OFF |
| MZ_BUILD_FUZZ_TEST | Builds minizip fuzz executables | OFF |
| MZ_FILE32_API | Builds using posix 32-bit file api | OFF |
| MZ_BUILD_TESTS | Builds minizip test executable | OFF |
| MZ_BUILD_UNIT_TESTS | Builds minizip unit test project | OFF |
| MZ_BUILD_FUZZ_TESTS | Builds minizip fuzz executables | OFF |
| MZ_CODE_COVERAGE | Build with code coverage flags | OFF |
| MZ_PROJECT_SUFFIX | Project name suffix for packaging | |
| MZ_FILE32_API | Builds using posix 32-bit file api | OFF |
## Third-Party Libraries
Third-party libraries may be required based on the CMake options selected. If the system already has the library
installed then it will be used, otherwise CMake will retrieve the source code for the library from its official git repository and compile it in.
installed then it will be used, otherwise CMake will retrieve the source code for the library from its official git repository and compile it in when the `MZ_FETCH_LIBS` option is enabled.
|Project|License|CMake Option|Comments|
|-|-|-|-|
|[aes](https://github.com/BrianGladman/aes)|[license](https://github.com/BrianGladman/aes/blob/master/license.txt)|`MZ_BRG`|Written by Brian Gladman.|
[bzip2](https://www.sourceware.org/bzip2/)|[license](https://github.com/nmoinvaz/minizip/blob/dev/lib/bzip2/LICENSE)|`MZ_BZIP2`|Written by Julian Seward.|
[bzip2](https://www.sourceware.org/bzip2/)|[license](https://github.com/zlib-ng/minizip-ng/blob/dev/lib/bzip2/LICENSE)|`MZ_BZIP2`|Written by Julian Seward.|
|[liblzma](https://tukaani.org/xz/)|Public domain|`MZ_LZMA`|Written by Igor Pavlov and Lasse Collin.|
|[sha](https://github.com/BrianGladman/sha)|[license](https://github.com/BrianGladman/aes/blob/master/license.txt)|`MZ_BRG`|Written by Brian Gladman.|
|[zlib](https://zlib.net/)|zlib|`MZ_ZLIB`|Written by Mark Adler and Jean-loup Gailly. Or alternatively, [zlib-ng](https://github.com/Dead2/zlib-ng) by Hans Kristian Rosbach.|
|[zlib](https://zlib.net/)|zlib|`MZ_ZLIB`|Written by Mark Adler and Jean-loup Gailly. Or alternatively, [zlib-ng](https://github.com/zlib-ng/zlib-ng) by Hans Kristian Rosbach.|
|[zstd](https://github.com/facebook/zstd)|[BSD](https://github.com/facebook/zstd/blob/dev/LICENSE)|`MZ_ZSTD`|Written by Facebook.|
This project uses the zlib [license](LICENSE).
@ -117,4 +110,4 @@ Thanks go out to all the people who have taken the time to contribute code revie
Thanks to [Gilles Vollant](https://www.winimage.com/zLibDll/minizip.html) on which this work is originally based on.
The [ZIP format](https://github.com/nmoinvaz/minizip/blob/master/doc/zip/appnote.txt) was defined by Phil Katz of PKWARE.
The [ZIP format](https://github.com/zlib-ng/minizip-ng/blob/master/doc/zip/appnote.txt) was defined by Phil Katz of PKWARE.

View File

@ -1,10 +1,9 @@
This copy of minizip is based on the updated version maintained
by Nathan Moinvaziri at https://github.com/nmoinvaz/minizip .
This copy of minizip-ng 2.0.0 is a modified version of the original.
commit 123c49e94edd144d6ec2d1fc29fc2f4ee8de6a07
Version 2.10.5
commit 6f17da582d2327c8cdc43622ddd31a185b6ef5fb
Version 3.0.0.
Tag: 2.10.5
Tag: 3.0.0
The following changes have been made to the original:
@ -19,8 +18,8 @@ The following changes have been made to the original:
- Some other functionality not needed by rom-properties has been disabled.
To obtain the original minizip-ng 2.0.0, visit:
https://github.com/zlib-ng/minizip-ng
To obtain the original minizip-1.1, visit:
http://www.winimage.com/zLibDll/minizip.html
To obtain the original updated version, visit:
https://github.com/nmoinvaz/minizip

View File

@ -1,4 +1,4 @@
# Minizip Documentation <!-- omit in toc -->
# minizip-ng Documentation <!-- omit in toc -->
### Table of Contents
@ -117,7 +117,7 @@ instance, some #defines will have to be set as they have changed.
||MZ_ZIP_NO_COMPRESSION|Intended to reduce compilation size if not using zipping functionality.|
||MZ_ZIP_NO_COMPRESSION|Intended to reduce compilation size if not using zipping functionality.|
At a minimum HAVE_ZLIB and HAVE_PKCRYPT will be necessary to be defined for drop-in replacement. To determine which files to drop in, see the Contents section of the [README](https://github.com/nmoinvaz/minizip/blob/master/README.md).
At a minimum HAVE_ZLIB and HAVE_PKCRYPT will be necessary to be defined for drop-in replacement. To determine which files to drop in, see the Contents section of the [README](https://github.com/zlib-ng/minizip-ng/blob/master/README.md).
The compatibility layer for 1.x does not currently provide support for the `ioapi` interface; it has been replaced with a new streaming interface. It is possible to create a stream interface in a similar way that you would have created an ioapi interface.
@ -125,7 +125,7 @@ The compatibility layer for 1.x does not currently provide support for the `ioap
### WinZip AES <!-- omit in toc -->
When compressing an archive with WinZIP AES enabled, by default it uses 256 bit encryption. During decompression minizip will use whatever bit encryption was specified when the entry was added to the archive.
When compressing an archive with WinZIP AES enabled, by default it uses 256 bit encryption. During decompression whatever bit encryption was specified when the entry was added to the archive will be used.
WinZip AES encryption uses CTR on top of ECB which prevents identical ciphertext blocks that might occur when using ECB by itself. More details about the WinZIP AES format can be found in the [winzip documentation](zip/winzip_aes.md).

View File

@ -1,6 +1,6 @@
# MZ_COMPRESS_LEVEL
Minizip compression level enumeration.
Compression level enumeration.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_COMPRESS_METHOD
Minizip compression method enumeration.
Compression method enumeration.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_ENCODING
Minizip character encoding enumeration. Older zip files may store the filename in a different character encoding.
Character encoding enumeration. Older zip files may store the filename in a different character encoding.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_ERROR
Minizip error enumeration. These errors codes are compatible with and extend zlib error codes.
Error code enumeration. These errors codes are compatible with and extend zlib error codes.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_HASH
Minizip hash algorithm enumeration. The _mz_zip_reader_ and _mz_zip_writer_ instances support storing more secure hash algorithms for each zip entry.
Hash algorithm enumeration. The _mz_zip_reader_ and _mz_zip_writer_ instances support storing more secure hash algorithms for each zip entry.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_HOST_SYSTEM
Minizip host system enumeration. These values correspond to section 4.4.2.2 of the [PKWARE zip app note](zip/appnote.txt).
Host system enumeration. These values correspond to section 4.4.2.2 of the [PKWARE zip app note](zip/appnote.txt).
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_OPEN
Minizip stream open flag enumeration.
Stream open flag enumeration.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_SEEK
Minizip stream seek origin enumeration.
Stream seek origin enumeration.
|Name|Code|Description|
|-|-|-|

View File

@ -28,6 +28,7 @@ The _mz_zip_ object allows for the reading and writing of the a zip file and its
- [mz_zip_entry_write_open](#mz_zip_entry_write_open)
- [mz_zip_entry_write](#mz_zip_entry_write)
- [mz_zip_entry_write_close](#mz_zip_entry_write_close)
- [mz_zip_entry_seek_local_header](#mz_zip_entry_seek_local_header)
- [mz_zip_entry_close_raw](#mz_zip_entry_close_raw)
- [mz_zip_entry_close](#mz_zip_entry_close)
- [Entry Enumeration](#entry-enumeration)
@ -508,7 +509,7 @@ if (mz_zip_entry_is_open(zip_handle) == MZ_OK)
Opens for reading the current entry in the zip file. To navigate to an entry use _mz_zip_goto_first_entry_, _mz_zip_goto_next_entry_, or _mz_zip_locate_entry_.
Normally, when reading from a zip entry, the minizip library will automatically decrypt and decompress the entry data. To read the raw zip entry data, set the raw parameter to 1. This is useful if you want access to the raw gzip data (assuming the entry is gzip compressed).
Normally, when reading from a zip entry, the data will be automatically decrypted and decompressed. To read the raw zip entry data, set the raw parameter to 1. This is useful if you want access to the raw gzip data (assuming the entry is gzip compressed).
**Arguments**
|Type|Name|Description|
@ -695,6 +696,32 @@ if (err == MZ_OK)
printf("Zip file entry closed for writing\n");
```
### mz_zip_entry_seek_local_header
Seeks to the local header for the entry.
**Arguments**
|Type|Name|Description|
|-|-|-|
|void *|handle|_mz_zip_ instance|
**Return**
|Type|Description|
|-|-|
|int32_t|[MZ_ERROR](mz_error.md) code, MZ_OK if successful.|
**Example**
```
int32_t err = mz_zip_goto_first_entry(zip_handle);
if (err == MZ_OK)
err = mz_zip_entry_seek_local_header(zip_handle);
if (err == MZ_OK) {
void *stream = NULL;
mz_zip_get_stream(zip_handle, &stream);
int64_t position = mz_stream_tell(stream);
printf("Position of local header of first entry: %lld\n", position);
}
```
### mz_zip_entry_close_raw
Closes the current entry in the zip file. To be used to close an entry that has been opened for reading or writing in raw mode.
@ -1227,6 +1254,7 @@ Seeks using a _mz_stream_ to an extra field by its type and returns its length.
|-|-|-|
|void *|stream|_mz_stream_ instance|
|uint16_t|type|Extra field type indentifier (See [PKWARE zip app note](zip/appnote.iz.txt) section 4.5.2)|
|int32_t|max_seek|Maximum length to search for extrafield|
|uint16_t *|length|Pointer to extra field length|
**Return**
@ -1246,7 +1274,7 @@ mz_stream_mem_create(&file_extra_stream);
mz_stream_mem_set_buffer(file_extra_stream, (void *)file_info->extrafield,
file_info->extrafield_size);
if (mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_AES, &extrafield_length) == MZ_OK)
if (mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_AES, INT32_MAX, &extrafield_length) == MZ_OK)
printf("Found AES extra field, length %d\n", extrafield_length);
else
printf("Unable to find AES extra field in zip entry\n");

View File

@ -1,6 +1,6 @@
# MZ_ZIP64
Minizip zip64 mode enumeration. The zip64 extension is documented in [PKWARE zip app note](zip/appnote.txt) section 4.5.3 and provides support for zip files and entries greater than 4GB. These modes are only supported while writing a zip entry.
Zip64 mode enumeration. The zip64 extension is documented in [PKWARE zip app note](zip/appnote.txt) section 4.5.3 and provides support for zip files and entries greater than 4GB. These modes are only supported while writing a zip entry.
|Name|Code|Description|
|-|-|-|

View File

@ -1,6 +1,6 @@
# MZ_ZIP_FILE
Minizip zip entry information structure. The _mz_zip_file_ structure is populated when reading zip entry information and can be used to populate zip entry information when writing zip entries.
Zip entry information structure. The _mz_zip_file_ structure is populated when reading zip entry information and can be used to populate zip entry information when writing zip entries.
|Type|Name|Description|[PKWARE zip app note](zip/appnote.txt) section|
|-|-|-|-|

View File

@ -1331,6 +1331,7 @@ if (mz_zip_writer_is_open(zip_writer) == MZ_OK)
|-|-|-|
|void *|handle|_mz_zip_writer_ instance|
|void *|stream|_mz_stream_ instance|
|uint8_t|append|Opens in append mode if 1|
**Return**
|Type|Description|
@ -1345,9 +1346,9 @@ const char *path = "c:\\my.zip";
mz_zip_writer_create(&zip_writer);
mz_stream_os_create(&file_stream);
err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_READ);
err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_WRITE | MZ_OPEN_MODE_CREATE);
if (err == MZ_OK) {
err = mz_zip_writer_open(zip_writer, file_stream);
err = mz_zip_writer_open(zip_writer, file_stream, 0);
if (err == MZ_OK) {
printf("Zip writer was opened %s\n", path);
mz_zip_writer_close(zip_writer);

View File

@ -1,8 +1,8 @@
/* minigzip.c
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -28,7 +28,7 @@ int32_t minigzip_help(void);
/***************************************************************************/
int32_t minigzip_banner(void) {
printf("Minigzip %s - https://github.com/nmoinvaz/minizip\n", MZ_VERSION);
printf("Minigzip %s - https://github.com/zlib-ng/minizip-ng\n", MZ_VERSION);
printf("---------------------------------------------------\n");
return MZ_OK;
}
@ -125,12 +125,7 @@ int32_t minigzip_copy(const char *path, const char *destination, int16_t operati
/***************************************************************************/
#if !defined(MZ_ZIP_NO_MAIN)
# ifdef _MSC_VER
# define MZ_C_API __cdecl
# else
# define MZ_C_API
# endif
int MZ_C_API main(int argc, const char *argv[]) {
int main(int argc, const char *argv[]) {
int16_t operation_level = MZ_COMPRESS_LEVEL_DEFAULT;
int32_t path_arg = 0;
int32_t err = 0;

View File

@ -1,8 +1,8 @@
/* minizip.c
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2010 Gilles Vollant
https://www.winimage.com/zLibDll/minizip.html
@ -62,7 +62,7 @@ int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg
/***************************************************************************/
int32_t minizip_banner(void) {
printf("Minizip %s - https://github.com/nmoinvaz/minizip\n", MZ_VERSION);
printf("minizip-ng %s - https://github.com/zlib-ng/minizip-ng\n", MZ_VERSION);
printf("---------------------------------------------------\n");
return MZ_OK;
}

View File

@ -1,8 +1,8 @@
/* mz.h -- Errors codes, zip flags and magic
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -14,8 +14,8 @@
/***************************************************************************/
/* MZ_VERSION */
#define MZ_VERSION ("2.10.5")
#define MZ_VERSION_BUILD (21005)
#define MZ_VERSION ("3.0.0")
#define MZ_VERSION_BUILD (030000)
/* MZ_ERROR */
#define MZ_OK (0) /* zlib */

View File

@ -1,8 +1,8 @@
/* mz_compat.c -- Backwards compatible interface for older versions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2010 Gilles Vollant
https://www.winimage.com/zLibDll/minizip.html

View File

@ -1,8 +1,8 @@
/* mz_compat.h -- Backwards compatible interface for older versions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2010 Gilles Vollant
https://www.winimage.com/zLibDll/minizip.html

View File

@ -1,8 +1,8 @@
/* mz_crypt.c -- Crypto/hash functions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -10,6 +10,7 @@
#include "mz.h"
#include "mz_os.h"
#include "mz_crypt.h"
#if defined(HAVE_ZLIB)
@ -40,6 +41,12 @@
/***************************************************************************/
#if defined(MZ_ZIP_NO_CRYPTO)
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
return mz_os_rand(buf, size);
}
#endif
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size) {
#if defined(HAVE_ZLIB)
return (uint32_t)ZLIB_PREFIX(crc32)((z_crc_t)value, buf, (uInt)size);
@ -104,7 +111,7 @@ uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size)
#endif
}
#ifndef MZ_ZIP_NO_ENCRYPTION
#if defined(HAVE_WZAES)
int32_t mz_crypt_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length) {
void *hmac1 = NULL;

View File

@ -1,8 +1,8 @@
/* mz_crypt.h -- Crypto/hash functions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_crypt_apple.c -- Crypto/hash functions for Apple
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_crypt_openssl.c -- Crypto/hash functions for OpenSSL
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,17 +1,13 @@
/* mz_crypt_win32.c -- Crypto/hash functions for Windows
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifdef _MSC_VER
#pragma comment(lib, "crypt32.lib")
#endif
#include "mz.h"
#include "mz_os.h"
#include "mz_crypt.h"

View File

@ -1,8 +1,8 @@
/* mz_os.c -- System functions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2010 Gilles Vollant
https://www.winimage.com/zLibDll/minizip.html

View File

@ -1,8 +1,8 @@
/* mz_os.h -- System functions
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_os_posix.c -- System functions for posix
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -30,6 +30,17 @@
# include <mach/mach.h>
#endif
#if defined(HAVE_GETRANDOM)
# include <sys/random.h>
#endif
#if defined(HAVE_LIBBSD)
# include <sys/types.h>
# ifndef __u_char_defined
typedef unsigned char u_char;
# endif
# include <bsd/stdlib.h> /* arc4random_buf */
#endif
/***************************************************************************/
#if defined(HAVE_ICONV)
@ -106,6 +117,44 @@ void mz_os_utf8_string_delete(uint8_t **string) {
/***************************************************************************/
#if defined(HAVE_ARC4RANDOM_BUF)
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
if (size < 0)
return 0;
arc4random_buf(buf, (uint32_t)size);
return size;
}
#elif defined(HAVE_ARC4RANDOM)
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
int32_t left = size;
for (; left > 2; left -= 3, buf += 3) {
uint32_t val = arc4random();
buf[0] = (val) & 0xFF;
buf[1] = (val >> 8) & 0xFF;
buf[2] = (val >> 16) & 0xFF;
}
for (; left > 0; left--, buf++) {
*buf = arc4random() & 0xFF;
}
return size - left;
}
#elif defined(HAVE_GETRANDOM)
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
int32_t left = size;
int32_t written = 0;
while (left > 0) {
written = getrandom(buf, left, 0);
if (written < 0)
return MZ_INTERNAL_ERROR;
buf += written;
left -= written;
}
return size - left;
}
#else
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
static unsigned calls = 0;
int32_t i = 0;
@ -121,6 +170,7 @@ int32_t mz_os_rand(uint8_t *buf, int32_t size) {
return size;
}
#endif
int32_t mz_os_rename(const char *source_path, const char *target_path) {
if (rename(source_path, target_path) == -1)

View File

@ -1,8 +1,8 @@
/* mz_os_win32.c -- System functions for Windows
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm.c -- Stream interface
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm.h -- Stream interface
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,10 +1,10 @@
/* mz_strm_buf.c -- Stream for buffering reads/writes
part of the MiniZip project
part of the minizip-ng project
This version of ioapi is designed to buffer IO.
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -123,12 +123,17 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size) {
int32_t bytes_to_copy = 0;
int32_t bytes_left_to_read = size;
int32_t bytes_read = 0;
int32_t bytes_flushed = 0;
mz_stream_buffered_print("Buffered - Read (size %" PRId32 " pos %" PRId64 ")\n", size, buffered->position);
if (buffered->writebuf_len > 0) {
mz_stream_buffered_print("Buffered - Switch from write to read, not yet supported (pos %" PRId64 ")\n",
buffered->position);
int64_t position = buffered->position + buffered->writebuf_pos
mz_stream_buffered_print("Buffered - Switch from write to read, flushing (pos %" PRId64 ")\n", position);
mz_stream_buffered_flush(stream, &bytes_flushed);
mz_stream_buffered_seek(stream, position, MZ_SEEK_SET);
}
while (bytes_left_to_read > 0) {
@ -264,6 +269,11 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin) {
switch (origin) {
case MZ_SEEK_SET:
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
(offset >= buffered->position - buffered->readbuf_len)) {
buffered->readbuf_pos = (int32_t)(offset - (buffered->position - buffered->readbuf_len));
return MZ_OK;
}
if (buffered->writebuf_len > 0) {
if ((offset >= buffered->position) && (offset <= buffered->position + buffered->writebuf_len)) {
buffered->writebuf_pos = (int32_t)(offset - buffered->position);
@ -271,12 +281,6 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin) {
}
}
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
(offset >= buffered->position - buffered->readbuf_len)) {
buffered->readbuf_pos = (int32_t)(offset - (buffered->position - buffered->readbuf_len));
return MZ_OK;
}
err = mz_stream_buffered_flush(stream, &bytes_flushed);
if (err != MZ_OK)
return err;

View File

@ -1,10 +1,10 @@
/* mz_strm_buf.h -- Stream for buffering reads/writes
part of the MiniZip project
part of the minizip-ng project
This version of ioapi is designed to buffer IO.
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_libcomp.c -- Stream for apple compression
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -85,7 +85,7 @@ int32_t mz_stream_libcomp_open(void *stream, const char *path, int32_t mode) {
algorithm = COMPRESSION_LZMA;
else
return MZ_SUPPORT_ERROR;
err = compression_stream_init(&libcomp->cstream, (compression_stream_operation)operation, algorithm);
if (err == COMPRESSION_STATUS_ERROR) {
@ -354,38 +354,3 @@ void mz_stream_libcomp_delete(void **stream) {
MZ_FREE(libcomp);
*stream = NULL;
}
/***************************************************************************/
static mz_stream_vtbl mz_stream_zlib_vtbl = {
mz_stream_libcomp_open,
mz_stream_libcomp_is_open,
mz_stream_libcomp_read,
mz_stream_libcomp_write,
mz_stream_libcomp_tell,
mz_stream_libcomp_seek,
mz_stream_libcomp_close,
mz_stream_libcomp_error,
mz_stream_zlib_create,
mz_stream_libcomp_delete,
mz_stream_libcomp_get_prop_int64,
mz_stream_libcomp_set_prop_int64
};
void *mz_stream_zlib_create(void **stream) {
mz_stream_libcomp *libcomp = NULL;
void *stream_int = NULL;
mz_stream_libcomp_create(&stream_int);
if (stream_int != NULL) {
libcomp = (mz_stream_libcomp *)stream_int;
libcomp->stream.vtbl = &mz_stream_zlib_vtbl;
libcomp->method = MZ_COMPRESS_METHOD_DEFLATE;
}
if (stream != NULL)
*stream = stream_int;
return stream_int;
}
void *mz_stream_zlib_get_interface(void) {
return (void *)&mz_stream_zlib_vtbl;
}

View File

@ -1,8 +1,8 @@
/* mz_strm_libcomp.h -- Stream for apple compression
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -35,27 +35,6 @@ void* mz_stream_libcomp_create(void **stream);
void mz_stream_libcomp_delete(void **stream);
void* mz_stream_libcomp_get_interface(void);
void* mz_stream_libcomp_get_crc32_update(void);
/***************************************************************************/
int32_t mz_stream_zlib_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_zlib_is_open(void *stream);
int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_zlib_tell(void *stream);
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_zlib_close(void *stream);
int32_t mz_stream_zlib_error(void *stream);
int32_t mz_stream_zlib_get_prop_int64(void *stream, int32_t prop, int64_t *value);
int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value);
void* mz_stream_zlib_create(void **stream);
void mz_stream_zlib_delete(void **stream);
void* mz_stream_zlib_get_interface(void);
void* mz_stream_zlib_get_crc32_update(void);
/***************************************************************************/

View File

@ -1,8 +1,8 @@
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as lzma.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,13 +1,13 @@
/* mz_strm_mem.c -- Stream for memory access
part of the MiniZip project
part of the minizip-ng project
This interface is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of.
Based on Unzip ioapi.c version 0.22, May 19th, 2003
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
https://www.winimage.com/zLibDll/minizip.html

View File

@ -1,8 +1,8 @@
/* mz_strm_mem.h -- Stream for memory access
part of MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_sstrm_os.h -- Stream for filesystem access
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com

View File

@ -1,8 +1,8 @@
/* mz_strm_win32.c -- Stream for filesystem access for windows
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com

View File

@ -1,8 +1,8 @@
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
https://www.winimage.com/zLibDll/minizip.html
@ -138,12 +138,6 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode) {
mz_stream_pkcrypt_init_keys(stream, password);
if (mode & MZ_OPEN_MODE_WRITE) {
#ifdef MZ_ZIP_NO_COMPRESSION
MZ_UNUSED(t);
MZ_UNUSED(i);
return MZ_SUPPORT_ERROR;
#else
/* First generate RAND_HEAD_LEN - 2 random bytes. */
mz_crypt_rand(header, MZ_PKCRYPT_HEADER_SIZE - 2);
@ -158,16 +152,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode) {
return MZ_WRITE_ERROR;
pkcrypt->total_out += MZ_PKCRYPT_HEADER_SIZE;
#endif
} else if (mode & MZ_OPEN_MODE_READ) {
#ifdef MZ_ZIP_NO_DECOMPRESSION
MZ_UNUSED(t);
MZ_UNUSED(i);
MZ_UNUSED(verify1);
MZ_UNUSED(verify2);
return MZ_SUPPORT_ERROR;
#else
if (mz_stream_read(pkcrypt->stream.base, header, sizeof(header)) != sizeof(header))
return MZ_READ_ERROR;
@ -183,7 +168,6 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode) {
return MZ_PASSWORD_ERROR;
pkcrypt->total_in += MZ_PKCRYPT_HEADER_SIZE;
#endif
}
pkcrypt->initialized = 1;

View File

@ -1,8 +1,8 @@
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_split.c -- Stream for split files
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_split.h -- Stream for split files
part of MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_wzaes.c -- Stream for WinZip AES encryption
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 1998-2010 Brian Gladman, Worcester, UK
This program is distributed under the terms of the same license as zlib.
@ -95,18 +95,10 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode) {
salt_length = MZ_AES_SALT_LENGTH(wzaes->encryption_mode);
if (mode & MZ_OPEN_MODE_WRITE) {
#ifdef MZ_ZIP_NO_COMPRESSION
return MZ_SUPPORT_ERROR;
#else
mz_crypt_rand(salt_value, salt_length);
#endif
} else if (mode & MZ_OPEN_MODE_READ) {
#ifdef MZ_ZIP_NO_DECOMPRESSION
return MZ_SUPPORT_ERROR;
#else
if (mz_stream_read(wzaes->stream.base, salt_value, salt_length) != salt_length)
return MZ_READ_ERROR;
#endif
}
key_length = MZ_AES_KEY_LENGTH(wzaes->encryption_mode);

View File

@ -1,8 +1,8 @@
/* mz_strm_wzaes.h -- Stream for WinZIP AES encryption
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* mz_strm_zstd.c -- Stream for zstd compress/decompress
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Authors: Force Charlie
https://github.com/fcharlie
@ -65,9 +65,6 @@ int32_t mz_stream_zstd_open(void *stream, const char *path, int32_t mode) {
return MZ_SUPPORT_ERROR;
#else
zstd->zcstream = ZSTD_createCStream();
// rom-properties: Force max compression.
// TODO: Map the 0-9 value from minizip.
ZSTD_initCStream(zstd->zcstream, ZSTD_maxCLevel());
zstd->out.dst = zstd->buffer;
zstd->out.size = sizeof(zstd->buffer);
zstd->out.pos = 0;

View File

@ -1,9 +1,9 @@
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
Version 2.9.2, February 12, 2020
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.

View File

@ -1,8 +1,8 @@
/* zip.c -- Zip manipulation
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
@ -73,6 +73,7 @@
#define MZ_ZIP_SIZE_MAX_DATA_DESCRIPTOR (24)
#define MZ_ZIP_OFFSET_CRC_SIZES (14)
#define MZ_ZIP_UNCOMPR_SIZE64_CUSHION (2 * 1024 * 1024)
#ifndef MZ_ZIP_EOCD_MAX_BACK
#define MZ_ZIP_EOCD_MAX_BACK (1 << 20)
@ -190,7 +191,7 @@ static int32_t mz_zip_search_zip64_eocd(void *stream, const int64_t end_central_
/* Get PKWARE traditional encryption verifier */
static uint16_t mz_zip_get_pk_verify(uint32_t dos_date, uint64_t crc, uint16_t flag)
{
/* Info-ZIP modification to ZipCrypto format: if bit 3 of the general
/* Info-ZIP modification to ZipCrypto format: if bit 3 of the general
* purpose bit flag is set, it uses high byte of 16-bit File Time. */
if (flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR)
return ((dos_date >> 16) & 0xff) << 8 | ((dos_date >> 8) & 0xff);
@ -521,7 +522,7 @@ static int32_t mz_zip_entry_read_descriptor(void *stream, uint8_t zip64, uint32_
return err;
}
static int32_t mz_zip_entry_write_crc_sizes(void *stream, uint8_t mask, mz_zip_file *file_info) {
static int32_t mz_zip_entry_write_crc_sizes(void *stream, uint8_t zip64, uint8_t mask, mz_zip_file *file_info) {
int32_t err = MZ_OK;
if (mask)
@ -529,23 +530,71 @@ static int32_t mz_zip_entry_write_crc_sizes(void *stream, uint8_t mask, mz_zip_f
else
err = mz_stream_write_uint32(stream, file_info->crc); /* crc */
/* For backwards-compatibility with older zip applications we set all sizes to UINT32_MAX
* when zip64 is needed, instead of only setting sizes larger than UINT32_MAX. */
if (err == MZ_OK) {
if (file_info->compressed_size >= UINT32_MAX) /* compr size */
if (zip64) /* compr size */
err = mz_stream_write_uint32(stream, UINT32_MAX);
else
err = mz_stream_write_uint32(stream, (uint32_t)file_info->compressed_size);
}
if (err == MZ_OK) {
if (file_info->uncompressed_size >= UINT32_MAX) /* uncompr size */
err = mz_stream_write_uint32(stream, UINT32_MAX);
else if (mask)
if (mask) /* uncompr size */
err = mz_stream_write_uint32(stream, 0);
else if (zip64)
err = mz_stream_write_uint32(stream, UINT32_MAX);
else
err = mz_stream_write_uint32(stream, (uint32_t)file_info->uncompressed_size);
}
return err;
}
static int32_t mz_zip_entry_needs_zip64(mz_zip_file *file_info, uint8_t local, uint8_t *zip64) {
uint32_t max_uncompressed_size = UINT32_MAX;
uint8_t needs_zip64 = 0;
if (zip64 == NULL)
return MZ_PARAM_ERROR;
*zip64 = 0;
if (local) {
/* At local header we might not know yet whether compressed size will overflow unsigned
32-bit integer which might happen for high entropy data so we give it some cushion */
max_uncompressed_size -= MZ_ZIP_UNCOMPR_SIZE64_CUSHION;
}
needs_zip64 = (file_info->uncompressed_size >= max_uncompressed_size) ||
(file_info->compressed_size >= UINT32_MAX);
if (!local) {
/* Disk offset and number only used in central directory header */
needs_zip64 |= (file_info->disk_offset >= UINT32_MAX) ||
(file_info->disk_number >= UINT16_MAX);
}
if (file_info->zip64 == MZ_ZIP64_AUTO) {
/* If uncompressed size is unknown, assume zip64 for 64-bit data descriptors */
if (local && file_info->uncompressed_size == 0) {
/* Don't use zip64 for local header directory entries */
if (mz_zip_attrib_is_dir(file_info->external_fa, file_info->version_madeby) != MZ_OK) {
*zip64 = 1;
}
}
*zip64 |= needs_zip64;
} else if (file_info->zip64 == MZ_ZIP64_FORCE) {
*zip64 = 1;
} else if (file_info->zip64 == MZ_ZIP64_DISABLE) {
/* Zip64 extension is required to zip file */
if (needs_zip64)
return MZ_PARAM_ERROR;
}
return MZ_OK;
}
static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_file *file_info) {
uint64_t ntfs_time = 0;
uint32_t reserved = 0;
@ -578,26 +627,18 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
if ((local) && (file_info->flag & MZ_ZIP_FLAG_MASK_LOCAL_INFO))
mask = 1;
/* Calculate extra field sizes */
if (file_info->uncompressed_size >= UINT32_MAX)
field_length_zip64 += 8;
if (file_info->compressed_size >= UINT32_MAX)
field_length_zip64 += 8;
if (file_info->disk_offset >= UINT32_MAX)
field_length_zip64 += 8;
if (file_info->zip64 == MZ_ZIP64_AUTO) {
/* If uncompressed size is unknown, assume zip64 for 64-bit data descriptors */
zip64 = (local && file_info->uncompressed_size == 0) || (field_length_zip64 > 0);
} else if (file_info->zip64 == MZ_ZIP64_FORCE) {
zip64 = 1;
} else if (file_info->zip64 == MZ_ZIP64_DISABLE) {
/* Zip64 extension is required to zip file */
if (field_length_zip64 > 0)
return MZ_PARAM_ERROR;
}
/* Determine if zip64 extra field is necessary */
err = mz_zip_entry_needs_zip64(file_info, local, &zip64);
if (err != MZ_OK)
return err;
/* Start calculating extra field sizes */
if (zip64) {
/* Both compressed and uncompressed sizes must be included (at least in local header) */
field_length_zip64 = 8 + 8;
if ((!local) && (file_info->disk_offset >= UINT32_MAX))
field_length_zip64 += 8;
extrafield_size += 4;
extrafield_size += field_length_zip64;
}
@ -699,7 +740,7 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
}
if (err == MZ_OK)
err = mz_zip_entry_write_crc_sizes(stream, mask, file_info);
err = mz_zip_entry_write_crc_sizes(stream, zip64, mask, file_info);
if (mask) {
snprintf(masked_name, sizeof(masked_name), "%" PRIx32 "_%" PRIx64,
@ -754,45 +795,21 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
err = mz_stream_write_uint8(stream, '/');
}
if (file_info->extrafield_size > 0) {
err_mem = mz_stream_mem_seek(file_extra_stream, 0, MZ_SEEK_SET);
while (err == MZ_OK && err_mem == MZ_OK) {
err_mem = mz_stream_read_uint16(file_extra_stream, &field_type);
if (err_mem == MZ_OK)
err_mem = mz_stream_read_uint16(file_extra_stream, &field_length);
if (err_mem != MZ_OK)
break;
/* Prefer our zip 64, ntfs, unix1 extensions over incoming */
if (field_type == MZ_ZIP_EXTENSION_ZIP64 || field_type == MZ_ZIP_EXTENSION_NTFS ||
field_type == MZ_ZIP_EXTENSION_UNIX1) {
err_mem = mz_stream_seek(file_extra_stream, field_length, MZ_SEEK_CUR);
continue;
}
err = mz_stream_write_uint16(stream, field_type);
if (err == MZ_OK)
err = mz_stream_write_uint16(stream, field_length);
if (err == MZ_OK)
err = mz_stream_copy(stream, file_extra_stream, field_length);
}
mz_stream_mem_delete(&file_extra_stream);
}
/* Write ZIP64 extra field */
/* Write ZIP64 extra field first so we can update sizes later if data descriptor not used */
if ((err == MZ_OK) && (zip64)) {
err = mz_zip_extrafield_write(stream, MZ_ZIP_EXTENSION_ZIP64, field_length_zip64);
if ((err == MZ_OK) && (file_info->uncompressed_size >= UINT32_MAX)) {
if (err == MZ_OK) {
if (mask)
err = mz_stream_write_int64(stream, 0);
else
err = mz_stream_write_int64(stream, file_info->uncompressed_size);
}
if ((err == MZ_OK) && (file_info->compressed_size >= UINT32_MAX))
if (err == MZ_OK)
err = mz_stream_write_int64(stream, file_info->compressed_size);
if ((err == MZ_OK) && (file_info->disk_offset >= UINT32_MAX))
if ((err == MZ_OK) && (!local) && (file_info->disk_offset >= UINT32_MAX))
err = mz_stream_write_int64(stream, file_info->disk_offset);
if ((err == MZ_OK) && (!local) && (file_info->disk_number >= UINT16_MAX))
err = mz_stream_write_uint32(stream, file_info->disk_number);
}
/* Write NTFS extra field */
if ((err == MZ_OK) && (field_length_ntfs > 0)) {
@ -848,6 +865,33 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
err = mz_stream_write_uint16(stream, file_info->compression_method);
}
#endif
if (file_info->extrafield_size > 0) {
err_mem = mz_stream_mem_seek(file_extra_stream, 0, MZ_SEEK_SET);
while (err == MZ_OK && err_mem == MZ_OK) {
err_mem = mz_stream_read_uint16(file_extra_stream, &field_type);
if (err_mem == MZ_OK)
err_mem = mz_stream_read_uint16(file_extra_stream, &field_length);
if (err_mem != MZ_OK)
break;
/* Prefer our zip 64, ntfs, unix1 extensions over incoming */
if (field_type == MZ_ZIP_EXTENSION_ZIP64 || field_type == MZ_ZIP_EXTENSION_NTFS ||
field_type == MZ_ZIP_EXTENSION_UNIX1) {
err_mem = mz_stream_seek(file_extra_stream, field_length, MZ_SEEK_CUR);
continue;
}
err = mz_stream_write_uint16(stream, field_type);
if (err == MZ_OK)
err = mz_stream_write_uint16(stream, field_length);
if (err == MZ_OK)
err = mz_stream_copy(stream, file_extra_stream, field_length);
}
mz_stream_mem_delete(&file_extra_stream);
}
if ((err == MZ_OK) && (!local) && (file_info->comment != NULL)) {
if (mz_stream_write(stream, file_info->comment, file_info->comment_size) != file_info->comment_size)
err = MZ_WRITE_ERROR;
@ -1701,7 +1745,7 @@ static int32_t mz_zip_entry_open_int(void *handle, uint8_t raw, int16_t compress
if (err == MZ_OK) {
if (zip->entry_raw || zip->file_info.compression_method == MZ_COMPRESS_METHOD_STORE)
mz_stream_raw_create(&zip->compress_stream);
#if defined(HAVE_ZLIB) || defined(HAVE_LIBCOMP)
#ifdef HAVE_ZLIB
else if (zip->file_info.compression_method == MZ_COMPRESS_METHOD_DEFLATE)
mz_stream_zlib_create(&zip->compress_stream);
#endif
@ -1710,7 +1754,8 @@ static int32_t mz_zip_entry_open_int(void *handle, uint8_t raw, int16_t compress
mz_stream_bzip_create(&zip->compress_stream);
#endif
#ifdef HAVE_LIBCOMP
else if (zip->file_info.compression_method == MZ_COMPRESS_METHOD_XZ) {
else if (zip->file_info.compression_method == MZ_COMPRESS_METHOD_DEFLATE ||
zip->file_info.compression_method == MZ_COMPRESS_METHOD_XZ) {
mz_stream_libcomp_create(&zip->compress_stream);
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_COMPRESS_METHOD,
zip->file_info.compression_method);
@ -1795,30 +1840,6 @@ int32_t mz_zip_entry_is_open(void *handle) {
return MZ_OK;
}
static int32_t mz_zip_seek_to_local_header(void *handle) {
mz_zip *zip = (mz_zip *)handle;
int64_t disk_size = 0;
uint32_t disk_number = zip->file_info.disk_number;
if (disk_number == zip->disk_number_with_cd) {
mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_SIZE, &disk_size);
if ((disk_size == 0) || ((zip->open_mode & MZ_OPEN_MODE_WRITE) == 0))
disk_number = (uint32_t)-1;
}
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, disk_number);
mz_zip_print("Zip - Entry - Seek local (disk %" PRId32 " offset %" PRId64 ")\n",
disk_number, zip->file_info.disk_offset);
/* Guard against seek overflows */
if ((zip->disk_offset_shift > 0) &&
(zip->file_info.disk_offset > (INT64_MAX - zip->disk_offset_shift)))
return MZ_FORMAT_ERROR;
return mz_stream_seek(zip->stream, zip->file_info.disk_offset + zip->disk_offset_shift, MZ_SEEK_SET);
}
int32_t mz_zip_entry_read_open(void *handle, uint8_t raw, const char *password) {
mz_zip *zip = (mz_zip *)handle;
int32_t err = MZ_OK;
@ -1837,7 +1858,7 @@ int32_t mz_zip_entry_read_open(void *handle, uint8_t raw, const char *password)
mz_zip_print("Zip - Entry - Read open (raw %" PRId32 ")\n", raw);
err = mz_zip_seek_to_local_header(handle);
err = mz_zip_entry_seek_local_header(handle);
if (err == MZ_OK)
err = mz_zip_entry_read_header(zip->stream, 1, &zip->local_file_info, zip->local_file_info_stream);
@ -2048,7 +2069,7 @@ int32_t mz_zip_entry_read_close(void *handle, uint32_t *crc32, int64_t *compress
zip->local_file_info.extrafield_size, MZ_ZIP_EXTENSION_ZIP64, NULL) == MZ_OK)
zip64 = 1;
err = mz_zip_seek_to_local_header(handle);
err = mz_zip_entry_seek_local_header(handle);
/* Seek to end of compressed stream since we might have over-read during compression */
if (err == MZ_OK)
@ -2115,21 +2136,11 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
mz_stream_get_prop_int64(zip->crypt_stream, MZ_STREAM_PROP_TOTAL_OUT, &compressed_size);
}
mz_zip_entry_needs_zip64(&zip->file_info, 1, &zip64);
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR)) {
/* Determine if we need to write data descriptor in zip64 format,
if local extrafield was saved with zip64 extrafield */
if (zip->file_info.zip64 == MZ_ZIP64_AUTO) {
if (zip->file_info.uncompressed_size >= UINT32_MAX)
zip64 = 1;
if (zip->file_info.compressed_size >= UINT32_MAX)
zip64 = 1;
if (zip->file_info.disk_offset >= UINT32_MAX)
zip64 = 1;
else if (zip->file_info.uncompressed_size == 0)
zip64 = 1;
} else if (zip->file_info.zip64 == MZ_ZIP64_FORCE) {
zip64 = 1;
}
if (zip->file_info.flag & MZ_ZIP_FLAG_MASK_LOCAL_INFO)
err = mz_zip_entry_write_descriptor(zip->stream,
@ -2158,7 +2169,7 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
int64_t end_pos = mz_stream_tell(zip->stream);
mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, &end_disk_number);
err = mz_zip_seek_to_local_header(handle);
err = mz_zip_entry_seek_local_header(handle);
if (err == MZ_OK) {
/* Seek to crc32 and sizes offset in local header */
@ -2166,7 +2177,23 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
}
if (err == MZ_OK)
err = mz_zip_entry_write_crc_sizes(zip->stream, 0, &zip->file_info);
err = mz_zip_entry_write_crc_sizes(zip->stream, zip64, 0, &zip->file_info);
/* Seek to and update zip64 extension sizes */
if ((err == MZ_OK) && (zip64)) {
int64_t filename_size = zip->file_info.filename_size;
if (filename_size == 0)
filename_size = strlen(zip->file_info.filename);
/* Since we write zip64 extension first we know its offset */
err = mz_stream_seek(zip->stream, 2 + 2 + filename_size + 4, MZ_SEEK_CUR);
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, zip->file_info.uncompressed_size);
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, zip->file_info.compressed_size);
}
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, end_disk_number);
mz_stream_seek(zip->stream, end_pos, MZ_SEEK_SET);
@ -2179,6 +2206,30 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
return err;
}
int32_t mz_zip_entry_seek_local_header(void *handle) {
mz_zip *zip = (mz_zip *)handle;
int64_t disk_size = 0;
uint32_t disk_number = zip->file_info.disk_number;
if (disk_number == zip->disk_number_with_cd) {
mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_SIZE, &disk_size);
if ((disk_size == 0) || ((zip->open_mode & MZ_OPEN_MODE_WRITE) == 0))
disk_number = (uint32_t)-1;
}
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, disk_number);
mz_zip_print("Zip - Entry - Seek local (disk %" PRId32 " offset %" PRId64 ")\n",
disk_number, zip->file_info.disk_offset);
/* Guard against seek overflows */
if ((zip->disk_offset_shift > 0) &&
(zip->file_info.disk_offset > (INT64_MAX - zip->disk_offset_shift)))
return MZ_FORMAT_ERROR;
return mz_stream_seek(zip->stream, zip->file_info.disk_offset + zip->disk_offset_shift, MZ_SEEK_SET);
}
int32_t mz_zip_entry_close(void *handle) {
return mz_zip_entry_close_raw(handle, UINT64_MAX, 0);
}
@ -2498,11 +2549,15 @@ int32_t mz_zip_attrib_win32_to_posix(uint32_t win32_attrib, uint32_t *posix_attr
/***************************************************************************/
int32_t mz_zip_extrafield_find(void *stream, uint16_t type, uint16_t *length) {
int32_t mz_zip_extrafield_find(void *stream, uint16_t type, int32_t max_seek, uint16_t *length) {
int32_t err = MZ_OK;
uint16_t field_type = 0;
uint16_t field_length = 0;
if (max_seek < 4)
return MZ_EXIST_ERROR;
do {
err = mz_stream_read_uint16(stream, &field_type);
if (err == MZ_OK)
@ -2516,6 +2571,10 @@ int32_t mz_zip_extrafield_find(void *stream, uint16_t type, uint16_t *length) {
return MZ_OK;
}
max_seek -= field_length - 4;
if (max_seek < 0)
return MZ_EXIST_ERROR;
err = mz_stream_seek(stream, field_length, MZ_SEEK_CUR);
} while (err == MZ_OK);
@ -2533,7 +2592,7 @@ int32_t mz_zip_extrafield_contains(const uint8_t *extrafield, int32_t extrafield
mz_stream_mem_create(&file_extra_stream);
mz_stream_mem_set_buffer(file_extra_stream, (void *)extrafield, extrafield_size);
err = mz_zip_extrafield_find(file_extra_stream, type, length);
err = mz_zip_extrafield_find(file_extra_stream, type, extrafield_size, length);
mz_stream_mem_delete(&file_extra_stream);

View File

@ -1,8 +1,8 @@
/* mz_zip.h -- Zip manipulation
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
@ -136,6 +136,9 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
int64_t uncompressed_size);
/* Close the current file for writing and set data descriptor values */
int32_t mz_zip_entry_seek_local_header(void *handle);
/* Seeks to the local header for the entry */
int32_t mz_zip_entry_close_raw(void *handle, int64_t uncompressed_size, uint32_t crc32);
/* Close the current file in the zip file where raw is compressed data */
@ -200,7 +203,7 @@ int32_t mz_zip_attrib_win32_to_posix(uint32_t win32_attrib, uint32_t *posix_attr
/***************************************************************************/
int32_t mz_zip_extrafield_find(void *stream, uint16_t type, uint16_t *length);
int32_t mz_zip_extrafield_find(void *stream, uint16_t type, int32_t max_seek, uint16_t *length);
/* Seeks to extra field by its type and returns its length */
int32_t mz_zip_extrafield_contains(const uint8_t *extrafield, int32_t extrafield_size,

View File

@ -1,8 +1,8 @@
/* mz_zip_rw.c -- Zip reader/writer
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -247,7 +247,7 @@ int32_t mz_zip_reader_unzip_cd(void *handle) {
mz_stream_mem_create(&file_extra_stream);
mz_stream_mem_set_buffer(file_extra_stream, (void *)cd_info->extrafield, cd_info->extrafield_size);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_CDCD, NULL);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_CDCD, INT32_MAX, NULL);
if (err == MZ_OK)
err = mz_stream_read_uint64(file_extra_stream, &number_entry);
@ -382,7 +382,7 @@ int32_t mz_zip_reader_entry_open(void *handle) {
}
err = mz_zip_entry_read_open(reader->zip_handle, reader->raw, password);
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
if (err != MZ_OK)
return err;
@ -418,7 +418,7 @@ int32_t mz_zip_reader_entry_close(void *handle) {
mz_zip_reader *reader = (mz_zip_reader *)handle;
int32_t err = MZ_OK;
int32_t err_close = MZ_OK;
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
int32_t err_hash = MZ_OK;
uint8_t computed_hash[MZ_HASH_MAX_SIZE];
uint8_t expected_hash[MZ_HASH_MAX_SIZE];
@ -448,7 +448,7 @@ int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len) {
mz_zip_reader *reader = (mz_zip_reader *)handle;
int32_t read = 0;
read = mz_zip_entry_read(reader->zip_handle, buf, len);
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
if ((read > 0) && (reader->hash != NULL))
mz_crypt_sha_update(reader->hash, buf, read);
#endif
@ -465,7 +465,7 @@ int32_t mz_zip_reader_entry_has_sign(void *handle) {
reader->file_info->extrafield_size, MZ_ZIP_EXTENSION_SIGN, NULL);
}
#if !defined(MZ_ZIP_NO_ENCRYPTION) && defined(MZ_ZIP_SIGNING)
#if !defined(MZ_ZIP_NO_CRYPTO) && defined(MZ_ZIP_SIGNING)
int32_t mz_zip_reader_entry_sign_verify(void *handle) {
mz_zip_reader *reader = (mz_zip_reader *)handle;
void *file_extra_stream = NULL;
@ -481,7 +481,7 @@ int32_t mz_zip_reader_entry_sign_verify(void *handle) {
mz_stream_mem_set_buffer(file_extra_stream, (void *)reader->file_info->extrafield,
reader->file_info->extrafield_size);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_SIGN, &signature_size);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_SIGN, INT32_MAX, &signature_size);
if ((err == MZ_OK) && (signature_size > 0)) {
signature = (uint8_t *)MZ_ALLOC(signature_size);
if (mz_stream_read(file_extra_stream, signature, signature_size) != signature_size)
@ -520,7 +520,7 @@ int32_t mz_zip_reader_entry_get_hash(void *handle, uint16_t algorithm, uint8_t *
reader->file_info->extrafield_size);
do {
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_HASH, NULL);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_HASH, INT32_MAX, NULL);
if (err != MZ_OK)
break;
@ -557,7 +557,7 @@ int32_t mz_zip_reader_entry_get_first_hash(void *handle, uint16_t *algorithm, ui
mz_stream_mem_set_buffer(file_extra_stream, (void *)reader->file_info->extrafield,
reader->file_info->extrafield_size);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_HASH, NULL);
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_HASH, INT32_MAX, NULL);
if (err == MZ_OK)
err = mz_stream_read_uint16(file_extra_stream, &cur_algorithm);
if (err == MZ_OK)
@ -1116,8 +1116,16 @@ static int32_t mz_zip_writer_open_int(void *handle, void *stream, int32_t mode)
return MZ_OK;
}
int32_t mz_zip_writer_open(void *handle, void *stream) {
return mz_zip_writer_open_int(handle, stream, MZ_OPEN_MODE_WRITE);
int32_t mz_zip_writer_open(void *handle, void *stream, uint8_t append) {
int32_t mode = MZ_OPEN_MODE_WRITE;
if (append) {
mode |= MZ_OPEN_MODE_APPEND;
} else {
mode |= MZ_OPEN_MODE_CREATE;
}
return mz_zip_writer_open_int(handle, stream, mode);
}
int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append) {
@ -1213,7 +1221,7 @@ int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path) {
mz_stream_os_delete(&file_stream);
if (err == MZ_OK)
err = mz_zip_writer_open(handle, writer->mem_stream);
err = mz_zip_writer_open(handle, writer->mem_stream, 1);
if (err != MZ_OK)
mz_zip_writer_close(handle);
@ -1279,7 +1287,7 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info) {
password = password_buf;
}
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
if (mz_zip_attrib_is_dir(writer->file_info.external_fa, writer->file_info.version_madeby) != MZ_OK) {
/* Start calculating sha256 */
mz_crypt_sha_create(&writer->sha256);
@ -1295,7 +1303,7 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info) {
return err;
}
#if !defined(MZ_ZIP_NO_ENCRYPTION) && defined(MZ_ZIP_SIGNING)
#if !defined(MZ_ZIP_NO_CRYPTO) && defined(MZ_ZIP_SIGNING)
int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message_size,
uint8_t *cert_data, int32_t cert_data_size, const char *cert_pwd) {
mz_zip_writer *writer = (mz_zip_writer *)handle;
@ -1333,7 +1341,7 @@ int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message
int32_t mz_zip_writer_entry_close(void *handle) {
mz_zip_writer *writer = (mz_zip_writer *)handle;
int32_t err = MZ_OK;
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
const uint8_t *extrafield = NULL;
int32_t extrafield_size = 0;
int16_t field_length_hash = 0;
@ -1400,7 +1408,7 @@ int32_t mz_zip_writer_entry_write(void *handle, const void *buf, int32_t len) {
mz_zip_writer *writer = (mz_zip_writer *)handle;
int32_t written = 0;
written = mz_zip_entry_write(writer->zip_handle, buf, len);
#ifndef MZ_ZIP_NO_ENCRYPTION
#ifndef MZ_ZIP_NO_CRYPTO
if ((written > 0) && (writer->sha256 != NULL))
mz_crypt_sha_update(writer->sha256, buf, written);
#endif

View File

@ -1,8 +1,8 @@
/* mz_zip_rw.h -- Zip reader/writer
part of the MiniZip project
part of the minizip-ng project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2010-2021 Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@ -170,7 +170,7 @@ typedef int32_t (*mz_zip_writer_entry_cb)(void *handle, void *userdata, mz_zip_f
int32_t mz_zip_writer_is_open(void *handle);
/* Checks to see if the zip file is open */
int32_t mz_zip_writer_open(void *handle, void *stream);
int32_t mz_zip_writer_open(void *handle, void *stream, uint8_t append);
/* Opens zip file from stream */
int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append);

View File

@ -1,402 +0,0 @@
/* mz_crypt_brg.c -- Crypto/hash functions using Brian Gladman's library
part of the MiniZip project
Copyright (C) 2010-2020 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include "mz.h"
#include "mz_os.h"
#if defined(HAVE_GETRANDOM)
# include <sys/random.h>
#endif
#if defined(HAVE_LIBBSD)
# include <sys/types.h>
# ifndef __u_char_defined
typedef unsigned char u_char;
# endif
# include <bsd/stdlib.h> /* arc4random_buf */
#endif
#include "aes.h"
#include "sha1.h"
#include "sha2.h"
#include "hmac.h"
/***************************************************************************/
#if defined(HAVE_ARC4RANDOM_BUF)
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
if (size < 0)
return 0;
arc4random_buf(buf, (uint32_t)size);
return size;
}
#elif defined(HAVE_ARC4RANDOM)
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
int32_t left = size;
for (; left > 2; left -= 3, buf += 3) {
uint32_t val = arc4random();
buf[0] = (val) & 0xFF;
buf[1] = (val >> 8) & 0xFF;
buf[2] = (val >> 16) & 0xFF;
}
for (; left > 0; left--, buf++) {
*buf = arc4random() & 0xFF;
}
return size - left;
}
#elif defined(HAVE_GETRANDOM)
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
int32_t left = size;
int32_t written = 0;
while (left > 0) {
written = getrandom(buf, left, 0);
if (written < 0)
return MZ_INTERNAL_ERROR;
buf += written;
left -= written;
}
return size - left;
}
#else
#if !defined(FORCE_LOWQUALITY_ENTROPY)
#pragma message("Warning: Low quality entropy function used for encryption")
#endif
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
return mz_os_rand(buf, size);
}
#endif
/***************************************************************************/
typedef struct mz_crypt_sha_s {
sha256_ctx ctx256;
sha1_ctx ctx1;
int32_t initialized;
uint16_t algorithm;
} mz_crypt_sha;
/***************************************************************************/
void mz_crypt_sha_reset(void *handle) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
sha->initialized = 0;
}
int32_t mz_crypt_sha_begin(void *handle) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
if (sha == NULL)
return MZ_PARAM_ERROR;
if (sha->algorithm == MZ_HASH_SHA1)
sha1_begin(&sha->ctx1);
else
sha256_begin(&sha->ctx256);
sha->initialized = 1;
return MZ_OK;
}
int32_t mz_crypt_sha_update(void *handle, const void *buf, int32_t size) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
if (sha == NULL || buf == NULL || !sha->initialized)
return MZ_PARAM_ERROR;
if (sha->algorithm == MZ_HASH_SHA1)
sha1_hash(buf, size, &sha->ctx1);
else
sha256_hash(buf, size, &sha->ctx256);
return size;
}
int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
if (sha == NULL || digest == NULL || !sha->initialized)
return MZ_PARAM_ERROR;
if (sha->algorithm == MZ_HASH_SHA1) {
if (digest_size < MZ_HASH_SHA1_SIZE)
return MZ_BUF_ERROR;
sha1_end(digest, &sha->ctx1);
} else {
if (digest_size < MZ_HASH_SHA256_SIZE)
return MZ_BUF_ERROR;
sha256_end(digest, &sha->ctx256);
}
return MZ_OK;
}
void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
sha->algorithm = algorithm;
}
void *mz_crypt_sha_create(void **handle) {
mz_crypt_sha *sha = NULL;
sha = (mz_crypt_sha *)MZ_ALLOC(sizeof(mz_crypt_sha));
if (sha != NULL) {
memset(sha, 0, sizeof(mz_crypt_sha));
sha->algorithm = MZ_HASH_SHA256;
}
if (handle != NULL)
*handle = sha;
return sha;
}
void mz_crypt_sha_delete(void **handle) {
mz_crypt_sha *sha = NULL;
if (handle == NULL)
return;
sha = (mz_crypt_sha *)*handle;
if (sha != NULL) {
mz_crypt_sha_reset(*handle);
MZ_FREE(sha);
}
*handle = NULL;
}
/***************************************************************************/
typedef struct mz_crypt_aes_s {
aes_encrypt_ctx encrypt_ctx;
aes_decrypt_ctx decrypt_ctx;
int32_t mode;
int32_t error;
} mz_crypt_aes;
/***************************************************************************/
void mz_crypt_aes_reset(void *handle) {
MZ_UNUSED(handle);
}
int32_t mz_crypt_aes_encrypt(void *handle, uint8_t *buf, int32_t size) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
if (aes == NULL || buf == NULL)
return MZ_PARAM_ERROR;
if (size != MZ_AES_BLOCK_SIZE)
return MZ_PARAM_ERROR;
aes->error = aes_encrypt(buf, buf, &aes->encrypt_ctx);
if (aes->error)
return MZ_CRYPT_ERROR;
return size;
}
int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
if (aes == NULL || buf == NULL)
return MZ_PARAM_ERROR;
if (size != MZ_AES_BLOCK_SIZE)
return MZ_PARAM_ERROR;
aes->error = aes_decrypt(buf, buf, &aes->decrypt_ctx);
if (aes->error)
return MZ_CRYPT_ERROR;
return size;
}
int32_t mz_crypt_aes_set_encrypt_key(void *handle, const void *key, int32_t key_length) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
if (aes == NULL || key == NULL)
return MZ_PARAM_ERROR;
mz_crypt_aes_reset(handle);
aes->error = aes_encrypt_key(key, key_length, &aes->encrypt_ctx);
if (aes->error)
return MZ_HASH_ERROR;
return MZ_OK;
}
int32_t mz_crypt_aes_set_decrypt_key(void *handle, const void *key, int32_t key_length) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
if (aes == NULL || key == NULL)
return MZ_PARAM_ERROR;
mz_crypt_aes_reset(handle);
aes->error = aes_decrypt_key(key, key_length, &aes->decrypt_ctx);
if (aes->error)
return MZ_HASH_ERROR;
return MZ_OK;
}
void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
aes->mode = mode;
}
void *mz_crypt_aes_create(void **handle) {
mz_crypt_aes *aes = NULL;
aes = (mz_crypt_aes *)MZ_ALLOC(sizeof(mz_crypt_aes));
if (aes != NULL)
memset(aes, 0, sizeof(mz_crypt_aes));
if (handle != NULL)
*handle = aes;
return aes;
}
void mz_crypt_aes_delete(void **handle) {
mz_crypt_aes *aes = NULL;
if (handle == NULL)
return;
aes = (mz_crypt_aes *)*handle;
if (aes != NULL)
MZ_FREE(aes);
*handle = NULL;
}
/***************************************************************************/
typedef struct mz_crypt_hmac_s {
hmac_ctx ctx;
int32_t initialized;
int32_t error;
uint16_t algorithm;
} mz_crypt_hmac;
/***************************************************************************/
void mz_crypt_hmac_reset(void *handle) {
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
hmac->error = 0;
}
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
if (hmac == NULL)
return MZ_PARAM_ERROR;
mz_crypt_hmac_reset(handle);
if (hmac->algorithm == MZ_HASH_SHA1)
hmac_sha_begin(HMAC_SHA1, &hmac->ctx);
else
hmac_sha_begin(HMAC_SHA256, &hmac->ctx);
hmac_sha_key(key, key_length, &hmac->ctx);
return MZ_OK;
}
int32_t mz_crypt_hmac_update(void *handle, const void *buf, int32_t size) {
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
if (hmac == NULL || buf == NULL)
return MZ_PARAM_ERROR;
hmac_sha_data(buf, size, &hmac->ctx);
return MZ_OK;
}
int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size) {
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
if (hmac == NULL || digest == NULL)
return MZ_PARAM_ERROR;
if (hmac->algorithm == MZ_HASH_SHA1) {
if (digest_size < MZ_HASH_SHA1_SIZE)
return MZ_BUF_ERROR;
hmac_sha_end(digest, digest_size, &hmac->ctx);
} else {
if (digest_size < MZ_HASH_SHA256_SIZE)
return MZ_BUF_ERROR;
hmac_sha_end(digest, digest_size, &hmac->ctx);
}
return MZ_OK;
}
void mz_crypt_hmac_set_algorithm(void *handle, uint16_t algorithm) {
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
hmac->algorithm = algorithm;
}
int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
mz_crypt_hmac *source = (mz_crypt_hmac *)src_handle;
mz_crypt_hmac *target = (mz_crypt_hmac *)target_handle;
if (target == NULL || source == NULL)
return MZ_PARAM_ERROR;
memcpy(&target->ctx, &source->ctx, sizeof(hmac_ctx));
return MZ_OK;
}
void *mz_crypt_hmac_create(void **handle) {
mz_crypt_hmac *hmac = NULL;
hmac = (mz_crypt_hmac *)MZ_ALLOC(sizeof(mz_crypt_hmac));
if (hmac != NULL) {
memset(hmac, 0, sizeof(mz_crypt_hmac));
hmac->algorithm = MZ_HASH_SHA256;
}
if (handle != NULL)
*handle = hmac;
return hmac;
}
void mz_crypt_hmac_delete(void **handle) {
mz_crypt_hmac *hmac = NULL;
if (handle == NULL)
return;
hmac = (mz_crypt_hmac *)*handle;
if (hmac != NULL)
MZ_FREE(hmac);
*handle = NULL;
}
/***************************************************************************/
#if defined(MZ_ZIP_SIGNING)
int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data, int32_t cert_data_size,
const char *cert_pwd, uint8_t **signature, int32_t *signature_size) {
MZ_UNUSED(message);
MZ_UNUSED(message_size);
MZ_UNUSED(cert_data);
MZ_UNUSED(cert_data_size);
MZ_UNUSED(cert_pwd);
MZ_UNUSED(signature);
MZ_UNUSED(signature_size);
return MZ_SUPPORT_ERROR;
}
int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size) {
MZ_UNUSED(message);
MZ_UNUSED(message_size);
MZ_UNUSED(signature);
MZ_UNUSED(signature_size);
return MZ_SUPPORT_ERROR;
}
#endif