diff options
author | Brad King <brad.king@kitware.com> | 2023-04-25 14:28:08 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-04-25 14:28:08 (GMT) |
commit | 1e2bce305fca2f3d480c2e6b5257fa29921b148f (patch) | |
tree | eabb87fa9425d01aba8d5e7386899cbde5bb9d2c /Utilities | |
parent | 744a42c0ee0a1911b17a105915023eff1f1b7ce0 (diff) | |
parent | e468170731ebdcfe1513cf3a14a07dc68f27320c (diff) | |
download | CMake-1e2bce305fca2f3d480c2e6b5257fa29921b148f.zip CMake-1e2bce305fca2f3d480c2e6b5257fa29921b148f.tar.gz CMake-1e2bce305fca2f3d480c2e6b5257fa29921b148f.tar.bz2 |
Merge branch 'upstream-LibArchive' into update-libarchive
* upstream-LibArchive:
LibArchive 2022-12-09 (ba80276c)
Diffstat (limited to 'Utilities')
36 files changed, 348 insertions, 113 deletions
diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index b38e653..89b37a7 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -238,7 +238,7 @@ OPTION(ENABLE_BZip2 "Enable the use of the system BZip2 library if found" ON) OPTION(ENABLE_LIBXML2 "Enable the use of the system libxml2 library if found" ON) OPTION(ENABLE_EXPAT "Enable the use of the system EXPAT library if found" ON) OPTION(ENABLE_PCREPOSIX "Enable the use of the system PCREPOSIX library if found" ON) -OPTION(ENABLE_LibGCC "Enable the use of the system LibGCC library if found" ON) +OPTION(ENABLE_LIBGCC "Enable the use of the system LibGCC library if found" ON) # CNG is used for encrypt/decrypt Zip archives on Windows. OPTION(ENABLE_CNG "Enable the use of CNG(Crypto Next Generation)" ON) @@ -257,7 +257,7 @@ OPTION(ENABLE_INSTALL "Enable installing of libraries" ON) SET(POSIX_REGEX_LIB "AUTO" CACHE STRING "Choose what library should provide POSIX regular expression support") SET(ENABLE_SAFESEH "AUTO" CACHE STRING "Enable use of /SAFESEH linker flag (MSVC only)") -SET(WINDOWS_VERSION "WIN7" CACHE STRING "Set Windows version to use (Windows only)") +SET(WINDOWS_VERSION "WIN10" CACHE STRING "Set Windows version to use (Windows only)") IF(ENABLE_COVERAGE) include(LibarchiveCodeCoverage) @@ -268,7 +268,11 @@ IF(ENABLE_TEST) ENDIF(ENABLE_TEST) IF(WIN32) - IF(WINDOWS_VERSION STREQUAL "WIN8") + IF(WINDOWS_VERSION STREQUAL "WIN10") + SET(NTDDI_VERSION 0x0A000000) + SET(_WIN32_WINNT 0x0A00) + SET(WINVER 0x0A00) + ELSEIF(WINDOWS_VERSION STREQUAL "WIN8") SET(NTDDI_VERSION 0x06020000) SET(_WIN32_WINNT 0x0602) SET(WINVER 0x0602) @@ -292,12 +296,12 @@ IF(WIN32) SET(NTDDI_VERSION 0x05010000) SET(_WIN32_WINNT 0x0501) SET(WINVER 0x0501) - ELSE(WINDOWS_VERSION STREQUAL "WIN8") + ELSE(WINDOWS_VERSION STREQUAL "WIN10") # Default to Windows Server 2003 API if we don't recognize the specifier SET(NTDDI_VERSION 0x05020000) SET(_WIN32_WINNT 0x0502) SET(WINVER 0x0502) - ENDIF(WINDOWS_VERSION STREQUAL "WIN8") + ENDIF(WINDOWS_VERSION STREQUAL "WIN10") ENDIF(WIN32) IF(MSVC) @@ -632,8 +636,13 @@ IF(ENABLE_ZSTD) SET(ZSTD_FIND_QUIETLY TRUE) ENDIF (ZSTD_INCLUDE_DIR) - FIND_PATH(ZSTD_INCLUDE_DIR zstd.h) - FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd) + IF(UNIX) + FIND_PACKAGE(PkgConfig QUIET) + PKG_SEARCH_MODULE(PC_ZSTD libzstd) + ENDIF() + + FIND_PATH(ZSTD_INCLUDE_DIR zstd.h HINTS ${PC_ZSTD_INCLUDEDIR} ${PC_ZSTD_INCLUDE_DIRS}) + FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd HINTS ${PC_ZSTD_LIBDIR} ${PC_ZSTD_LIBRARY_DIRS}) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD DEFAULT_MSG ZSTD_LIBRARY ZSTD_INCLUDE_DIR) ELSE(ENABLE_ZSTD) @@ -1284,9 +1293,10 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$" # # If requested, try finding library for PCREPOSIX # - IF(ENABLE_LibGCC) - FIND_PACKAGE(LibGCC) + IF(ENABLE_LIBGCC) + FIND_PACKAGE(LIBGCC) ELSE() + MESSAGE(FATAL_ERROR "libgcc not found.") SET(LIBGCC_FOUND FALSE) # Override cached value ENDIF() IF(ENABLE_PCREPOSIX) @@ -1996,6 +2006,17 @@ CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD) CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512") +# Check visibility annotations +SET(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") +SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror") +CHECK_C_SOURCE_COMPILES("void __attribute__((visibility(\"default\"))) foo(void); +int main() { return 0; }" HAVE_VISIBILITY_ATTR) +IF (HAVE_VISIBILITY_ATTR) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") + ADD_DEFINITIONS(-D__LIBARCHIVE_ENABLE_VISIBILITY) +ENDIF(HAVE_VISIBILITY_ATTR) +SET(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") + # Generate "config.h" from "build/cmake/config.h.in" CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake b/Utilities/cmlibarchive/build/cmake/FindLIBGCC.cmake index 7985f2b..7985f2b 100644 --- a/Utilities/cmlibarchive/build/cmake/FindLibGCC.cmake +++ b/Utilities/cmlibarchive/build/cmake/FindLIBGCC.cmake diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in index 72467a5..e44a514 100644 --- a/Utilities/cmlibarchive/build/cmake/config.h.in +++ b/Utilities/cmlibarchive/build/cmake/config.h.in @@ -147,13 +147,13 @@ #cmakedefine ARCHIVE_XATTR_LINUX 1 /* Version number of bsdcpio */ -#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}" +#cmakedefine BSDCPIO_VERSION_STRING "@BSDCPIO_VERSION_STRING@" /* Version number of bsdtar */ -#cmakedefine BSDTAR_VERSION_STRING "${BSDTAR_VERSION_STRING}" +#cmakedefine BSDTAR_VERSION_STRING "@BSDTAR_VERSION_STRING@" /* Version number of bsdcat */ -#cmakedefine BSDCAT_VERSION_STRING "${BSDCAT_VERSION_STRING}" +#cmakedefine BSDCAT_VERSION_STRING "@BSDCAT_VERSION_STRING@" /* Define to 1 if you have the `acl_create_entry' function. */ #cmakedefine HAVE_ACL_CREATE_ENTRY 1 @@ -1012,13 +1012,13 @@ #cmakedefine HAVE__MKGMTIME64 1 /* Define as const if the declaration of iconv() needs const. */ -#define ICONV_CONST ${ICONV_CONST} +#define ICONV_CONST @ICONV_CONST@ /* Version number of libarchive as a single integer */ -#cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}" +#cmakedefine LIBARCHIVE_VERSION_NUMBER "@LIBARCHIVE_VERSION_NUMBER@" /* Version number of libarchive */ -#cmakedefine LIBARCHIVE_VERSION_STRING "${LIBARCHIVE_VERSION_STRING}" +#cmakedefine LIBARCHIVE_VERSION_STRING "@LIBARCHIVE_VERSION_STRING@" /* Define to 1 if `lstat' dereferences a symlink specified with a trailing slash. */ @@ -1036,7 +1036,7 @@ #cmakedefine NO_MINUS_C_MINUS_O 1 /* The size of `wchar_t', as computed by sizeof. */ -#cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T} +#cmakedefine SIZEOF_WCHAR_T @SIZEOF_WCHAR_T@ /* Define to 1 if strerror_r returns char *. */ #cmakedefine STRERROR_R_CHAR_P 1 @@ -1072,56 +1072,56 @@ #endif /* SAFE_TO_DEFINE_EXTENSIONS */ /* Version number of package */ -#cmakedefine VERSION "${VERSION}" +#cmakedefine VERSION "@VERSION@" /* Number of bits in a file offset, on hosts where this is settable. */ -#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} +#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ #cmakedefine _LARGEFILE_SOURCE 1 /* Define for large files, on AIX-style hosts. */ -#cmakedefine _LARGE_FILES ${_LARGE_FILES} +#cmakedefine _LARGE_FILES @_LARGE_FILES@ /* Define to control Windows SDK version */ #ifndef NTDDI_VERSION -#cmakedefine NTDDI_VERSION ${NTDDI_VERSION} +#cmakedefine NTDDI_VERSION @NTDDI_VERSION@ #endif // NTDDI_VERSION #ifndef _WIN32_WINNT -#cmakedefine _WIN32_WINNT ${_WIN32_WINNT} +#cmakedefine _WIN32_WINNT @_WIN32_WINNT@ #endif // _WIN32_WINNT #ifndef WINVER -#cmakedefine WINVER ${WINVER} +#cmakedefine WINVER @WINVER@ #endif // WINVER /* Define to empty if `const' does not conform to ANSI C. */ -#cmakedefine const ${const} +#cmakedefine const @const@ /* Define to `int' if <sys/types.h> doesn't define. */ -#cmakedefine gid_t ${gid_t} +#cmakedefine gid_t @gid_t@ /* Define to `unsigned long' if <sys/types.h> does not define. */ -#cmakedefine id_t ${id_t} +#cmakedefine id_t @id_t@ /* Define to `int' if <sys/types.h> does not define. */ -#cmakedefine mode_t ${mode_t} +#cmakedefine mode_t @mode_t@ /* Define to `long long' if <sys/types.h> does not define. */ -#cmakedefine off_t ${off_t} +#cmakedefine off_t @off_t@ /* Define to `int' if <sys/types.h> doesn't define. */ -#cmakedefine pid_t ${pid_t} +#cmakedefine pid_t @pid_t@ /* Define to `unsigned int' if <sys/types.h> does not define. */ -#cmakedefine size_t ${size_t} +#cmakedefine size_t @size_t@ /* Define to `int' if <sys/types.h> does not define. */ -#cmakedefine ssize_t ${ssize_t} +#cmakedefine ssize_t @ssize_t@ /* Define to `int' if <sys/types.h> doesn't define. */ -#cmakedefine uid_t ${uid_t} +#cmakedefine uid_t @uid_t@ #include <cm3p/kwiml/int.h> diff --git a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in index 4b631e6..1f51e77 100644 --- a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in +++ b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in @@ -10,3 +10,4 @@ Cflags: -I${includedir} Cflags.private: -DLIBARCHIVE_STATIC Libs: -L${libdir} -larchive Libs.private: @LIBS@ +Requires.private: @LIBSREQUIRED@ diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version index 102ec29..1af1bec 100644 --- a/Utilities/cmlibarchive/build/version +++ b/Utilities/cmlibarchive/build/version @@ -1 +1 @@ -3006000 +3006002 diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt index feb8697..bee69c2 100644 --- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt @@ -5,6 +5,10 @@ # ############################################ +if (ANDROID) + include_directories(${PROJECT_SOURCE_DIR}/contrib/android/include) +endif() + # Public headers SET(include_HEADERS archive.h @@ -78,6 +82,7 @@ SET(libarchive_SOURCES archive_read_set_format.c archive_read_set_options.c archive_read_support_filter_all.c + archive_read_support_filter_by_code.c archive_read_support_filter_bzip2.c archive_read_support_filter_compress.c archive_read_support_filter_gzip.c diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h index ac01738..180f3e4 100644 --- a/Utilities/cmlibarchive/libarchive/archive.h +++ b/Utilities/cmlibarchive/libarchive/archive.h @@ -36,7 +36,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3006000 +#define ARCHIVE_VERSION_NUMBER 3006002 #include <sys/stat.h> #include <stddef.h> /* for wchar_t */ @@ -120,6 +120,8 @@ typedef ssize_t la_ssize_t; # define __LA_DECL __declspec(dllimport) # endif # endif +#elif defined __LIBARCHIVE_ENABLE_VISIBILITY +# define __LA_DECL __attribute__((visibility("default"))) #else /* Static libraries or non-Windows needs no special declaration. */ # define __LA_DECL @@ -152,7 +154,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.6.0" +#define ARCHIVE_VERSION_ONLY_STRING "3.6.2" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); diff --git a/Utilities/cmlibarchive/libarchive/archive_digest.c b/Utilities/cmlibarchive/libarchive/archive_digest.c index 410df01..3361b19 100644 --- a/Utilities/cmlibarchive/libarchive/archive_digest.c +++ b/Utilities/cmlibarchive/libarchive/archive_digest.c @@ -49,16 +49,16 @@ * Initialize a Message digest. */ static int -win_crypto_init(Digest_CTX *ctx, ALG_ID algId) +win_crypto_init(Digest_CTX *ctx, DWORD prov, ALG_ID algId) { ctx->valid = 0; if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + prov, CRYPT_VERIFYCONTEXT)) { if (GetLastError() != (DWORD)NTE_BAD_KEYSET) return (ARCHIVE_FAILED); if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_NEWKEYSET)) + prov, CRYPT_NEWKEYSET)) return (ARCHIVE_FAILED); } @@ -243,7 +243,8 @@ __archive_md5init(archive_md5_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_md5()); + if (!EVP_DigestInit(*ctx, EVP_md5())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -275,7 +276,7 @@ __archive_md5final(archive_md5_ctx *ctx, void *md) static int __archive_md5init(archive_md5_ctx *ctx) { - return (win_crypto_init(ctx, CALG_MD5)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_MD5)); } static int @@ -434,7 +435,8 @@ __archive_ripemd160init(archive_rmd160_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_ripemd160()); + if (!EVP_DigestInit(*ctx, EVP_ripemd160())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -624,7 +626,8 @@ __archive_sha1init(archive_sha1_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_sha1()); + if (!EVP_DigestInit(*ctx, EVP_sha1())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -656,7 +659,7 @@ __archive_sha1final(archive_sha1_ctx *ctx, void *md) static int __archive_sha1init(archive_sha1_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA1)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_SHA1)); } static int @@ -887,7 +890,8 @@ __archive_sha256init(archive_sha256_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_sha256()); + if (!EVP_DigestInit(*ctx, EVP_sha256())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -915,7 +919,7 @@ __archive_sha256final(archive_sha256_ctx *ctx, void *md) static int __archive_sha256init(archive_sha256_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_256)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_256)); } static int @@ -1122,7 +1126,8 @@ __archive_sha384init(archive_sha384_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_sha384()); + if (!EVP_DigestInit(*ctx, EVP_sha384())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -1150,7 +1155,7 @@ __archive_sha384final(archive_sha384_ctx *ctx, void *md) static int __archive_sha384init(archive_sha384_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_384)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_384)); } static int @@ -1381,7 +1386,8 @@ __archive_sha512init(archive_sha512_ctx *ctx) { if ((*ctx = EVP_MD_CTX_new()) == NULL) return (ARCHIVE_FAILED); - EVP_DigestInit(*ctx, EVP_sha512()); + if (!EVP_DigestInit(*ctx, EVP_sha512())) + return (ARCHIVE_FAILED); return (ARCHIVE_OK); } @@ -1409,7 +1415,7 @@ __archive_sha512final(archive_sha512_ctx *ctx, void *md) static int __archive_sha512init(archive_sha512_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_512)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_512)); } static int diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c index ca7a4bd..ae6dc33 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry.c @@ -568,6 +568,13 @@ archive_entry_nlink(struct archive_entry *entry) return (entry->ae_stat.aest_nlink); } +/* Instead, our caller could have chosen a specific encoding + * (archive_mstring_get_mbs, archive_mstring_get_utf8, + * archive_mstring_get_wcs). So we should try multiple + * encodings. Try mbs first because of history, even though + * utf8 might be better for pathname portability. + * Also omit wcs because of type mismatch (char * versus wchar *) + */ const char * archive_entry_pathname(struct archive_entry *entry) { @@ -575,6 +582,13 @@ archive_entry_pathname(struct archive_entry *entry) if (archive_mstring_get_mbs( entry->archive, &entry->ae_pathname, &p) == 0) return (p); +#if HAVE_EILSEQ /*{*/ + if (errno == EILSEQ) { + if (archive_mstring_get_utf8( + entry->archive, &entry->ae_pathname, &p) == 0) + return (p); + } +#endif /*}*/ if (errno == ENOMEM) __archive_errx(1, "No memory"); return (NULL); diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h index 221ef80..91ef0c9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry.h @@ -30,7 +30,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3006000 +#define ARCHIVE_VERSION_NUMBER 3006002 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -122,6 +122,8 @@ typedef ssize_t la_ssize_t; # define __LA_DECL __declspec(dllimport) # endif # endif +#elif defined __LIBARCHIVE_ENABLE_VISIBILITY +# define __LA_DECL __attribute__((visibility("default"))) #else /* Static libraries on all platforms and shared libraries on non-Windows. */ # define __LA_DECL diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac.c b/Utilities/cmlibarchive/libarchive/archive_hmac.c index 2a9d04c..012fe15 100644 --- a/Utilities/cmlibarchive/libarchive/archive_hmac.c +++ b/Utilities/cmlibarchive/libarchive/archive_hmac.c @@ -230,10 +230,23 @@ __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) static int __hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + OSSL_PARAM params[2]; + + EVP_MAC *mac = EVP_MAC_fetch(NULL, "HMAC", NULL); + *ctx = EVP_MAC_CTX_new(mac); + if (*ctx == NULL) + return -1; + EVP_MAC_free(mac); + params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0); + params[1] = OSSL_PARAM_construct_end(); + EVP_MAC_init(*ctx, key, key_len, params); +#else *ctx = HMAC_CTX_new(); if (*ctx == NULL) return -1; HMAC_Init_ex(*ctx, key, key_len, EVP_sha1(), NULL); +#endif return 0; } @@ -241,22 +254,38 @@ static void __hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data, size_t data_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_update(*ctx, data, data_len); +#else HMAC_Update(*ctx, data, data_len); +#endif } static void __hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + size_t len = *out_len; +#else unsigned int len = (unsigned int)*out_len; +#endif +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_final(*ctx, out, &len, *out_len); +#else HMAC_Final(*ctx, out, &len); +#endif *out_len = len; } static void __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_CTX_free(*ctx); +#else HMAC_CTX_free(*ctx); +#endif *ctx = NULL; } diff --git a/Utilities/cmlibarchive/libarchive/archive_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h index 13a67d4..50044a0 100644 --- a/Utilities/cmlibarchive/libarchive/archive_hmac_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_hmac_private.h @@ -74,9 +74,16 @@ typedef mbedtls_md_context_t archive_hmac_sha1_ctx; typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx; #elif defined(HAVE_LIBCRYPTO) +#include <openssl/opensslv.h> +#include <openssl/hmac.h> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +typedef EVP_MAC_CTX *archive_hmac_sha1_ctx; + +#else #include "archive_openssl_hmac_private.h" typedef HMAC_CTX* archive_hmac_sha1_ctx; +#endif #else diff --git a/Utilities/cmlibarchive/libarchive/archive_platform.h b/Utilities/cmlibarchive/libarchive/archive_platform.h index f87b423..63b255e 100644 --- a/Utilities/cmlibarchive/libarchive/archive_platform.h +++ b/Utilities/cmlibarchive/libarchive/archive_platform.h @@ -188,8 +188,9 @@ /* * glibc 2.24 deprecates readdir_r + * bionic c deprecates readdir_r too */ -#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)) +#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)) && (!defined(__ANDROID__)) #define USE_READDIR_R 1 #else #undef USE_READDIR_R diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c index d0e1f35..5a94ec5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c @@ -34,9 +34,6 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef HAVE_SYS_MOUNT_H -#include <sys/mount.h> -#endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -54,6 +51,8 @@ __FBSDID("$FreeBSD$"); #endif #ifdef HAVE_LINUX_FS_H #include <linux/fs.h> +#elif HAVE_SYS_MOUNT_H +#include <sys/mount.h> #endif /* * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. @@ -109,6 +108,11 @@ __FBSDID("$FreeBSD$"); #define O_CLOEXEC 0 #endif +#if defined(__hpux) && !defined(HAVE_DIRFD) +#define dirfd(x) ((x)->__dd_fd) +#define HAVE_DIRFD +#endif + /*- * This is a new directory-walking system that addresses a number * of problems I've had with fts(3). In particular, it has no @@ -2098,6 +2102,8 @@ tree_push(struct tree *t, const char *path, int filesystem_id, struct tree_entry *te; te = calloc(1, sizeof(*te)); + if (te == NULL) + __archive_errx(1, "Out of memory"); te->next = t->stack; te->parent = t->current; if (te->parent) @@ -2428,7 +2434,7 @@ tree_dir_next_posix(struct tree *t) #else /* HAVE_FDOPENDIR */ if (tree_enter_working_dir(t) == 0) { t->d = opendir("."); -#if HAVE_DIRFD || defined(dirfd) +#ifdef HAVE_DIRFD __archive_ensure_cloexec_flag(dirfd(t->d)); #endif } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c index ea32e2a..f9d1395 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c @@ -418,8 +418,9 @@ la_linkname_from_pathw(const wchar_t *path, wchar_t **outbuf, int *linktype) FILE_FLAG_OPEN_REPARSE_POINT; int ret; - h = CreateFileW(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, flag, - NULL); + h = CreateFileW(path, 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, flag, NULL); if (h == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); return (-1); @@ -1073,7 +1074,9 @@ next_entry(struct archive_read_disk *a, struct tree *t, else flags |= FILE_FLAG_SEQUENTIAL_SCAN; t->entry_fh = CreateFileW(tree_current_access_path(t), - GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, flags, NULL); + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, flags, NULL); if (t->entry_fh == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); archive_set_error(&a->archive, errno, @@ -2046,7 +2049,8 @@ tree_current_file_information(struct tree *t, BY_HANDLE_FILE_INFORMATION *st, if (sim_lstat && tree_current_is_physical_link(t)) flag |= FILE_FLAG_OPEN_REPARSE_POINT; - h = CreateFileW(tree_current_access_path(t), 0, FILE_SHARE_READ, NULL, + h = CreateFileW(tree_current_access_path(t), 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, flag, NULL); if (h == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); @@ -2275,7 +2279,8 @@ archive_read_disk_entry_from_file(struct archive *_a, } else desiredAccess = GENERIC_READ; - h = CreateFileW(path, desiredAccess, FILE_SHARE_READ, NULL, + h = CreateFileW(path, desiredAccess, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, flag, NULL); if (h == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); @@ -2337,7 +2342,8 @@ archive_read_disk_entry_from_file(struct archive *_a, if (fd >= 0) { h = (HANDLE)_get_osfhandle(fd); } else { - h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, + h = CreateFileW(path, GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c index ae0b080..1e99542 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c @@ -450,7 +450,9 @@ lz4_filter_read_descriptor(struct archive_read_filter *self) chsum = (chsum >> 8) & 0xff; chsum_verifier = read_buf[descriptor_bytes-1] & 0xff; if (chsum != chsum_verifier) +#ifndef DONT_FAIL_ON_CRC_ERROR goto malformed_error; +#endif __archive_read_filter_consume(self->upstream, descriptor_bytes); @@ -521,7 +523,9 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p) unsigned int chsum_block = archive_le32dec(read_buf + 4 + compressed_size); if (chsum != chsum_block) +#ifndef DONT_FAIL_ON_CRC_ERROR goto malformed_error; +#endif } @@ -652,10 +656,12 @@ lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p) state->xxh32_state); state->xxh32_state = NULL; if (checksum != checksum_stream) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, "lz4 stream checksum error"); return (ARCHIVE_FATAL); +#endif } } else if (ret > 0) __archive_xxhash.XXH32_update(state->xxh32_state, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c index 42e2636..cc1572f 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lzop.c @@ -283,7 +283,9 @@ consume_header(struct archive_read_filter *self) else checksum = adler32(adler32(0, NULL, 0), p, len); if (archive_be32dec(p + len) != checksum) +#ifndef DONT_FAIL_ON_CRC_ERROR goto corrupted; +#endif __archive_read_filter_consume(self->upstream, len + 4); if (flags & EXTRA_FIELD) { /* Skip extra field */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c index b978eb0..90b0da2 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c @@ -612,9 +612,11 @@ lzip_tail(struct archive_read_filter *self) /* Check the crc32 value of the uncompressed data of the current * member */ if (state->crc32 != archive_le32dec(f)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, "Lzip: CRC32 error"); return (ARCHIVE_FAILED); +#endif } /* Check the uncompressed size of the current member */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c index 7d7e702..722edf1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c @@ -287,6 +287,7 @@ struct _7zip { const unsigned char *next_in; int64_t avail_in; int64_t total_in; + int64_t stream_in; unsigned char *next_out; int64_t avail_out; int64_t total_out; @@ -775,7 +776,7 @@ archive_read_format_7zip_read_header(struct archive_read *a, } /* Set up a more descriptive format name. */ - sprintf(zip->format_name, "7-Zip"); + snprintf(zip->format_name, sizeof(zip->format_name), "7-Zip"); a->archive.archive_format_name = zip->format_name; return (ret); @@ -986,15 +987,30 @@ ppmd_read(void *p) struct _7zip *zip = (struct _7zip *)(a->format->data); Byte b; - if (zip->ppstream.avail_in == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated RAR file data"); - zip->ppstream.overconsumed = 1; - return (0); + if (zip->ppstream.avail_in <= 0) { + /* + * Ppmd7_DecodeSymbol might require reading multiple bytes + * and we are on boundary; + * last resort to read using __archive_read_ahead. + */ + ssize_t bytes_avail = 0; + const uint8_t* data = __archive_read_ahead(a, + zip->ppstream.stream_in+1, &bytes_avail); + if(bytes_avail < zip->ppstream.stream_in+1) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7z file data"); + zip->ppstream.overconsumed = 1; + return (0); + } + zip->ppstream.next_in++; + b = data[zip->ppstream.stream_in]; + } else { + b = *zip->ppstream.next_in++; } - b = *zip->ppstream.next_in++; zip->ppstream.avail_in--; zip->ppstream.total_in++; + zip->ppstream.stream_in++; return (b); } @@ -1485,6 +1501,7 @@ decompress(struct archive_read *a, struct _7zip *zip, } zip->ppstream.next_in = t_next_in; zip->ppstream.avail_in = t_avail_in; + zip->ppstream.stream_in = 0; zip->ppstream.next_out = t_next_out; zip->ppstream.avail_out = t_avail_out; if (zip->ppmd7_stat == 0) { @@ -2840,8 +2857,10 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* CRC check. */ if (crc32(0, (const unsigned char *)p + 12, 20) != archive_le32dec(p + 8)) { +#ifdef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, -1, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } next_header_offset = archive_le64dec(p + 12); @@ -2891,8 +2910,10 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* Check the EncodedHeader CRC.*/ if (r == 0 && zip->header_crc32 != next_header_crc) { archive_set_error(&a->archive, -1, +#ifndef DONT_FAIL_ON_CRC_ERROR "Damaged 7-Zip archive"); r = -1; +#endif } if (r == 0) { if (zip->si.ci.folders[0].digest_defined) @@ -2943,9 +2964,11 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* Check the Header CRC.*/ if (check_header_crc && zip->header_crc32 != next_header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); return (ARCHIVE_FATAL); +#endif } break; default: diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c index 8742378..6fcfbfc 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c @@ -996,7 +996,7 @@ archive_read_format_cab_read_header(struct archive_read *a, cab->end_of_entry_cleanup = cab->end_of_entry = 1; /* Set up a more descriptive format name. */ - sprintf(cab->format_name, "CAB %d.%d (%s)", + snprintf(cab->format_name, sizeof(cab->format_name), "CAB %d.%d (%s)", hd->major, hd->minor, cab->entry_cffolder->compname); a->archive.archive_format_name = cab->format_name; @@ -1134,7 +1134,7 @@ cab_checksum_update(struct archive_read *a, size_t bytes) } if (sumbytes) { int odd = sumbytes & 3; - if (sumbytes - odd > 0) + if ((int)(sumbytes - odd) > 0) cfdata->sum_calculated = cab_checksum_cfdata_4( p, sumbytes - odd, cfdata->sum_calculated); if (odd) @@ -1171,12 +1171,14 @@ cab_checksum_finish(struct archive_read *a) cfdata->sum_calculated = cab_checksum_cfdata( cfdata->memimage + CFDATA_cbData, l, cfdata->sum_calculated); if (cfdata->sum_calculated != cfdata->sum) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Checksum error CFDATA[%d] %" PRIx32 ":%" PRIx32 " in %d bytes", cab->entry_cffolder->cfdata_index -1, cfdata->sum, cfdata->sum_calculated, cfdata->compressed_size); return (ARCHIVE_FAILED); +#endif } return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c index 9121166..380cbb8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c @@ -1007,7 +1007,8 @@ read_children(struct archive_read *a, struct file_info *parent) p = b; b += iso9660->logical_block_size; step -= iso9660->logical_block_size; - for (; *p != 0 && p < b && p + *p <= b; p += *p) { + for (; *p != 0 && p + DR_name_offset < b && p + *p <= b; + p += *p) { struct file_info *child; /* N.B.: these special directory identifiers @@ -1756,7 +1757,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent, size_t name_len; const unsigned char *rr_start, *rr_end; const unsigned char *p; - size_t dr_len; + size_t dr_len = 0; uint64_t fsize, offset; int32_t location; int flags; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c index 1357f9a..8b7bf66 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c @@ -739,7 +739,7 @@ archive_read_format_lha_read_header(struct archive_read *a, if (lha->directory || lha->compsize == 0) lha->end_of_entry = 1; - sprintf(lha->format_name, "lha -%c%c%c-", + snprintf(lha->format_name, sizeof(lha->format_name), "lha -%c%c%c-", lha->method[0], lha->method[1], lha->method[2]); a->archive.archive_format_name = lha->format_name; @@ -1039,9 +1039,11 @@ lha_read_file_header_2(struct archive_read *a, struct lha *lha) } if (header_crc != lha->header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "LHa header CRC error"); return (ARCHIVE_FATAL); +#endif } return (err); } @@ -1107,9 +1109,11 @@ lha_read_file_header_3(struct archive_read *a, struct lha *lha) return (err); if (header_crc != lha->header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "LHa header CRC error"); return (ARCHIVE_FATAL); +#endif } return (err); invalid: diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c index 88bca76..2bc3ba0 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c @@ -692,7 +692,7 @@ detect_form(struct archive_read *a, int *is_form_d) { const char *p; ssize_t avail, ravail; - ssize_t detected_bytes = 0, len, nl; + ssize_t len, nl; int entry_cnt = 0, multiline = 0; int form_D = 0;/* The archive is generated by `NetBSD mtree -D' * (In this source we call it `form D') . */ @@ -728,8 +728,6 @@ detect_form(struct archive_read *a, int *is_form_d) * character of previous line was '\' character. */ if (bid_keyword_list(p, len, 0, 0) <= 0) break; - if (multiline == 1) - detected_bytes += len; if (p[len-nl-1] != '\\') { if (multiline == 1 && ++entry_cnt >= MAX_BID_ENTRY) @@ -745,7 +743,6 @@ detect_form(struct archive_read *a, int *is_form_d) keywords = bid_entry(p, len, nl, &last_is_path); if (keywords >= 0) { - detected_bytes += len; if (form_D == 0) { if (last_is_path) form_D = 1; @@ -997,9 +994,11 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, struct mtree_entry *alt; alt = (struct mtree_entry *)__archive_rb_tree_find_node( &mtree->rbtree, entry->name); - while (alt->next_dup) - alt = alt->next_dup; - alt->next_dup = entry; + if (alt != NULL) { + while (alt->next_dup) + alt = alt->next_dup; + alt->next_dup = entry; + } } } @@ -1074,7 +1073,7 @@ read_mtree(struct archive_read *a, struct mtree *mtree) continue; /* Non-printable characters are not allowed */ for (s = p;s < p + len - 1; s++) { - if (!isprint((unsigned char)*s)) { + if (!isprint((unsigned char)*s) && *s != '\t') { r = ARCHIVE_FATAL; break; } @@ -1253,9 +1252,17 @@ parse_file(struct archive_read *a, struct archive_entry *entry, archive_entry_filetype(entry) == AE_IFDIR) { mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC); __archive_ensure_cloexec_flag(mtree->fd); - if (mtree->fd == -1 && - (errno != ENOENT || - archive_strlen(&mtree->contents_name) > 0)) { + if (mtree->fd == -1 && ( +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * On Windows, attempting to open a file with an + * invalid name result in EINVAL (Error 22) + */ + (errno != ENOENT && errno != EINVAL) +#else + errno != ENOENT +#endif + || archive_strlen(&mtree->contents_name) > 0)) { archive_set_error(&a->archive, errno, "Can't open %s", path); r = ARCHIVE_WARN; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c index 5c02a25..1c9a057 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c @@ -430,7 +430,7 @@ static int new_node(struct huffman_code *); static int make_table(struct archive_read *, struct huffman_code *); static int make_table_recurse(struct archive_read *, struct huffman_code *, int, struct huffman_table_entry *, int, int); -static int64_t expand(struct archive_read *, int64_t); +static int expand(struct archive_read *, int64_t *); static int copy_from_lzss_window_to_unp(struct archive_read *, const void **, int64_t, int); static const void *rar_read_ahead(struct archive_read *, size_t, ssize_t *); @@ -1007,9 +1007,11 @@ archive_read_format_rar_read_header(struct archive_read *a, crc32_val = crc32(0, (const unsigned char *)p + 2, (unsigned)skip - 2); if ((crc32_val & 0xffff) != archive_le16dec(p)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } __archive_read_consume(a, skip); break; @@ -1065,9 +1067,11 @@ archive_read_format_rar_read_header(struct archive_read *a, skip -= to_read; } if ((crc32_val & 0xffff) != crc32_expected) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } if (head_type == ENDARC_HEAD) return (ARCHIVE_EOF); @@ -1432,9 +1436,11 @@ read_header(struct archive_read *a, struct archive_entry *entry, /* File Header CRC check. */ crc32_val = crc32(crc32_val, h, (unsigned)(header_size - 7)); if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } /* If no CRC error, Go on parsing File Header. */ p = h; @@ -1952,9 +1958,11 @@ read_data_stored(struct archive_read *a, const void **buff, size_t *size, *size = 0; *offset = rar->offset; if (rar->file_crc != rar->crc_calculated) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "File CRC error"); return (ARCHIVE_FATAL); +#endif } rar->entry_eof = 1; return (ARCHIVE_EOF); @@ -1988,7 +1996,7 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, return (ARCHIVE_FATAL); struct rar *rar; - int64_t start, end, actualend; + int64_t start, end; size_t bs; int ret = (ARCHIVE_OK), sym, code, lzss_offset, length, i; @@ -2045,9 +2053,11 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, *size = 0; *offset = rar->offset; if (rar->file_crc != rar->crc_calculated) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "File CRC error"); return (ARCHIVE_FATAL); +#endif } rar->entry_eof = 1; return (ARCHIVE_EOF); @@ -2179,11 +2189,12 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, end = rar->filters.filterstart; } - if ((actualend = expand(a, end)) < 0) - return ((int)actualend); + ret = expand(a, &end); + if (ret != ARCHIVE_OK) + return (ret); - rar->bytes_uncopied = actualend - start; - rar->filters.lastend = actualend; + rar->bytes_uncopied = end - start; + rar->filters.lastend = end; if (rar->filters.lastend != rar->filters.filterstart && rar->bytes_uncopied == 0) { /* Broken RAR files cause this case. * NOTE: If this case were possible on a normal RAR file @@ -2825,8 +2836,8 @@ make_table_recurse(struct archive_read *a, struct huffman_code *code, int node, return ret; } -static int64_t -expand(struct archive_read *a, int64_t end) +static int +expand(struct archive_read *a, int64_t *end) { static const unsigned char lengthbases[] = { 0, 1, 2, 3, 4, 5, 6, @@ -2873,16 +2884,19 @@ expand(struct archive_read *a, int64_t end) struct rar *rar = (struct rar *)(a->format->data); struct rar_br *br = &(rar->br); - if (rar->filters.filterstart < end) - end = rar->filters.filterstart; + if (rar->filters.filterstart < *end) + *end = rar->filters.filterstart; while (1) { - if(lzss_position(&rar->lzss) >= end) - return end; + if(lzss_position(&rar->lzss) >= *end) { + return (ARCHIVE_OK); + } - if(rar->is_ppmd_block) - return lzss_position(&rar->lzss); + if(rar->is_ppmd_block) { + *end = lzss_position(&rar->lzss); + return (ARCHIVE_OK); + } if ((symbol = read_next_symbol(a, &rar->maincode)) < 0) return (ARCHIVE_FATAL); @@ -2906,7 +2920,8 @@ expand(struct archive_read *a, int64_t end) goto truncated_data; rar->start_new_table = rar_br_bits(br, 1); rar_br_consume(br, 1); - return lzss_position(&rar->lzss); + *end = lzss_position(&rar->lzss); + return (ARCHIVE_OK); } else { @@ -2917,7 +2932,7 @@ expand(struct archive_read *a, int64_t end) } else if(symbol==257) { - if (!read_filter(a, &end)) + if (!read_filter(a, end)) return (ARCHIVE_FATAL); continue; } @@ -3323,14 +3338,43 @@ run_filters(struct archive_read *a) struct rar *rar = (struct rar *)(a->format->data); struct rar_filters *filters = &rar->filters; struct rar_filter *filter = filters->stack; - size_t start = filters->filterstart; - size_t end = start + filter->blocklength; + struct rar_filter *f; + size_t start, end; + int64_t tend; uint32_t lastfilteraddress; uint32_t lastfilterlength; int ret; + if (filters == NULL || filter == NULL) + return (0); + + start = filters->filterstart; + end = start + filter->blocklength; + filters->filterstart = INT64_MAX; - end = (size_t)expand(a, end); + tend = (int64_t)end; + ret = expand(a, &tend); + if (ret != ARCHIVE_OK) + return 0; + + /* Check if filter stack was modified in expand() */ + ret = ARCHIVE_FATAL; + f = filters->stack; + while (f) + { + if (f == filter) + { + ret = ARCHIVE_OK; + break; + } + f = f->next; + } + if (ret != ARCHIVE_OK) + return 0; + + if (tend < 0) + return 0; + end = (size_t)tend; if (end != start + filter->blocklength) return 0; diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c index 8850c93..548da4e 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar5.c @@ -2821,11 +2821,13 @@ static int parse_block_header(struct archive_read* a, const uint8_t* p, ^ (uint8_t) (*block_size >> 16); if(calculated_cksum != hdr->block_cksum) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Block checksum error: got 0x%x, expected 0x%x", hdr->block_cksum, calculated_cksum); return ARCHIVE_FATAL; +#endif } return ARCHIVE_OK; @@ -3911,6 +3913,13 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, case GOOD: /* fallthrough */ case BEST: + /* No data is returned here. But because a sparse-file aware + * caller (like archive_read_data_into_fd) may treat zero-size + * as a sparse file block, we need to update the offset + * accordingly. At this point the decoder doesn't have any + * pending uncompressed data blocks, so the current position in + * the output file should be last_write_ptr. */ + if (offset) *offset = rar->cstate.last_write_ptr; return uncompress_file(a); default: archive_set_error(&a->archive, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c index bfdad7f..93c3fd5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c @@ -407,14 +407,13 @@ archive_read_format_tar_bid(struct archive_read *a, int best_bid) /* * Check format of mode/uid/gid/mtime/size/rdevmajor/rdevminor fields. */ - if (bid > 0 && ( - validate_number_field(header->mode, sizeof(header->mode)) == 0 + if (validate_number_field(header->mode, sizeof(header->mode)) == 0 || validate_number_field(header->uid, sizeof(header->uid)) == 0 || validate_number_field(header->gid, sizeof(header->gid)) == 0 || validate_number_field(header->mtime, sizeof(header->mtime)) == 0 || validate_number_field(header->size, sizeof(header->size)) == 0 || validate_number_field(header->rdevmajor, sizeof(header->rdevmajor)) == 0 - || validate_number_field(header->rdevminor, sizeof(header->rdevminor)) == 0)) { + || validate_number_field(header->rdevminor, sizeof(header->rdevminor)) == 0) { bid = 0; } @@ -2108,6 +2107,21 @@ pax_attribute(struct archive_read *a, struct tar *tar, /* "size" is the size of the data in the entry. */ tar->entry_bytes_remaining = tar_atol10(value, strlen(value)); + if (tar->entry_bytes_remaining < 0) { + tar->entry_bytes_remaining = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Tar size attribute is negative"); + return (ARCHIVE_FATAL); + } + if (tar->entry_bytes_remaining == INT64_MAX) { + /* Note: tar_atol returns INT64_MAX on overflow */ + tar->entry_bytes_remaining = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Tar size attribute overflow"); + return (ARCHIVE_FATAL); + } /* * The "size" pax header keyword always overrides the * "size" field in the tar header. diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c index 2e60cf7..330df58 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c @@ -624,7 +624,9 @@ read_toc(struct archive_read *a) __archive_read_consume(a, xar->toc_chksum_size); xar->offset += xar->toc_chksum_size; if (r != ARCHIVE_OK) +#ifndef DONT_FAIL_ON_CRC_ERROR return (ARCHIVE_FATAL); +#endif } /* @@ -827,10 +829,12 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry) xattr->a_sum.val, xattr->a_sum.len, xattr->e_sum.val, xattr->e_sum.len); if (r != ARCHIVE_OK) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, "Xattr checksum error"); r = ARCHIVE_WARN; break; +#endif } if (xattr->name.s == NULL) { archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c index 8ad73b6..e126ae3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c @@ -1667,7 +1667,7 @@ zipx_lzma_alone_init(struct archive_read *a, struct zip *zip) */ /* Read magic1,magic2,lzma_params from the ZIPX stream. */ - if((p = __archive_read_ahead(a, 9, NULL)) == NULL) { + if(zip->entry_bytes_remaining < 9 || (p = __archive_read_ahead(a, 9, NULL)) == NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Truncated lzma data"); return (ARCHIVE_FATAL); diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c index d7f2c46..69458e1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.c +++ b/Utilities/cmlibarchive/libarchive/archive_string.c @@ -3988,10 +3988,10 @@ int archive_mstring_get_mbs_l(struct archive *a, struct archive_mstring *aes, const char **p, size_t *length, struct archive_string_conv *sc) { - int r, ret = 0; - - (void)r; /* UNUSED */ + int ret = 0; #if defined(_WIN32) && !defined(__CYGWIN__) + int r; + /* * Internationalization programming on Windows must use Wide * characters because Windows platform cannot make locale UTF-8. diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c index 66592e8..27626b5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write.c +++ b/Utilities/cmlibarchive/libarchive/archive_write.c @@ -201,6 +201,10 @@ __archive_write_allocate_filter(struct archive *_a) struct archive_write_filter *f; f = calloc(1, sizeof(*f)); + + if (f == NULL) + return (NULL); + f->archive = _a; f->state = ARCHIVE_WRITE_FILTER_STATE_NEW; if (a->filter_first == NULL) @@ -548,6 +552,10 @@ archive_write_open2(struct archive *_a, void *client_data, a->client_data = client_data; client_filter = __archive_write_allocate_filter(_a); + + if (client_filter == NULL) + return (ARCHIVE_FATAL); + client_filter->open = archive_write_client_open; client_filter->write = archive_write_client_write; client_filter->close = archive_write_client_close; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c index b6d3d0a..bd5180e 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c @@ -1996,6 +1996,8 @@ archive_write_disk_new(void) free(a); return (NULL); } + a->path_safe.s[0] = 0; + #ifdef HAVE_ZLIB_H a->decmpfs_compression_level = 5; #endif @@ -2793,7 +2795,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, char *tail; char *head; int last; - char c; + char c = '\0'; int r; struct stat st; int chdir_fd; diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c index 1b12a29..88df3ce 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c @@ -1370,6 +1370,7 @@ archive_write_disk_new(void) free(a); return (NULL); } + a->path_safe.s[0] = 0; return (&a->archive); } @@ -2154,6 +2155,8 @@ check_symlinks(struct archive_write_disk *a) return (ARCHIVE_FAILED); } } + if (!c) + break; pn[0] = c; pn++; } @@ -2258,6 +2261,9 @@ cleanup_pathname(struct archive_write_disk *a, wchar_t *name) return (ARCHIVE_FAILED); } else p += 4; + /* Network drive path like "\\<server-name>\<share-name>\file" */ + } else if (p[0] == L'\\' && p[1] == L'\\') { + p += 2; } /* Skip leading drive letter from archives created diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open.3 b/Utilities/cmlibarchive/libarchive/archive_write_open.3 index 29bffe4..6bceb96 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_open.3 @@ -218,6 +218,7 @@ On failure, the callback should invoke .Fn archive_set_error to register an error code and message and return +.Cm ARCHIVE_FATAL . .Bl -item -offset indent .It .Ft typedef int diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c index 5291149..cf1f477 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c @@ -1717,7 +1717,7 @@ build_pax_attribute_name(char *dest, const char *src) * to having clients override it. */ #if HAVE_GETPID && 0 /* Disable this for now; see above comment. */ - sprintf(buff, "PaxHeader.%d", getpid()); + snprintf(buff, sizeof(buff), "PaxHeader.%d", getpid()); #else /* If the platform can't fetch the pid, don't include it. */ strcpy(buff, "PaxHeader"); diff --git a/Utilities/cmlibarchive/libarchive/cpio.5 b/Utilities/cmlibarchive/libarchive/cpio.5 index 837a456..c71018b 100644 --- a/Utilities/cmlibarchive/libarchive/cpio.5 +++ b/Utilities/cmlibarchive/libarchive/cpio.5 @@ -354,7 +354,7 @@ while working in AT&T's Unix Support Group. It appeared in 1977 as part of PWB/UNIX 1.0, the .Dq Programmer's Work Bench derived from -.At 6th Edition UNIX +.At v6 that was used internally at AT&T. Both the new binary and old character formats were in use by 1980, according to the System III source released diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_posix.c b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c index ac255c4..62085a7 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork_posix.c +++ b/Utilities/cmlibarchive/libarchive/filter_fork_posix.c @@ -76,7 +76,7 @@ int __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, pid_t *out_child) { - pid_t child; + pid_t child = -1; int stdin_pipe[2], stdout_pipe[2], tmp; #if HAVE_POSIX_SPAWNP posix_spawn_file_actions_t actions; |