diff --git a/libarchive-clib/c/archive.h b/libarchive-clib/c/archive.h index a18b81f..fd4dd20 100644 --- a/libarchive-clib/c/archive.h +++ b/libarchive-clib/c/archive.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/lib/libarchive/archive.h.in,v 1.50 2008/05/26 17:00:22 kientzle Exp $ */ #ifndef ARCHIVE_H_INCLUDED @@ -36,7 +34,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3007002 +#define ARCHIVE_VERSION_NUMBER 3007004 #include #include /* for wchar_t */ @@ -157,7 +155,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.7.2" +#define ARCHIVE_VERSION_ONLY_STRING "3.7.4" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); @@ -535,6 +533,10 @@ __LA_DECL int archive_read_open_filenames(struct archive *, const char **_filenames, size_t _block_size); __LA_DECL int archive_read_open_filename_w(struct archive *, const wchar_t *_filename, size_t _block_size); +#if defined(_WIN32) && !defined(__CYGWIN__) +__LA_DECL int archive_read_open_filenames_w(struct archive *, + const wchar_t **_filenames, size_t _block_size); +#endif /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ __LA_DECL int archive_read_open_file(struct archive *, const char *_filename, size_t _block_size) __LA_DEPRECATED; @@ -893,7 +895,7 @@ __LA_DECL int archive_write_set_options(struct archive *_a, const char *opts); /* - * Set a encryption passphrase. + * Set an encryption passphrase. */ __LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p); __LA_DECL int archive_write_set_passphrase_callback(struct archive *, diff --git a/libarchive-clib/c/archive_acl.c b/libarchive-clib/c/archive_acl.c index ead7e36..254324c 100644 --- a/libarchive-clib/c/archive_acl.c +++ b/libarchive-clib/c/archive_acl.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_acl_private.h b/libarchive-clib/c/archive_acl_private.h index af10816..750b4dd 100644 --- a/libarchive-clib/c/archive_acl_private.h +++ b/libarchive-clib/c/archive_acl_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_ACL_PRIVATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_check_magic.c b/libarchive-clib/c/archive_check_magic.c index 1f40072..d12f0c4 100644 --- a/libarchive-clib/c/archive_check_magic.c +++ b/libarchive-clib/c/archive_check_magic.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_check_magic.c 201089 2009-12-28 02:20:23Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -62,7 +61,7 @@ errmsg(const char *m) } } -static __LA_DEAD void +static __LA_NORETURN void diediedie(void) { #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) @@ -99,13 +98,12 @@ archive_handle_type_name(unsigned m) } } - -static char * +static void write_all_states(char *buff, unsigned int states) { unsigned int lowbit; - buff[0] = '\0'; + *buff = '\0'; /* A trick for computing the lowest set bit. */ while ((lowbit = states & (1 + ~states)) != 0) { @@ -114,7 +112,6 @@ write_all_states(char *buff, unsigned int states) if (states != 0) strcat(buff, "/"); } - return buff; } /* @@ -160,16 +157,19 @@ __archive_check_magic(struct archive *a, unsigned int magic, if ((a->state & state) == 0) { /* If we're already FATAL, don't overwrite the error. */ - if (a->state != ARCHIVE_STATE_FATAL) + if (a->state != ARCHIVE_STATE_FATAL) { + write_all_states(states1, a->state); + write_all_states(states2, state); archive_set_error(a, -1, "INTERNAL ERROR: Function '%s' invoked with" " archive structure in state '%s'," " should be in state '%s'", function, - write_all_states(states1, a->state), - write_all_states(states2, state)); + states1, + states2); + } a->state = ARCHIVE_STATE_FATAL; return (ARCHIVE_FATAL); } - return ARCHIVE_OK; + return (ARCHIVE_OK); } diff --git a/libarchive-clib/c/archive_cmdline.c b/libarchive-clib/c/archive_cmdline.c index 5c519cd..2e5428c 100644 --- a/libarchive-clib/c/archive_cmdline.c +++ b/libarchive-clib/c/archive_cmdline.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_STRING_H # include #endif diff --git a/libarchive-clib/c/archive_cmdline_private.h b/libarchive-clib/c/archive_cmdline_private.h index 57a1949..7495dfe 100644 --- a/libarchive-clib/c/archive_cmdline_private.h +++ b/libarchive-clib/c/archive_cmdline_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_CMDLINE_PRIVATE_H diff --git a/libarchive-clib/c/archive_crc32.h b/libarchive-clib/c/archive_crc32.h index 4f1aed3..98a4e2c 100644 --- a/libarchive-clib/c/archive_crc32.h +++ b/libarchive-clib/c/archive_crc32.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_crc32.h 201102 2009-12-28 03:11:36Z kientzle $ */ #ifndef ARCHIVE_CRC32_H diff --git a/libarchive-clib/c/archive_cryptor.c b/libarchive-clib/c/archive_cryptor.c index 112baf1..437dba0 100644 --- a/libarchive-clib/c/archive_cryptor.c +++ b/libarchive-clib/c/archive_cryptor.c @@ -424,8 +424,8 @@ static int aes_ctr_release(archive_crypto_ctx *ctx) { EVP_CIPHER_CTX_free(ctx->ctx); - memset(ctx->key, 0, ctx->key_len); - memset(ctx->nonce, 0, sizeof(ctx->nonce)); + OPENSSL_cleanse(ctx->key, ctx->key_len); + OPENSSL_cleanse(ctx->nonce, sizeof(ctx->nonce)); return 0; } diff --git a/libarchive-clib/c/archive_endian.h b/libarchive-clib/c/archive_endian.h index e6d3f2c..83b2efa 100644 --- a/libarchive-clib/c/archive_endian.h +++ b/libarchive-clib/c/archive_endian.h @@ -23,8 +23,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libarchive/archive_endian.h 201085 2009-12-28 02:17:15Z kientzle $ - * * Borrowed from FreeBSD's */ diff --git a/libarchive-clib/c/archive_entry.c b/libarchive-clib/c/archive_entry.c index ae6dc33..9463233 100644 --- a/libarchive-clib/c/archive_entry.c +++ b/libarchive-clib/c/archive_entry.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry.c 201096 2009-12-28 02:41:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -372,6 +371,12 @@ archive_entry_filetype(struct archive_entry *entry) return (AE_IFMT & entry->acl.mode); } +int +archive_entry_filetype_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_FILETYPE); +} + void archive_entry_fflags(struct archive_entry *entry, unsigned long *set, unsigned long *clear) @@ -425,6 +430,12 @@ archive_entry_gid(struct archive_entry *entry) return (entry->ae_stat.aest_gid); } +int +archive_entry_gid_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_GID); +} + const char * archive_entry_gname(struct archive_entry *entry) { @@ -631,6 +642,12 @@ archive_entry_perm(struct archive_entry *entry) return (~AE_IFMT & entry->acl.mode); } +int +archive_entry_perm_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_PERM); +} + dev_t archive_entry_rdev(struct archive_entry *entry) { @@ -759,6 +776,12 @@ archive_entry_uid(struct archive_entry *entry) return (entry->ae_stat.aest_uid); } +int +archive_entry_uid_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_UID); +} + const char * archive_entry_uname(struct archive_entry *entry) { @@ -827,6 +850,7 @@ archive_entry_set_filetype(struct archive_entry *entry, unsigned int type) entry->stat_valid = 0; entry->acl.mode &= ~AE_IFMT; entry->acl.mode |= AE_IFMT & type; + entry->ae_set |= AE_SET_FILETYPE; } void @@ -861,6 +885,7 @@ archive_entry_set_gid(struct archive_entry *entry, la_int64_t g) { entry->stat_valid = 0; entry->ae_stat.aest_gid = g; + entry->ae_set |= AE_SET_GID; } void @@ -1145,6 +1170,7 @@ archive_entry_set_mode(struct archive_entry *entry, mode_t m) { entry->stat_valid = 0; entry->acl.mode = m; + entry->ae_set |= AE_SET_PERM | AE_SET_FILETYPE; } void @@ -1220,6 +1246,7 @@ archive_entry_set_perm(struct archive_entry *entry, mode_t p) entry->stat_valid = 0; entry->acl.mode &= AE_IFMT; entry->acl.mode |= ~AE_IFMT & p; + entry->ae_set |= AE_SET_PERM; } void @@ -1354,6 +1381,7 @@ archive_entry_set_uid(struct archive_entry *entry, la_int64_t u) { entry->stat_valid = 0; entry->ae_stat.aest_uid = u; + entry->ae_set |= AE_SET_UID; } void diff --git a/libarchive-clib/c/archive_entry.h b/libarchive-clib/c/archive_entry.h index e4c0ab3..1c59ded 100644 --- a/libarchive-clib/c/archive_entry.h +++ b/libarchive-clib/c/archive_entry.h @@ -22,15 +22,13 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_entry.h 201096 2009-12-28 02:41:27Z kientzle $ */ #ifndef ARCHIVE_ENTRY_H_INCLUDED #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3007002 +#define ARCHIVE_VERSION_NUMBER 3007004 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -251,11 +249,13 @@ __LA_DECL int archive_entry_dev_is_set(struct archive_entry *); __LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); __LA_DECL dev_t archive_entry_devminor(struct archive_entry *); __LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); +__LA_DECL int archive_entry_filetype_is_set(struct archive_entry *); __LA_DECL void archive_entry_fflags(struct archive_entry *, unsigned long * /* set */, unsigned long * /* clear */); __LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); __LA_DECL la_int64_t archive_entry_gid(struct archive_entry *); +__LA_DECL int archive_entry_gid_is_set(struct archive_entry *); __LA_DECL const char *archive_entry_gname(struct archive_entry *); __LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); @@ -274,6 +274,7 @@ __LA_DECL const char *archive_entry_pathname(struct archive_entry *); __LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); __LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *); +__LA_DECL int archive_entry_perm_is_set(struct archive_entry *); __LA_DECL dev_t archive_entry_rdev(struct archive_entry *); __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); __LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); @@ -287,6 +288,7 @@ __LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *); __LA_DECL int archive_entry_symlink_type(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); __LA_DECL la_int64_t archive_entry_uid(struct archive_entry *); +__LA_DECL int archive_entry_uid_is_set(struct archive_entry *); __LA_DECL const char *archive_entry_uname(struct archive_entry *); __LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *); __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); diff --git a/libarchive-clib/c/archive_entry_copy_bhfi.c b/libarchive-clib/c/archive_entry_copy_bhfi.c index 77bf38e..d5317a5 100644 --- a/libarchive-clib/c/archive_entry_copy_bhfi.c +++ b/libarchive-clib/c/archive_entry_copy_bhfi.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive_private.h" #include "archive_entry.h" diff --git a/libarchive-clib/c/archive_entry_copy_stat.c b/libarchive-clib/c/archive_entry_copy_stat.c index ac83868..f9c2e84 100644 --- a/libarchive-clib/c/archive_entry_copy_stat.c +++ b/libarchive-clib/c/archive_entry_copy_stat.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_copy_stat.c 189466 2009-03-07 00:52:02Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_entry_link_resolver.c b/libarchive-clib/c/archive_entry_link_resolver.c index c7d5949..6c61734 100644 --- a/libarchive-clib/c/archive_entry_link_resolver.c +++ b/libarchive-clib/c/archive_entry_link_resolver.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_link_resolver.c 201100 2009-12-28 03:05:31Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_entry_locale.h b/libarchive-clib/c/archive_entry_locale.h index 803c036..1b90c57 100644 --- a/libarchive-clib/c/archive_entry_locale.h +++ b/libarchive-clib/c/archive_entry_locale.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_ENTRY_LOCALE_H_INCLUDED diff --git a/libarchive-clib/c/archive_entry_private.h b/libarchive-clib/c/archive_entry_private.h index cf4deb2..3423966 100644 --- a/libarchive-clib/c/archive_entry_private.h +++ b/libarchive-clib/c/archive_entry_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_entry_private.h 201096 2009-12-28 02:41:27Z kientzle $ */ #ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED @@ -147,6 +145,10 @@ struct archive_entry { #define AE_SET_SIZE 64 #define AE_SET_INO 128 #define AE_SET_DEV 256 +#define AE_SET_PERM 512 +#define AE_SET_FILETYPE 1024 +#define AE_SET_UID 2048 +#define AE_SET_GID 4096 /* * Use aes here so that we get transparent mbs<->wcs conversions. diff --git a/libarchive-clib/c/archive_entry_sparse.c b/libarchive-clib/c/archive_entry_sparse.c index 74917b3..b81684d 100644 --- a/libarchive-clib/c/archive_entry_sparse.c +++ b/libarchive-clib/c/archive_entry_sparse.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_entry.h" diff --git a/libarchive-clib/c/archive_entry_stat.c b/libarchive-clib/c/archive_entry_stat.c index 71a407b..c490683 100644 --- a/libarchive-clib/c/archive_entry_stat.c +++ b/libarchive-clib/c/archive_entry_stat.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_stat.c 201100 2009-12-28 03:05:31Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_entry_strmode.c b/libarchive-clib/c/archive_entry_strmode.c index af2517a..5faa2fa 100644 --- a/libarchive-clib/c/archive_entry_strmode.c +++ b/libarchive-clib/c/archive_entry_strmode.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_strmode.c,v 1.4 2008/06/15 05:14:01 kientzle Exp $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_entry_xattr.c b/libarchive-clib/c/archive_entry_xattr.c index 5fe726b..14848a5 100644 --- a/libarchive-clib/c/archive_entry_xattr.c +++ b/libarchive-clib/c/archive_entry_xattr.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_xattr.c 201096 2009-12-28 02:41:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_getdate.c b/libarchive-clib/c/archive_getdate.c index 20ab1b1..69eebb0 100644 --- a/libarchive-clib/c/archive_getdate.c +++ b/libarchive-clib/c/archive_getdate.c @@ -28,10 +28,6 @@ */ #include "archive_platform.h" -#ifdef __FreeBSD__ -#include -__FBSDID("$FreeBSD$"); -#endif #include #include diff --git a/libarchive-clib/c/archive_getdate.h b/libarchive-clib/c/archive_getdate.h index 900a8f6..cfd49dd 100644 --- a/libarchive-clib/c/archive_getdate.h +++ b/libarchive-clib/c/archive_getdate.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_GETDATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_match.c b/libarchive-clib/c/archive_match.c index 04747b1..fc8a4ce 100644 --- a/libarchive-clib/c/archive_match.c +++ b/libarchive-clib/c/archive_match.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_options.c b/libarchive-clib/c/archive_options.c index 6496025..92647c9 100644 --- a/libarchive-clib/c/archive_options.c +++ b/libarchive-clib/c/archive_options.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_options_private.h b/libarchive-clib/c/archive_options_private.h index 9a7f808..3e49222 100644 --- a/libarchive-clib/c/archive_options_private.h +++ b/libarchive-clib/c/archive_options_private.h @@ -27,8 +27,6 @@ #define ARCHIVE_OPTIONS_PRIVATE_H_INCLUDED #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #include "archive_private.h" typedef int (*option_handler)(struct archive *a, diff --git a/libarchive-clib/c/archive_pack_dev.c b/libarchive-clib/c/archive_pack_dev.c index d95444d..3c6209b 100644 --- a/libarchive-clib/c/archive_pack_dev.c +++ b/libarchive-clib/c/archive_pack_dev.c @@ -33,13 +33,6 @@ #include "archive_platform.h" -#if HAVE_SYS_CDEFS_H -#include -#endif -#if !defined(lint) -__RCSID("$NetBSD$"); -#endif /* not lint */ - #ifdef HAVE_LIMITS_H #include #endif diff --git a/libarchive-clib/c/archive_pathmatch.c b/libarchive-clib/c/archive_pathmatch.c index 0867a26..19e0889 100644 --- a/libarchive-clib/c/archive_pathmatch.c +++ b/libarchive-clib/c/archive_pathmatch.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_STRING_H #include diff --git a/libarchive-clib/c/archive_pathmatch.h b/libarchive-clib/c/archive_pathmatch.h index 9995142..3f406ff 100644 --- a/libarchive-clib/c/archive_pathmatch.h +++ b/libarchive-clib/c/archive_pathmatch.h @@ -22,8 +22,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_PATHMATCH_H diff --git a/libarchive-clib/c/archive_platform.h b/libarchive-clib/c/archive_platform.h index 1038932..24e8b50 100644 --- a/libarchive-clib/c/archive_platform.h +++ b/libarchive-clib/c/archive_platform.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_platform.h 201090 2009-12-28 02:22:04Z kientzle $ */ /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ @@ -87,19 +85,6 @@ * headers as required. */ -/* Get a real definition for __FBSDID or __RCSID if we can */ -#if HAVE_SYS_CDEFS_H -#include -#endif - -/* If not, define them so as to avoid dangling semicolons. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif -#ifndef __RCSID -#define __RCSID(a) struct _undefined_hack -#endif - /* Try to get standard C99-style integer type definitions. */ #if HAVE_INTTYPES_H #include diff --git a/libarchive-clib/c/archive_platform_acl.h b/libarchive-clib/c/archive_platform_acl.h index 264e6de..48556f8 100644 --- a/libarchive-clib/c/archive_platform_acl.h +++ b/libarchive-clib/c/archive_platform_acl.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ diff --git a/libarchive-clib/c/archive_platform_xattr.h b/libarchive-clib/c/archive_platform_xattr.h index ad4b90a..2ae222f 100644 --- a/libarchive-clib/c/archive_platform_xattr.h +++ b/libarchive-clib/c/archive_platform_xattr.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ diff --git a/libarchive-clib/c/archive_private.h b/libarchive-clib/c/archive_private.h index b2a2cda..0f05169 100644 --- a/libarchive-clib/c/archive_private.h +++ b/libarchive-clib/c/archive_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_private.h 201098 2009-12-28 02:58:14Z kientzle $ */ #ifndef ARCHIVE_PRIVATE_H_INCLUDED @@ -40,10 +38,12 @@ #include "archive_string.h" #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_NORETURN __attribute__((__noreturn__)) +#elif defined(_MSC_VER) +#define __LA_NORETURN __declspec(noreturn) #else -#define __LA_DEAD +#define __LA_NORETURN #endif #if defined(__GNUC__) && (__GNUC__ > 2 || \ @@ -153,7 +153,7 @@ int __archive_check_magic(struct archive *, unsigned int magic, return ARCHIVE_FATAL; \ } while (0) -void __archive_errx(int retvalue, const char *msg) __LA_DEAD; +__LA_NORETURN void __archive_errx(int retvalue, const char *msg); void __archive_ensure_cloexec_flag(int fd); int __archive_mktemp(const char *tmpdir); diff --git a/libarchive-clib/c/archive_random.c b/libarchive-clib/c/archive_random.c index a410dc0..8c48d2d 100644 --- a/libarchive-clib/c/archive_random.c +++ b/libarchive-clib/c/archive_random.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_STDLIB_H #include diff --git a/libarchive-clib/c/archive_read.c b/libarchive-clib/c/archive_read.c index 45a38ae..d71fc2b 100644 --- a/libarchive-clib/c/archive_read.c +++ b/libarchive-clib/c/archive_read.c @@ -32,7 +32,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read.c 201157 2009-12-29 05:30:23Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_add_passphrase.c b/libarchive-clib/c/archive_read_add_passphrase.c index f0b1ab9..c67d1df 100644 --- a/libarchive-clib/c/archive_read_add_passphrase.c +++ b/libarchive-clib/c/archive_read_add_passphrase.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_append_filter.c b/libarchive-clib/c/archive_read_append_filter.c index 25dc4b2..74eead8 100644 --- a/libarchive-clib/c/archive_read_append_filter.c +++ b/libarchive-clib/c/archive_read_append_filter.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_data_into_fd.c b/libarchive-clib/c/archive_read_data_into_fd.c index f16ca5c..8fd5e12 100644 --- a/libarchive-clib/c/archive_read_data_into_fd.c +++ b/libarchive-clib/c/archive_read_data_into_fd.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_data_into_fd.c,v 1.16 2008/05/23 05:01:29 cperciva Exp $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_read_disk_entry_from_file.c b/libarchive-clib/c/archive_read_disk_entry_from_file.c index ab0270b..d89f435 100644 --- a/libarchive-clib/c/archive_read_disk_entry_from_file.c +++ b/libarchive-clib/c/archive_read_disk_entry_from_file.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD"); /* This is the tree-walking code for POSIX systems. */ #if !defined(_WIN32) || defined(__CYGWIN__) diff --git a/libarchive-clib/c/archive_read_disk_posix.c b/libarchive-clib/c/archive_read_disk_posix.c index 8d5c32f..76a4fa4 100644 --- a/libarchive-clib/c/archive_read_disk_posix.c +++ b/libarchive-clib/c/archive_read_disk_posix.c @@ -29,7 +29,6 @@ #if !defined(_WIN32) || defined(__CYGWIN__) #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_PARAM_H #include diff --git a/libarchive-clib/c/archive_read_disk_private.h b/libarchive-clib/c/archive_read_disk_private.h index bc8abc1..cf8da99 100644 --- a/libarchive-clib/c/archive_read_disk_private.h +++ b/libarchive-clib/c/archive_read_disk_private.h @@ -22,8 +22,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_read_disk_private.h 201105 2009-12-28 03:20:54Z kientzle $ */ #ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_read_disk_set_standard_lookup.c b/libarchive-clib/c/archive_read_disk_set_standard_lookup.c index c7fd247..3512d34 100644 --- a/libarchive-clib/c/archive_read_disk_set_standard_lookup.c +++ b/libarchive-clib/c/archive_read_disk_set_standard_lookup.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_set_standard_lookup.c 201109 2009-12-28 03:30:31Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_read_disk_windows.c b/libarchive-clib/c/archive_read_disk_windows.c index f92a78a..6b551f4 100644 --- a/libarchive-clib/c/archive_read_disk_windows.c +++ b/libarchive-clib/c/archive_read_disk_windows.c @@ -25,7 +25,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #if defined(_WIN32) && !defined(__CYGWIN__) @@ -2439,6 +2438,7 @@ archive_read_disk_entry_from_file(struct archive *_a, return (ARCHIVE_OK); } + r = ARCHIVE_OK; if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) { r = setup_sparse_from_disk(a, entry, h); if (fd < 0) diff --git a/libarchive-clib/c/archive_read_extract.c b/libarchive-clib/c/archive_read_extract.c index b7973fa..d2159c6 100644 --- a/libarchive-clib/c/archive_read_extract.c +++ b/libarchive-clib/c/archive_read_extract.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_extract2.c b/libarchive-clib/c/archive_read_extract2.c index 4febd8c..e11cac1 100644 --- a/libarchive-clib/c/archive_read_extract2.c +++ b/libarchive-clib/c/archive_read_extract2.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_read_open_fd.c b/libarchive-clib/c/archive_read_open_fd.c index f59cd07..3ee2423 100644 --- a/libarchive-clib/c/archive_read_open_fd.c +++ b/libarchive-clib/c/archive_read_open_fd.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_fd.c 201103 2009-12-28 03:13:49Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_read_open_file.c b/libarchive-clib/c/archive_read_open_file.c index 03719e8..dcf1d46 100644 --- a/libarchive-clib/c/archive_read_open_file.c +++ b/libarchive-clib/c/archive_read_open_file.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_file.c 201093 2009-12-28 02:28:44Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_read_open_filename.c b/libarchive-clib/c/archive_read_open_filename.c index 561289b..dd2e160 100644 --- a/libarchive-clib/c/archive_read_open_filename.c +++ b/libarchive-clib/c/archive_read_open_filename.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_filename.c 201093 2009-12-28 02:28:44Z kientzle $"); #ifdef HAVE_SYS_IOCTL_H #include @@ -155,55 +154,73 @@ archive_read_open_filenames(struct archive *a, const char **filenames, return (ARCHIVE_FATAL); } +/* + * This function is an implementation detail of archive_read_open_filename_w, + * which is exposed as a separate API on Windows. + */ +#if !defined(_WIN32) || defined(__CYGWIN__) +static +#endif int -archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename, +archive_read_open_filenames_w(struct archive *a, const wchar_t **wfilenames, size_t block_size) { - struct read_file_data *mine = (struct read_file_data *)calloc(1, - sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t)); - if (!mine) + struct read_file_data *mine; + const wchar_t *wfilename = NULL; + if (wfilenames) + wfilename = *(wfilenames++); + + archive_clear_error(a); + do { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - mine->fd = -1; - mine->block_size = block_size; + if (wfilename == NULL) + wfilename = L""; + mine = (struct read_file_data *)calloc(1, + sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t)); + if (mine == NULL) + goto no_memory; + mine->block_size = block_size; + mine->fd = -1; - if (wfilename == NULL || wfilename[0] == L'\0') { - mine->filename_type = FNT_STDIN; - } else { + if (wfilename == NULL || wfilename[0] == L'\0') { + mine->filename_type = FNT_STDIN; + } else { #if defined(_WIN32) && !defined(__CYGWIN__) - mine->filename_type = FNT_WCS; - wcscpy(mine->filename.w, wfilename); + mine->filename_type = FNT_WCS; + wcscpy(mine->filename.w, wfilename); #else - /* - * POSIX system does not support a wchar_t interface for - * open() system call, so we have to translate a wchar_t - * filename to multi-byte one and use it. - */ - struct archive_string fn; - - archive_string_init(&fn); - if (archive_string_append_from_wcs(&fn, wfilename, - wcslen(wfilename)) != 0) { - if (errno == ENOMEM) - archive_set_error(a, errno, - "Can't allocate memory"); - else - archive_set_error(a, EINVAL, - "Failed to convert a wide-character" - " filename to a multi-byte filename"); + /* + * POSIX system does not support a wchar_t interface for + * open() system call, so we have to translate a wchar_t + * filename to multi-byte one and use it. + */ + struct archive_string fn; + + archive_string_init(&fn); + if (archive_string_append_from_wcs(&fn, wfilename, + wcslen(wfilename)) != 0) { + if (errno == ENOMEM) + archive_set_error(a, errno, + "Can't allocate memory"); + else + archive_set_error(a, EINVAL, + "Failed to convert a wide-character" + " filename to a multi-byte filename"); + archive_string_free(&fn); + free(mine); + return (ARCHIVE_FATAL); + } + mine->filename_type = FNT_MBS; + strcpy(mine->filename.m, fn.s); archive_string_free(&fn); - free(mine); - return (ARCHIVE_FATAL); - } - mine->filename_type = FNT_MBS; - strcpy(mine->filename.m, fn.s); - archive_string_free(&fn); #endif - } - if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK)) - return (ARCHIVE_FATAL); + } + if (archive_read_append_callback_data(a, mine) != (ARCHIVE_OK)) + return (ARCHIVE_FATAL); + if (wfilenames == NULL) + break; + wfilename = *(wfilenames++); + } while (wfilename != NULL && wfilename[0] != '\0'); archive_read_set_open_callback(a, file_open); archive_read_set_read_callback(a, file_read); archive_read_set_skip_callback(a, file_skip); @@ -212,6 +229,19 @@ archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename, archive_read_set_seek_callback(a, file_seek); return (archive_read_open1(a)); +no_memory: + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); +} + +int +archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename, + size_t block_size) +{ + const wchar_t *wfilenames[2]; + wfilenames[0] = wfilename; + wfilenames[1] = NULL; + return archive_read_open_filenames_w(a, wfilenames, block_size); } static int diff --git a/libarchive-clib/c/archive_read_open_memory.c b/libarchive-clib/c/archive_read_open_memory.c index 311be47..a057ce6 100644 --- a/libarchive-clib/c/archive_read_open_memory.c +++ b/libarchive-clib/c/archive_read_open_memory.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_memory.c,v 1.6 2007/07/06 15:51:59 kientzle Exp $"); #include #include diff --git a/libarchive-clib/c/archive_read_private.h b/libarchive-clib/c/archive_read_private.h index 383405d..0c374f4 100644 --- a/libarchive-clib/c/archive_read_private.h +++ b/libarchive-clib/c/archive_read_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $ */ #ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_read_set_format.c b/libarchive-clib/c/archive_read_set_format.c index 796dcdc..c74361b 100644 --- a/libarchive-clib/c/archive_read_set_format.c +++ b/libarchive-clib/c/archive_read_set_format.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_set_options.c b/libarchive-clib/c/archive_read_set_options.c index 2bd9b81..c0a4b42 100644 --- a/libarchive-clib/c/archive_read_set_options.c +++ b/libarchive-clib/c/archive_read_set_options.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive_read_private.h" #include "archive_options_private.h" diff --git a/libarchive-clib/c/archive_read_support_filter_all.c b/libarchive-clib/c/archive_read_support_filter_all.c index edb508c..cb46d12 100644 --- a/libarchive-clib/c/archive_read_support_filter_all.c +++ b/libarchive-clib/c/archive_read_support_filter_all.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_private.h" diff --git a/libarchive-clib/c/archive_read_support_filter_by_code.c b/libarchive-clib/c/archive_read_support_filter_by_code.c index 94c4af6..ce50d8c 100644 --- a/libarchive-clib/c/archive_read_support_filter_by_code.c +++ b/libarchive-clib/c/archive_read_support_filter_by_code.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_private.h" diff --git a/libarchive-clib/c/archive_read_support_filter_bzip2.c b/libarchive-clib/c/archive_read_support_filter_bzip2.c index 9158e66..0392d45 100644 --- a/libarchive-clib/c/archive_read_support_filter_bzip2.c +++ b/libarchive-clib/c/archive_read_support_filter_bzip2.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif @@ -192,7 +190,7 @@ bzip2_reader_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_BZIP2; self->name = "bzip2"; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); out_block = (unsigned char *)malloc(out_block_size); if (state == NULL || out_block == NULL) { archive_set_error(&self->archive->archive, ENOMEM, diff --git a/libarchive-clib/c/archive_read_support_filter_compress.c b/libarchive-clib/c/archive_read_support_filter_compress.c index 05b80a5..29ae72a 100644 --- a/libarchive-clib/c/archive_read_support_filter_compress.c +++ b/libarchive-clib/c/archive_read_support_filter_compress.c @@ -64,7 +64,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include @@ -218,7 +217,7 @@ compress_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_COMPRESS; self->name = "compress (.Z)"; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); out_block = malloc(out_block_size); if (state == NULL || out_block == NULL) { free(out_block); diff --git a/libarchive-clib/c/archive_read_support_filter_grzip.c b/libarchive-clib/c/archive_read_support_filter_grzip.c index d4d1737..15b6757 100644 --- a/libarchive-clib/c/archive_read_support_filter_grzip.c +++ b/libarchive-clib/c/archive_read_support_filter_grzip.c @@ -25,9 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_read_support_filter_gzip.c b/libarchive-clib/c/archive_read_support_filter_gzip.c index 4135a63..152ea9b 100644 --- a/libarchive-clib/c/archive_read_support_filter_gzip.c +++ b/libarchive-clib/c/archive_read_support_filter_gzip.c @@ -25,9 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - - #ifdef HAVE_ERRNO_H #include #endif @@ -310,7 +307,7 @@ gzip_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_GZIP; self->name = "gzip"; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); out_block = (unsigned char *)malloc(out_block_size); if (state == NULL || out_block == NULL) { free(out_block); diff --git a/libarchive-clib/c/archive_read_support_filter_lrzip.c b/libarchive-clib/c/archive_read_support_filter_lrzip.c index a238989..a562d53 100644 --- a/libarchive-clib/c/archive_read_support_filter_lrzip.c +++ b/libarchive-clib/c/archive_read_support_filter_lrzip.c @@ -25,9 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_read_support_filter_lz4.c b/libarchive-clib/c/archive_read_support_filter_lz4.c index d0fc1a8..bccf4fb 100644 --- a/libarchive-clib/c/archive_read_support_filter_lz4.c +++ b/libarchive-clib/c/archive_read_support_filter_lz4.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif @@ -225,7 +223,7 @@ lz4_reader_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZ4; self->name = "lz4"; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); if (state == NULL) { archive_set_error(&self->archive->archive, ENOMEM, "Can't allocate data for lz4 decompression"); @@ -449,8 +447,8 @@ lz4_filter_read_descriptor(struct archive_read_filter *self) chsum = __archive_xxhash.XXH32(read_buf, (int)descriptor_bytes -1, 0); chsum = (chsum >> 8) & 0xff; chsum_verifier = read_buf[descriptor_bytes-1] & 0xff; - if (chsum != chsum_verifier) #ifndef DONT_FAIL_ON_CRC_ERROR + if (chsum != chsum_verifier) goto malformed_error; #endif @@ -522,8 +520,8 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p) read_buf + 4, (int)compressed_size, 0); unsigned int chsum_block = archive_le32dec(read_buf + 4 + compressed_size); - if (chsum != chsum_block) #ifndef DONT_FAIL_ON_CRC_ERROR + if (chsum != chsum_block) goto malformed_error; #endif } diff --git a/libarchive-clib/c/archive_read_support_filter_lzop.c b/libarchive-clib/c/archive_read_support_filter_lzop.c index 4ebdd3b..e971063 100644 --- a/libarchive-clib/c/archive_read_support_filter_lzop.c +++ b/libarchive-clib/c/archive_read_support_filter_lzop.c @@ -26,8 +26,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_UNISTD_H #include #endif @@ -187,7 +185,7 @@ lzop_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZOP; self->name = "lzop"; - state = (struct read_lzop *)calloc(sizeof(*state), 1); + state = (struct read_lzop *)calloc(1, sizeof(*state)); if (state == NULL) { archive_set_error(&self->archive->archive, ENOMEM, "Can't allocate data for lzop decompression"); @@ -282,8 +280,8 @@ consume_header(struct archive_read_filter *self) checksum = crc32(crc32(0, NULL, 0), p, len); else checksum = adler32(adler32(0, NULL, 0), p, len); - if (archive_be32dec(p + len) != checksum) #ifndef DONT_FAIL_ON_CRC_ERROR + if (archive_be32dec(p + len) != checksum) goto corrupted; #endif __archive_read_filter_consume(self->upstream, len + 4); diff --git a/libarchive-clib/c/archive_read_support_filter_none.c b/libarchive-clib/c/archive_read_support_filter_none.c index 95e5cfd..9eb8e54 100644 --- a/libarchive-clib/c/archive_read_support_filter_none.c +++ b/libarchive-clib/c/archive_read_support_filter_none.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_private.h" diff --git a/libarchive-clib/c/archive_read_support_filter_program.c b/libarchive-clib/c/archive_read_support_filter_program.c index 885b2c2..0482c57 100644 --- a/libarchive-clib/c/archive_read_support_filter_program.c +++ b/libarchive-clib/c/archive_read_support_filter_program.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_WAIT_H # include diff --git a/libarchive-clib/c/archive_read_support_filter_rpm.c b/libarchive-clib/c/archive_read_support_filter_rpm.c index 67a979c..87e9f2e 100644 --- a/libarchive-clib/c/archive_read_support_filter_rpm.c +++ b/libarchive-clib/c/archive_read_support_filter_rpm.c @@ -141,7 +141,7 @@ rpm_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_RPM; self->name = "rpm"; - rpm = (struct rpm *)calloc(sizeof(*rpm), 1); + rpm = (struct rpm *)calloc(1, sizeof(*rpm)); if (rpm == NULL) { archive_set_error(&self->archive->archive, ENOMEM, "Can't allocate data for rpm"); diff --git a/libarchive-clib/c/archive_read_support_filter_uu.c b/libarchive-clib/c/archive_read_support_filter_uu.c index cd79638..689ceb8 100644 --- a/libarchive-clib/c/archive_read_support_filter_uu.c +++ b/libarchive-clib/c/archive_read_support_filter_uu.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include @@ -374,7 +373,7 @@ uudecode_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_UU; self->name = "uu"; - uudecode = (struct uudecode *)calloc(sizeof(*uudecode), 1); + uudecode = (struct uudecode *)calloc(1, sizeof(*uudecode)); out_buff = malloc(OUT_BUFF_SIZE); in_buff = malloc(IN_BUFF_SIZE); if (uudecode == NULL || out_buff == NULL || in_buff == NULL) { diff --git a/libarchive-clib/c/archive_read_support_filter_xz.c b/libarchive-clib/c/archive_read_support_filter_xz.c index e313d39..e55fb00 100644 --- a/libarchive-clib/c/archive_read_support_filter_xz.c +++ b/libarchive-clib/c/archive_read_support_filter_xz.c @@ -26,8 +26,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif @@ -478,7 +476,7 @@ xz_lzma_bidder_init(struct archive_read_filter *self) struct private_data *state; int ret; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); out_block = (unsigned char *)malloc(out_block_size); if (state == NULL || out_block == NULL) { archive_set_error(&self->archive->archive, ENOMEM, @@ -656,13 +654,16 @@ xz_filter_read(struct archive_read_filter *self, const void **p) struct private_data *state; size_t decompressed; ssize_t avail_in; + int64_t member_in; int ret; state = (struct private_data *)self->data; + redo: /* Empty our output buffer. */ state->stream.next_out = state->out_block; state->stream.avail_out = state->out_block_size; + member_in = state->member_in; /* Try to fill the output buffer. */ while (state->stream.avail_out > 0 && !state->eof) { @@ -707,9 +708,18 @@ xz_filter_read(struct archive_read_filter *self, const void **p) decompressed = state->stream.next_out - state->out_block; state->total_out += decompressed; state->member_out += decompressed; - if (decompressed == 0) + if (decompressed == 0) { + if (member_in != state->member_in && + self->code == ARCHIVE_FILTER_LZIP && + state->eof) { + ret = lzip_tail(self); + if (ret != ARCHIVE_OK) + return (ret); + if (!state->eof) + goto redo; + } *p = NULL; - else { + } else { *p = state->out_block; if (self->code == ARCHIVE_FILTER_LZIP) { state->crc32 = lzma_crc32(state->out_block, diff --git a/libarchive-clib/c/archive_read_support_filter_zstd.c b/libarchive-clib/c/archive_read_support_filter_zstd.c index 1959b5a..f7326d2 100644 --- a/libarchive-clib/c/archive_read_support_filter_zstd.c +++ b/libarchive-clib/c/archive_read_support_filter_zstd.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif @@ -177,7 +175,7 @@ zstd_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_ZSTD; self->name = "zstd"; - state = (struct private_data *)calloc(sizeof(*state), 1); + state = (struct private_data *)calloc(1, sizeof(*state)); out_block = (unsigned char *)malloc(out_block_size); dstream = ZSTD_createDStream(); diff --git a/libarchive-clib/c/archive_read_support_format_7zip.c b/libarchive-clib/c/archive_read_support_format_7zip.c index 051082b..7e46593 100644 --- a/libarchive-clib/c/archive_read_support_format_7zip.c +++ b/libarchive-clib/c/archive_read_support_format_7zip.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include @@ -2038,6 +2037,8 @@ read_Folder(struct archive_read *a, struct _7z_folder *f) if (parse_7zip_uint64( a, &(f->coders[i].propertiesSize)) < 0) return (-1); + if (UMAX_ENTRY < f->coders[i].propertiesSize) + return (-1); if ((p = header_bytes( a, (size_t)f->coders[i].propertiesSize)) == NULL) return (-1); @@ -3051,8 +3052,8 @@ 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 + archive_set_error(&a->archive, -1, "Damaged 7-Zip archive"); r = -1; #endif diff --git a/libarchive-clib/c/archive_read_support_format_all.c b/libarchive-clib/c/archive_read_support_format_all.c index dea558b..3b53c9a 100644 --- a/libarchive-clib/c/archive_read_support_format_all.c +++ b/libarchive-clib/c/archive_read_support_format_all.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_all.c 174991 2007-12-30 04:58:22Z kientzle $"); #include "archive.h" #include "archive_private.h" @@ -68,7 +67,7 @@ archive_read_support_format_all(struct archive *a) * increase the chance that a high bid from someone else will * make it unnecessary for these to do anything at all. */ - /* These three have potentially large look-ahead. */ + /* These have potentially large look-ahead. */ archive_read_support_format_7zip(a); archive_read_support_format_cab(a); archive_read_support_format_rar(a); diff --git a/libarchive-clib/c/archive_read_support_format_ar.c b/libarchive-clib/c/archive_read_support_format_ar.c index 296b7db..6f1be85 100644 --- a/libarchive-clib/c/archive_read_support_format_ar.c +++ b/libarchive-clib/c/archive_read_support_format_ar.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_ar.c 201101 2009-12-28 03:06:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -271,7 +270,7 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry, } if (ar->strtab != NULL) { archive_set_error(&a->archive, EINVAL, - "More than one string tables exist"); + "More than one string table exists"); return (ARCHIVE_FATAL); } @@ -516,7 +515,7 @@ archive_read_format_ar_read_data(struct archive_read *a, if (ar->entry_padding) { if (skipped >= 0) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated ar archive- failed consuming padding"); + "Truncated ar archive - failed consuming padding"); } return (ARCHIVE_FATAL); } diff --git a/libarchive-clib/c/archive_read_support_format_by_code.c b/libarchive-clib/c/archive_read_support_format_by_code.c index 89e96f1..7ed045f 100644 --- a/libarchive-clib/c/archive_read_support_format_by_code.c +++ b/libarchive-clib/c/archive_read_support_format_by_code.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_support_format_cpio.c b/libarchive-clib/c/archive_read_support_format_cpio.c index 9adcfd3..dcff23f 100644 --- a/libarchive-clib/c/archive_read_support_format_cpio.c +++ b/libarchive-clib/c/archive_read_support_format_cpio.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 201163 2009-12-29 05:50:34Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_support_format_empty.c b/libarchive-clib/c/archive_read_support_format_empty.c index 53fb6cc..0dccd9d 100644 --- a/libarchive-clib/c/archive_read_support_format_empty.c +++ b/libarchive-clib/c/archive_read_support_format_empty.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_empty.c 191524 2009-04-26 18:24:14Z kientzle $"); #include "archive.h" #include "archive_entry.h" diff --git a/libarchive-clib/c/archive_read_support_format_iso9660.c b/libarchive-clib/c/archive_read_support_format_iso9660.c index f5414be..db5cdb6 100644 --- a/libarchive-clib/c/archive_read_support_format_iso9660.c +++ b/libarchive-clib/c/archive_read_support_format_iso9660.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_iso9660.c 201246 2009-12-30 05:30:35Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -3015,6 +3014,11 @@ heap_add_entry(struct archive_read *a, struct heap_queue *heap, uint64_t file_key, parent_key; int hole, parent; + /* Reserve 16 bits for possible key collisions (needed for linked items) */ + /* For ISO files with more than 65535 entries, reordering will still occur */ + key <<= 16; + key += heap->used & 0xFFFF; + /* Expand our pending files list as necessary. */ if (heap->used >= heap->allocated) { struct file_info **new_pending_files; diff --git a/libarchive-clib/c/archive_read_support_format_lha.c b/libarchive-clib/c/archive_read_support_format_lha.c index 1c64b29..4d6290a 100644 --- a/libarchive-clib/c/archive_read_support_format_lha.c +++ b/libarchive-clib/c/archive_read_support_format_lha.c @@ -1693,7 +1693,7 @@ archive_read_format_lha_cleanup(struct archive_read *a) * example. * 1. a symbolic-name is 'aaa/bb/cc' * 2. a filename is 'xxx/bbb' - * then a archived pathname is 'xxx/bbb|aaa/bb/cc' + * then an archived pathname is 'xxx/bbb|aaa/bb/cc' */ static int lha_parse_linkname(struct archive_wstring *linkname, @@ -2385,7 +2385,7 @@ lzh_decode_blocks(struct lzh_stream *strm, int last) return (100); } - /* lzh_br_read_ahead() always try to fill the + /* lzh_br_read_ahead() always tries to fill the * cache buffer up. In specific situation we * are close to the end of the data, the cache * buffer will not be full and thus we have to diff --git a/libarchive-clib/c/archive_read_support_format_mtree.c b/libarchive-clib/c/archive_read_support_format_mtree.c index a5fa30e..6971228 100644 --- a/libarchive-clib/c/archive_read_support_format_mtree.c +++ b/libarchive-clib/c/archive_read_support_format_mtree.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 201165 2009-12-29 05:52:13Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -417,8 +416,8 @@ next_line(struct archive_read *a, } /* - * Compare characters with a mtree keyword. - * Returns the length of a mtree keyword if matched. + * Compare characters with an mtree keyword. + * Returns the length of an mtree keyword if matched. * Returns 0 if not matched. */ static int @@ -516,7 +515,7 @@ bid_keyword(const char *p, ssize_t len) /* * Test whether there is a set of mtree keywords. - * Returns the number of keyword. + * Returns the number of keywords. * Returns -1 if we got incorrect sequence. * This function expects a set of "keyword=value". * When "unset" is specified, expects a set of "keyword". @@ -761,7 +760,7 @@ detect_form(struct archive_read *a, int *is_form_d) multiline = 1; else { /* We've got plenty of correct lines - * to assume that this file is a mtree + * to assume that this file is an mtree * format. */ if (++entry_cnt >= MAX_BID_ENTRY) break; diff --git a/libarchive-clib/c/archive_read_support_format_rar.c b/libarchive-clib/c/archive_read_support_format_rar.c index 16b6e6e..79669a8 100644 --- a/libarchive-clib/c/archive_read_support_format_rar.c +++ b/libarchive-clib/c/archive_read_support_format_rar.c @@ -734,7 +734,7 @@ archive_read_support_format_rar(struct archive *_a) archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_support_format_rar"); - rar = (struct rar *)calloc(sizeof(*rar), 1); + rar = (struct rar *)calloc(1, sizeof(*rar)); if (rar == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data"); @@ -2176,6 +2176,19 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, { start = rar->offset; end = start + rar->dictionary_size; + + /* We don't want to overflow the window and overwrite data that we write + * at 'start'. Therefore, reduce the end length by the maximum match size, + * which is 260 bytes. You can compute this maximum by looking at the + * definition of 'expand', in particular when 'symbol >= 271'. */ + /* NOTE: It's possible for 'dictionary_size' to be less than this 260 + * value, however that will only be the case when 'unp_size' is small, + * which should only happen when the entry size is small and there's no + * risk of overflowing the buffer */ + if (rar->dictionary_size > 260) { + end -= 260; + } + if (rar->filters.filterstart < end) { end = rar->filters.filterstart; } @@ -3615,7 +3628,7 @@ execute_filter_e8(struct rar_filter *filter, struct rar_virtual_machine *vm, siz uint32_t filesize = 0x1000000; uint32_t i; - if (length > PROGRAM_WORK_SIZE || length < 4) + if (length > PROGRAM_WORK_SIZE || length <= 4) return 0; for (i = 0; i <= length - 5; i++) diff --git a/libarchive-clib/c/archive_read_support_format_rar5.c b/libarchive-clib/c/archive_read_support_format_rar5.c index 1f90994..e8846a5 100644 --- a/libarchive-clib/c/archive_read_support_format_rar5.c +++ b/libarchive-clib/c/archive_read_support_format_rar5.c @@ -495,6 +495,11 @@ uint8_t bf_is_table_present(const struct compressed_block_header* hdr) { return (hdr->block_flags_u8 >> 7) & 1; } +static inline +uint8_t bf_is_last_block(const struct compressed_block_header* hdr) { + return (hdr->block_flags_u8 >> 6) & 1; +} + static inline struct rar5* get_context(struct archive_read* a) { return (struct rar5*) a->format->data; } @@ -3757,7 +3762,12 @@ static int do_uncompress_file(struct archive_read* a) { if(rar->cstate.last_write_ptr == rar->cstate.write_ptr) { /* The block didn't generate any new data, - * so just process a new block. */ + * so just process a new block if this one + * wasn't the last block in the file. */ + if (bf_is_last_block(&rar->last_block_hdr)) { + return ARCHIVE_EOF; + } + continue; } diff --git a/libarchive-clib/c/archive_read_support_format_raw.c b/libarchive-clib/c/archive_read_support_format_raw.c index ec0520b..efdbf27 100644 --- a/libarchive-clib/c/archive_read_support_format_raw.c +++ b/libarchive-clib/c/archive_read_support_format_raw.c @@ -23,7 +23,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_raw.c 201107 2009-12-28 03:25:33Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_support_format_tar.c b/libarchive-clib/c/archive_read_support_format_tar.c index 93c3fd5..e5058ee 100644 --- a/libarchive-clib/c/archive_read_support_format_tar.c +++ b/libarchive-clib/c/archive_read_support_format_tar.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_tar.c 201161 2009-12-29 05:44:39Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_read_support_format_warc.c b/libarchive-clib/c/archive_read_support_format_warc.c index 61ab29e..fcec5bc 100644 --- a/libarchive-clib/c/archive_read_support_format_warc.c +++ b/libarchive-clib/c/archive_read_support_format_warc.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); /** * WARC is standardised by ISO TC46/SC4/WG12 and currently available as @@ -216,6 +215,7 @@ _warc_rdhdr(struct archive_read *a, struct archive_entry *entry) const char *buf; ssize_t nrd; const char *eoh; + char *tmp; /* for the file name, saves some strndup()'ing */ warc_string_t fnam; /* warc record type, not that we really use it a lot */ @@ -322,7 +322,14 @@ _warc_rdhdr(struct archive_read *a, struct archive_entry *entry) * malloc()+free() roundtrip */ if (fnam.len + 1U > w->pool.len) { w->pool.len = ((fnam.len + 64U) / 64U) * 64U; - w->pool.str = realloc(w->pool.str, w->pool.len); + tmp = realloc(w->pool.str, w->pool.len); + if (tmp == NULL) { + archive_set_error( + &a->archive, ENOMEM, + "Out of memory"); + return (ARCHIVE_FATAL); + } + w->pool.str = tmp; } memcpy(w->pool.str, fnam.str, fnam.len); w->pool.str[fnam.len] = '\0'; diff --git a/libarchive-clib/c/archive_read_support_format_xar.c b/libarchive-clib/c/archive_read_support_format_xar.c index ec9cb19..2c34326 100644 --- a/libarchive-clib/c/archive_read_support_format_xar.c +++ b/libarchive-clib/c/archive_read_support_format_xar.c @@ -23,7 +23,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include @@ -623,8 +622,8 @@ read_toc(struct archive_read *a) (size_t)xar->toc_chksum_size, NULL, 0); __archive_read_consume(a, xar->toc_chksum_size); xar->offset += xar->toc_chksum_size; - if (r != ARCHIVE_OK) #ifndef DONT_FAIL_ON_CRC_ERROR + if (r != ARCHIVE_OK) return (ARCHIVE_FATAL); #endif } @@ -2056,6 +2055,11 @@ xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) attr = attr->next) { if (strcmp(attr->name, "link") != 0) continue; + if (xar->file->hdnext != NULL || xar->file->link != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File with multiple link targets"); + return (ARCHIVE_FATAL); + } if (strcmp(attr->value, "original") == 0) { xar->file->hdnext = xar->hdlink_orgs; xar->hdlink_orgs = xar->file; diff --git a/libarchive-clib/c/archive_read_support_format_zip.c b/libarchive-clib/c/archive_read_support_format_zip.c index c3b9b57..c9759ea 100644 --- a/libarchive-clib/c/archive_read_support_format_zip.c +++ b/libarchive-clib/c/archive_read_support_format_zip.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102 2009-12-28 03:11:36Z kientzle $"); /* * The definitive documentation of the Zip file format is: @@ -119,7 +118,7 @@ struct trad_enc_ctx { /* Bits used in zip_flags. */ #define ZIP_ENCRYPTED (1 << 0) -#define ZIP_LENGTH_AT_END (1 << 3) +#define ZIP_LENGTH_AT_END (1 << 3) /* Also called "Streaming bit" */ #define ZIP_STRONG_ENCRYPTED (1 << 6) #define ZIP_UTF8_NAME (1 << 11) /* See "7.2 Single Password Symmetric Encryption Method" @@ -166,8 +165,8 @@ struct zip { int64_t entry_compressed_bytes_read; int64_t entry_uncompressed_bytes_read; - /* Running CRC32 of the decompressed data */ - unsigned long entry_crc32; + /* Running CRC32 of the decompressed and decrypted data */ + unsigned long computed_crc32; unsigned long (*crc32func)(unsigned long, const void *, size_t); char ignore_crc32; @@ -945,7 +944,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, zip->end_of_entry = 0; zip->entry_uncompressed_bytes_read = 0; zip->entry_compressed_bytes_read = 0; - zip->entry_crc32 = zip->crc32func(0, NULL, 0); + zip->computed_crc32 = zip->crc32func(0, NULL, 0); /* Setup default conversion. */ if (zip->sconv == NULL && !zip->init_default_conversion) { @@ -1140,7 +1139,8 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, "Inconsistent CRC32 values"); ret = ARCHIVE_WARN; } - if (zip_entry->compressed_size == 0) { + if (zip_entry->compressed_size == 0 + || zip_entry->compressed_size == 0xffffffff) { zip_entry->compressed_size = zip_entry_central_dir.compressed_size; } else if (zip_entry->compressed_size @@ -1284,7 +1284,8 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, return ARCHIVE_FATAL; } } else if (0 == (zip_entry->zip_flags & ZIP_LENGTH_AT_END) - || zip_entry->uncompressed_size > 0) { + || (zip_entry->uncompressed_size > 0 + && zip_entry->uncompressed_size != 0xffffffff)) { /* Set the size only if it's meaningful. */ archive_entry_set_size(entry, zip_entry->uncompressed_size); } @@ -1343,25 +1344,267 @@ check_authentication_code(struct archive_read *a, const void *_p) } /* - * Read "uncompressed" data. There are three cases: - * 1) We know the size of the data. This is always true for the - * seeking reader (we've examined the Central Directory already). - * 2) ZIP_LENGTH_AT_END was set, but only the CRC was deferred. - * Info-ZIP seems to do this; we know the size but have to grab - * the CRC from the data descriptor afterwards. - * 3) We're streaming and ZIP_LENGTH_AT_END was specified and - * we have no size information. In this case, we can do pretty - * well by watching for the data descriptor record. The data - * descriptor is 16 bytes and includes a computed CRC that should - * provide a strong check. + * The Zip end-of-file marker is inherently ambiguous. The specification + * in APPNOTE.TXT allows any of four possible formats, and there is no + * guaranteed-correct way for a reader to know a priori which one the writer + * will have used. The four formats are: + * 1. 32-bit format with an initial PK78 marker + * 2. 32-bit format without that marker + * 3. 64-bit format with the marker + * 4. 64-bit format without the marker * - * TODO: Technically, the PK\007\010 signature is optional. - * In the original spec, the data descriptor contained CRC - * and size fields but had no leading signature. In practice, - * newer writers seem to provide the signature pretty consistently. + * Mark Adler's `sunzip` streaming unzip program solved this ambiguity + * by just looking at every possible combination and accepting the + * longest one that matches the expected values. His approach always + * consumes the longest possible matching EOF marker, based on an + * analysis of all the possible failures and how the values could + * overlap. * - * For uncompressed data, the PK\007\010 marker seems essential - * to be sure we've actually seen the end of the entry. + * For example, suppose both of the first two formats listed + * above match. In that case, we know the next four + * 32-bit words match this pattern: + * ``` + * [PK\07\08] [CRC32] [compressed size] [uncompressed size] + * ``` + * but we know they must also match this pattern: + * ``` + * [CRC32] [compressed size] [uncompressed size] [other PK marker] + * ``` + * + * Since the first word here matches both the PK78 signature in the + * first form and the CRC32 in the second, we know those two values + * are equal, the CRC32 must be exactly 0x08074b50. Similarly, the + * compressed and uncompressed size must also be exactly this value. + * So we know these four words are all 0x08074b50. If we were to + * accept the shorter pattern, it would be immediately followed by + * another PK78 marker, which is not possible in a well-formed ZIP + * archive unless there is garbage between entries. This implies we + * should not accept the shorter form in such a case; we should accept + * the longer form. + * + * If the second and third possibilities above both match, we + * have a slightly different situation. The following words + * must match both the 32-bit format + * ``` + * [CRC32] [compressed size] [uncompressed size] [other PK marker] + * ``` + * and the 64-bit format + * ``` + * [CRC32] [compressed low] [compressed high] [uncompressed low] [uncompressed high] [other PK marker] + * ``` + * Since the 32-bit and 64-bit compressed sizes both match, the + * actual size must fit in 32 bits, which implies the high-order + * word of the compressed size is zero. So we know the uncompressed + * low word is zero, which again implies that if we accept the shorter + * format, there will not be a valid PK marker following it. + * + * Similar considerations rule out the shorter form in every other + * possibly-ambiguous pair. So if two of the four possible formats + * match, we should accept the longer option. + * + * If none of the four formats matches, we know the archive must be + * corrupted in some fashion. In particular, it's possible that the + * length-at-end bit was incorrect and we should not really be looking + * for an EOF marker at all. To allow for this possibility, we + * evaluate the following words to collect data for a later error + * report but do not consume any bytes. We instead rely on the later + * search for a new PK marker to re-sync to the next well-formed + * entry. + */ +static void +consume_end_of_file_marker(struct archive_read *a, struct zip *zip) +{ + const char *marker; + const char *p; + uint64_t compressed32, uncompressed32; + uint64_t compressed64, uncompressed64; + uint64_t compressed_actual, uncompressed_actual; + uint32_t crc32_actual; + const uint32_t PK78 = 0x08074B50ULL; + uint8_t crc32_ignored, crc32_may_be_zero; + + /* If there shouldn't be a marker, don't consume it. */ + if ((zip->entry->zip_flags & ZIP_LENGTH_AT_END) == 0) { + return; + } + + /* The longest Zip end-of-file record is 24 bytes. Since an + * end-of-file record can never appear at the end of the + * archive, we know 24 bytes will be available unless + * the archive is severely truncated. */ + if (NULL == (marker = __archive_read_ahead(a, 24, NULL))) { + return; + } + p = marker; + + /* The end-of-file record comprises: + * = Optional PK\007\010 marker + * = 4-byte CRC32 + * = Compressed size + * = Uncompressed size + * + * The last two fields are either both 32 bits or both 64 + * bits. We check all possible layouts and accept any one + * that gives us a complete match, else we make a best-effort + * attempt to parse out the pieces. + */ + + /* CRC32 checking can be tricky: + * * Test suites sometimes ignore the CRC32 + * * AES AE-2 always writes zero for the CRC32 + * * AES AE-1 sometimes writes zero for the CRC32 + */ + crc32_ignored = zip->ignore_crc32; + crc32_may_be_zero = 0; + crc32_actual = zip->computed_crc32; + if (zip->hctx_valid) { + switch (zip->entry->aes_extra.vendor) { + case AES_VENDOR_AE_2: + crc32_actual = 0; + break; + case AES_VENDOR_AE_1: + default: + crc32_may_be_zero = 1; + break; + } + } + + /* Values computed from the actual data in the archive. */ + compressed_actual = (uint64_t)zip->entry_compressed_bytes_read; + uncompressed_actual = (uint64_t)zip->entry_uncompressed_bytes_read; + + + /* Longest: PK78 marker, all 64-bit fields (24 bytes total) */ + if (archive_le32dec(p) == PK78 + && ((archive_le32dec(p + 4) == crc32_actual) + || (crc32_may_be_zero && (archive_le32dec(p + 4) == 0)) + || crc32_ignored) + && (archive_le64dec(p + 8) == compressed_actual) + && (archive_le64dec(p + 16) == uncompressed_actual)) { + if (!crc32_ignored) { + zip->entry->crc32 = crc32_actual; + } + zip->entry->compressed_size = compressed_actual; + zip->entry->uncompressed_size = uncompressed_actual; + zip->unconsumed += 24; + return; + } + + /* No PK78 marker, 64-bit fields (20 bytes total) */ + if (((archive_le32dec(p) == crc32_actual) + || (crc32_may_be_zero && (archive_le32dec(p + 4) == 0)) + || crc32_ignored) + && (archive_le64dec(p + 4) == compressed_actual) + && (archive_le64dec(p + 12) == uncompressed_actual)) { + if (!crc32_ignored) { + zip->entry->crc32 = crc32_actual; + } + zip->entry->compressed_size = compressed_actual; + zip->entry->uncompressed_size = uncompressed_actual; + zip->unconsumed += 20; + return; + } + + /* PK78 marker and 32-bit fields (16 bytes total) */ + if (archive_le32dec(p) == PK78 + && ((archive_le32dec(p + 4) == crc32_actual) + || (crc32_may_be_zero && (archive_le32dec(p + 4) == 0)) + || crc32_ignored) + && (archive_le32dec(p + 8) == compressed_actual) + && (archive_le32dec(p + 12) == uncompressed_actual)) { + if (!crc32_ignored) { + zip->entry->crc32 = crc32_actual; + } + zip->entry->compressed_size = compressed_actual; + zip->entry->uncompressed_size = uncompressed_actual; + zip->unconsumed += 16; + return; + } + + /* Shortest: No PK78 marker, all 32-bit fields (12 bytes total) */ + if (((archive_le32dec(p) == crc32_actual) + || (crc32_may_be_zero && (archive_le32dec(p + 4) == 0)) + || crc32_ignored) + && (archive_le32dec(p + 4) == compressed_actual) + && (archive_le32dec(p + 8) == uncompressed_actual)) { + if (!crc32_ignored) { + zip->entry->crc32 = crc32_actual; + } + zip->entry->compressed_size = compressed_actual; + zip->entry->uncompressed_size = uncompressed_actual; + zip->unconsumed += 12; + return; + } + + /* If none of the above patterns gives us a full exact match, + * then there's something definitely amiss. The fallback code + * below will parse out some plausible values for error + * reporting purposes. Note that this won't actually + * consume anything: + * + * = If there really is a marker here, the logic to resync to + * the next entry will suffice to skip it. + * + * = There might not really be a marker: Corruption or bugs + * may have set the length-at-end bit without a marker ever + * having actually been written. In this case, we + * explicitly should not consume any bytes, since that would + * prevent us from correctly reading the next entry. + */ + if (archive_le32dec(p) == PK78) { + p += 4; /* Ignore PK78 if it appears to be present */ + } + zip->entry->crc32 = archive_le32dec(p); /* Parse CRC32 */ + p += 4; + + /* Consider both 32- and 64-bit interpretations */ + compressed32 = archive_le32dec(p); + uncompressed32 = archive_le32dec(p + 4); + compressed64 = archive_le64dec(p); + uncompressed64 = archive_le64dec(p + 8); + + /* The earlier patterns may have failed because of CRC32 + * mismatch, so it's still possible that both sizes match. + * Try to match as many as we can... + */ + if (compressed32 == compressed_actual + && uncompressed32 == uncompressed_actual) { + /* Both 32-bit fields match */ + zip->entry->compressed_size = compressed32; + zip->entry->uncompressed_size = uncompressed32; + } else if (compressed64 == compressed_actual + || uncompressed64 == uncompressed_actual) { + /* One or both 64-bit fields match */ + zip->entry->compressed_size = compressed64; + zip->entry->uncompressed_size = uncompressed64; + } else { + /* Zero or one 32-bit fields match */ + zip->entry->compressed_size = compressed32; + zip->entry->uncompressed_size = uncompressed32; + } +} + +/* + * Read "uncompressed" data. + * + * This is straightforward if we know the size of the data. This is + * always true for the seeking reader (we've examined the Central + * Directory already), and will often be true for the streaming reader + * (the writer was writing uncompressed so probably knows the size). + * + * If we don't know the size, then life is more interesting. Note + * that a careful reading of the Zip specification says that a writer + * must use ZIP_LENGTH_AT_END if it cannot write the CRC into the + * local header. And if it uses ZIP_LENGTH_AT_END, then it is + * prohibited from storing the sizes in the local header. This + * prevents fully-compliant streaming writers from providing any size + * clues to a streaming reader. In this case, we have to scan the + * data as we read to try to locate the end-of-file marker. + * + * We assume here that the end-of-file marker always has the + * PK\007\010 signature. Although it's technically optional, newer + * writers seem to provide it pretty consistently, and it's not clear + * how to efficiently recognize an end-of-file marker that lacks it. * * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets * zip->end_of_entry if it consumes all of the data. @@ -1373,18 +1616,18 @@ zip_read_data_none(struct archive_read *a, const void **_buff, struct zip *zip; const char *buff; ssize_t bytes_avail; + ssize_t trailing_extra; int r; (void)offset; /* UNUSED */ zip = (struct zip *)(a->format->data); + trailing_extra = zip->hctx_valid ? AUTH_CODE_SIZE : 0; if (zip->entry->zip_flags & ZIP_LENGTH_AT_END) { const char *p; - ssize_t grabbing_bytes = 24; + ssize_t grabbing_bytes = 24 + trailing_extra; - if (zip->hctx_valid) - grabbing_bytes += AUTH_CODE_SIZE; /* Grab at least 24 bytes. */ buff = __archive_read_ahead(a, grabbing_bytes, &bytes_avail); if (bytes_avail < grabbing_bytes) { @@ -1399,44 +1642,19 @@ zip_read_data_none(struct archive_read *a, const void **_buff, } /* Check for a complete PK\007\010 signature, followed * by the correct 4-byte CRC. */ - p = buff; - if (zip->hctx_valid) - p += AUTH_CODE_SIZE; + p = buff + trailing_extra; if (p[0] == 'P' && p[1] == 'K' && p[2] == '\007' && p[3] == '\010' - && (archive_le32dec(p + 4) == zip->entry_crc32 + && (archive_le32dec(p + 4) == zip->computed_crc32 || zip->ignore_crc32 || (zip->hctx_valid && zip->entry->aes_extra.vendor == AES_VENDOR_AE_2))) { - if (zip->entry->flags & LA_USED_ZIP64) { - uint64_t compressed, uncompressed; - zip->entry->crc32 = archive_le32dec(p + 4); - compressed = archive_le64dec(p + 8); - uncompressed = archive_le64dec(p + 16); - if (compressed > INT64_MAX || uncompressed > - INT64_MAX) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Overflow of 64-bit file sizes"); - return ARCHIVE_FAILED; - } - zip->entry->compressed_size = compressed; - zip->entry->uncompressed_size = uncompressed; - zip->unconsumed = 24; - } else { - zip->entry->crc32 = archive_le32dec(p + 4); - zip->entry->compressed_size = - archive_le32dec(p + 8); - zip->entry->uncompressed_size = - archive_le32dec(p + 12); - zip->unconsumed = 16; - } + zip->end_of_entry = 1; if (zip->hctx_valid) { r = check_authentication_code(a, buff); if (r != ARCHIVE_OK) return (r); } - zip->end_of_entry = 1; return (ARCHIVE_OK); } /* If not at EOF, ensure we consume at least one byte. */ @@ -1452,11 +1670,10 @@ zip_read_data_none(struct archive_read *a, const void **_buff, else if (p[3] == '\007') { p += 1; } else if (p[3] == '\010' && p[2] == '\007' && p[1] == 'K' && p[0] == 'P') { - if (zip->hctx_valid) - p -= AUTH_CODE_SIZE; break; } else { p += 4; } } + p -= trailing_extra; bytes_avail = p - buff; } else { if (zip->entry_bytes_remaining == 0) { @@ -1499,59 +1716,15 @@ zip_read_data_none(struct archive_read *a, const void **_buff, bytes_avail = dec_size; buff = (const char *)zip->decrypted_buffer; } - *size = bytes_avail; zip->entry_bytes_remaining -= bytes_avail; zip->entry_uncompressed_bytes_read += bytes_avail; zip->entry_compressed_bytes_read += bytes_avail; zip->unconsumed += bytes_avail; + *size = bytes_avail; *_buff = buff; return (ARCHIVE_OK); } -static int -consume_optional_marker(struct archive_read *a, struct zip *zip) -{ - if (zip->end_of_entry && (zip->entry->zip_flags & ZIP_LENGTH_AT_END)) { - const char *p; - - if (NULL == (p = __archive_read_ahead(a, 24, NULL))) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP end-of-file record"); - return (ARCHIVE_FATAL); - } - /* Consume the optional PK\007\010 marker. */ - if (p[0] == 'P' && p[1] == 'K' && - p[2] == '\007' && p[3] == '\010') { - p += 4; - zip->unconsumed = 4; - } - if (zip->entry->flags & LA_USED_ZIP64) { - uint64_t compressed, uncompressed; - zip->entry->crc32 = archive_le32dec(p); - compressed = archive_le64dec(p + 4); - uncompressed = archive_le64dec(p + 12); - if (compressed > INT64_MAX || - uncompressed > INT64_MAX) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Overflow of 64-bit file sizes"); - return ARCHIVE_FAILED; - } - zip->entry->compressed_size = compressed; - zip->entry->uncompressed_size = uncompressed; - zip->unconsumed += 20; - } else { - zip->entry->crc32 = archive_le32dec(p); - zip->entry->compressed_size = archive_le32dec(p + 4); - zip->entry->uncompressed_size = archive_le32dec(p + 8); - zip->unconsumed += 12; - } - } - - return (ARCHIVE_OK); -} - #if HAVE_LZMA_H && HAVE_LIBLZMA static int zipx_xz_init(struct archive_read *a, struct zip *zip) @@ -1803,10 +1976,6 @@ zip_read_data_zipx_xz(struct archive_read *a, const void **buff, *size = zip->zipx_lzma_stream.total_out; *buff = zip->uncompressed_buffer; - ret = consume_optional_marker(a, zip); - if (ret != ARCHIVE_OK) - return (ret); - return (ARCHIVE_OK); } @@ -1871,8 +2040,6 @@ zip_read_data_zipx_lzma_alone(struct archive_read *a, const void **buff, /* This case is optional in lzma alone format. It can happen, * but most of the files don't have it. (GitHub #1257) */ case LZMA_STREAM_END: - lzma_end(&zip->zipx_lzma_stream); - zip->zipx_lzma_valid = 0; if((int64_t) zip->zipx_lzma_stream.total_in != zip->entry_bytes_remaining) { @@ -1906,21 +2073,18 @@ zip_read_data_zipx_lzma_alone(struct archive_read *a, const void **buff, zip->end_of_entry = 1; } - /* Return values. */ - *size = zip->zipx_lzma_stream.total_out; - *buff = zip->uncompressed_buffer; - - /* Behave the same way as during deflate decompression. */ - ret = consume_optional_marker(a, zip); - if (ret != ARCHIVE_OK) - return (ret); - /* Free lzma decoder handle because we'll no longer need it. */ + /* This cannot be folded into LZMA_STREAM_END handling above + * because the stream end marker is not required in this format. */ if(zip->end_of_entry) { lzma_end(&zip->zipx_lzma_stream); zip->zipx_lzma_valid = 0; } + /* Return values. */ + *size = zip->zipx_lzma_stream.total_out; + *buff = zip->uncompressed_buffer; + /* If we're here, then we're good! */ return (ARCHIVE_OK); } @@ -2078,10 +2242,6 @@ zip_read_data_zipx_ppmd(struct archive_read *a, const void **buff, ++consumed_bytes; } while(consumed_bytes < zip->uncompressed_buffer_size); - /* Update pointers for libarchive. */ - *buff = zip->uncompressed_buffer; - *size = consumed_bytes; - /* Update pointers so we can continue decompression in another call. */ zip->entry_bytes_remaining -= zip->zipx_ppmd_read_compressed; zip->entry_compressed_bytes_read += zip->zipx_ppmd_read_compressed; @@ -2093,10 +2253,9 @@ zip_read_data_zipx_ppmd(struct archive_read *a, const void **buff, zip->ppmd8_valid = 0; } - /* Seek for optional marker, same way as in each zip entry. */ - ret = consume_optional_marker(a, zip); - if (ret != ARCHIVE_OK) - return ret; + /* Update pointers for libarchive. */ + *buff = zip->uncompressed_buffer; + *size = consumed_bytes; return ARCHIVE_OK; } @@ -2238,11 +2397,6 @@ zip_read_data_zipx_bzip2(struct archive_read *a, const void **buff, *size = total_out; *buff = zip->uncompressed_buffer; - /* Seek for optional marker, like in other entries. */ - r = consume_optional_marker(a, zip); - if(r != ARCHIVE_OK) - return r; - return ARCHIVE_OK; } @@ -2373,11 +2527,6 @@ zip_read_data_zipx_zstd(struct archive_read *a, const void **buff, *size = total_out; *buff = zip->uncompressed_buffer; - /* Seek for optional marker, like in other entries. */ - r = consume_optional_marker(a, zip); - if(r != ARCHIVE_OK) - return r; - return ARCHIVE_OK; } #endif @@ -2413,7 +2562,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { struct zip *zip; - ssize_t bytes_avail; + ssize_t bytes_avail, to_consume = 0; const void *compressed_buff, *sp; int r; @@ -2534,34 +2683,33 @@ zip_read_data_deflate(struct archive_read *a, const void **buff, } /* Consume as much as the compressor actually used. */ - bytes_avail = zip->stream.total_in; + to_consume = zip->stream.total_in; + __archive_read_consume(a, to_consume); + zip->entry_bytes_remaining -= to_consume; + zip->entry_compressed_bytes_read += to_consume; + zip->entry_uncompressed_bytes_read += zip->stream.total_out; + if (zip->tctx_valid || zip->cctx_valid) { - zip->decrypted_bytes_remaining -= bytes_avail; + zip->decrypted_bytes_remaining -= to_consume; if (zip->decrypted_bytes_remaining == 0) zip->decrypted_ptr = zip->decrypted_buffer; else - zip->decrypted_ptr += bytes_avail; + zip->decrypted_ptr += to_consume; } - /* Calculate compressed data as much as we used.*/ if (zip->hctx_valid) - archive_hmac_sha1_update(&zip->hctx, sp, bytes_avail); - __archive_read_consume(a, bytes_avail); - zip->entry_bytes_remaining -= bytes_avail; - zip->entry_compressed_bytes_read += bytes_avail; - - *size = zip->stream.total_out; - zip->entry_uncompressed_bytes_read += zip->stream.total_out; - *buff = zip->uncompressed_buffer; + archive_hmac_sha1_update(&zip->hctx, sp, to_consume); - if (zip->end_of_entry && zip->hctx_valid) { - r = check_authentication_code(a, NULL); - if (r != ARCHIVE_OK) - return (r); + if (zip->end_of_entry) { + if (zip->hctx_valid) { + r = check_authentication_code(a, NULL); + if (r != ARCHIVE_OK) { + return (r); + } + } } - r = consume_optional_marker(a, zip); - if (r != ARCHIVE_OK) - return (r); + *size = zip->stream.total_out; + *buff = zip->uncompressed_buffer; return (ARCHIVE_OK); } @@ -3029,13 +3177,27 @@ archive_read_format_zip_read_data(struct archive_read *a, } if (r != ARCHIVE_OK) return (r); - /* Update checksum */ - if (*size) - zip->entry_crc32 = zip->crc32func(zip->entry_crc32, *buff, - (unsigned)*size); - /* If we hit the end, swallow any end-of-data marker. */ + if (*size > 0) { + zip->computed_crc32 = zip->crc32func(zip->computed_crc32, *buff, + (unsigned)*size); + } + /* If we hit the end, swallow any end-of-data marker and + * verify the final check values. */ if (zip->end_of_entry) { - /* Check file size, CRC against these values. */ + consume_end_of_file_marker(a, zip); + + /* Check computed CRC against header */ + if ((!zip->hctx_valid || + zip->entry->aes_extra.vendor != AES_VENDOR_AE_2) && + zip->entry->crc32 != zip->computed_crc32 + && !zip->ignore_crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP bad CRC: 0x%lx should be 0x%lx", + (unsigned long)zip->computed_crc32, + (unsigned long)zip->entry->crc32); + return (ARCHIVE_FAILED); + } + /* Check file size against header. */ if (zip->entry->compressed_size != zip->entry_compressed_bytes_read) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, @@ -3043,7 +3205,7 @@ archive_read_format_zip_read_data(struct archive_read *a, "(read %jd, expected %jd)", (intmax_t)zip->entry_compressed_bytes_read, (intmax_t)zip->entry->compressed_size); - return (ARCHIVE_WARN); + return (ARCHIVE_FAILED); } /* Size field only stores the lower 32 bits of the actual * size. */ @@ -3054,18 +3216,7 @@ archive_read_format_zip_read_data(struct archive_read *a, "(read %jd, expected %jd)\n", (intmax_t)zip->entry_uncompressed_bytes_read, (intmax_t)zip->entry->uncompressed_size); - return (ARCHIVE_WARN); - } - /* Check computed CRC against header */ - if ((!zip->hctx_valid || - zip->entry->aes_extra.vendor != AES_VENDOR_AE_2) && - zip->entry->crc32 != zip->entry_crc32 - && !zip->ignore_crc32) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP bad CRC: 0x%lx should be 0x%lx", - (unsigned long)zip->entry_crc32, - (unsigned long)zip->entry->crc32); - return (ARCHIVE_WARN); + return (ARCHIVE_FAILED); } } @@ -3932,6 +4083,17 @@ slurp_central_directory(struct archive_read *a, struct archive_entry* entry, } else { /* Generate resource fork name to find its * resource file at zip->tree_rsrc. */ + + /* If this is an entry ending with slash, + * make the resource for name slash-less + * as the actual resource fork doesn't end with '/'. + */ + size_t tmp_length = filename_length; + if (tmp_length > 0 && name[tmp_length - 1] == '/') { + tmp_length--; + r = rsrc_basename(name, tmp_length); + } + archive_strcpy(&(zip_entry->rsrcname), "__MACOSX/"); archive_strncat(&(zip_entry->rsrcname), @@ -3939,7 +4101,7 @@ slurp_central_directory(struct archive_read *a, struct archive_entry* entry, archive_strcat(&(zip_entry->rsrcname), "._"); archive_strncat(&(zip_entry->rsrcname), name + (r - name), - filename_length - (r - name)); + tmp_length - (r - name)); /* Register an entry to RB tree to sort it by * file offset. */ __archive_rb_tree_insert_node(&zip->tree, diff --git a/libarchive-clib/c/archive_string.c b/libarchive-clib/c/archive_string.c index accf526..f39677a 100644 --- a/libarchive-clib/c/archive_string.c +++ b/libarchive-clib/c/archive_string.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33:22Z kientzle $"); /* * Basic resizable string support, to simplify manipulating arbitrary-sized @@ -553,6 +552,8 @@ archive_wstring_append_from_mbs_in_codepage(struct archive_wstring *dest, } else mbflag = MB_PRECOMPOSED; + mbflag |= MB_ERR_INVALID_CHARS; + buffsize = dest->length + length + 1; do { /* Allocate memory for WCS. */ @@ -1527,7 +1528,7 @@ get_current_codepage(void) p = strrchr(locale, '.'); if (p == NULL) return (GetACP()); - if (strcmp(p+1, "utf8") == 0) + if ((strcmp(p+1, "utf8") == 0) || (strcmp(p+1, "UTF-8") == 0)) return CP_UTF8; cp = my_atoi(p+1); if ((int)cp <= 0) @@ -4227,6 +4228,17 @@ archive_mstring_update_utf8(struct archive *a, struct archive_mstring *aes, if (sc == NULL) return (-1);/* Couldn't allocate memory for sc. */ r = archive_strcpy_l(&(aes->aes_mbs), utf8, sc); + +#if defined(_WIN32) && !defined(__CYGWIN__) + /* On failure, make an effort to convert UTF8 to WCS as the active code page + * may not be able to represent all characters in the string */ + if (r != 0) { + if (archive_wstring_append_from_mbs_in_codepage(&(aes->aes_wcs), + aes->aes_utf8.s, aes->aes_utf8.length, sc) == 0) + aes->aes_set = AES_SET_UTF8 | AES_SET_WCS; + } +#endif + if (a == NULL) free_sconv_object(sc); if (r != 0) diff --git a/libarchive-clib/c/archive_string.h b/libarchive-clib/c/archive_string.h index 49d7d30..e898786 100644 --- a/libarchive-clib/c/archive_string.h +++ b/libarchive-clib/c/archive_string.h @@ -21,9 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_string.h 201092 2009-12-28 02:26:06Z kientzle $ - * */ #ifndef ARCHIVE_STRING_H_INCLUDED diff --git a/libarchive-clib/c/archive_string_composition.h b/libarchive-clib/c/archive_string_composition.h index d0ac340..e917036 100644 --- a/libarchive-clib/c/archive_string_composition.h +++ b/libarchive-clib/c/archive_string_composition.h @@ -22,8 +22,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD$ - * */ /* diff --git a/libarchive-clib/c/archive_string_sprintf.c b/libarchive-clib/c/archive_string_sprintf.c index 969a560..c785e12 100644 --- a/libarchive-clib/c/archive_string_sprintf.c +++ b/libarchive-clib/c/archive_string_sprintf.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_string_sprintf.c 189435 2009-03-06 05:14:55Z kientzle $"); /* * The use of printf()-family functions can be troublesome diff --git a/libarchive-clib/c/archive_util.c b/libarchive-clib/c/archive_util.c index 40603c4..7b918fe 100644 --- a/libarchive-clib/c/archive_util.c +++ b/libarchive-clib/c/archive_util.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -256,10 +255,9 @@ __archive_mktempx(const char *tmpdir, wchar_t *template) #endif fd = -1; ws = NULL; + archive_string_init(&temp_name); if (template == NULL) { - archive_string_init(&temp_name); - /* Get a temporary directory. */ if (tmpdir == NULL) { size_t l; diff --git a/libarchive-clib/c/archive_version_details.c b/libarchive-clib/c/archive_version_details.c index bfb20ea..29be24f 100644 --- a/libarchive-clib/c/archive_version_details.c +++ b/libarchive-clib/c/archive_version_details.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); #ifdef HAVE_STDLIB_H #include diff --git a/libarchive-clib/c/archive_virtual.c b/libarchive-clib/c/archive_virtual.c index f509ee5..97e0b8a 100644 --- a/libarchive-clib/c/archive_virtual.c +++ b/libarchive-clib/c/archive_virtual.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_virtual.c 201098 2009-12-28 02:58:14Z kientzle $"); #include "archive.h" #include "archive_entry.h" diff --git a/libarchive-clib/c/archive_windows.c b/libarchive-clib/c/archive_windows.c index ebc5eef..bb540da 100644 --- a/libarchive-clib/c/archive_windows.c +++ b/libarchive-clib/c/archive_windows.c @@ -22,8 +22,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ /* diff --git a/libarchive-clib/c/archive_windows.h b/libarchive-clib/c/archive_windows.h index 47b7cb8..6b7006a 100644 --- a/libarchive-clib/c/archive_windows.h +++ b/libarchive-clib/c/archive_windows.h @@ -23,8 +23,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ /* diff --git a/libarchive-clib/c/archive_write.c b/libarchive-clib/c/archive_write.c index ec3c95c..b70bc78 100644 --- a/libarchive-clib/c/archive_write.c +++ b/libarchive-clib/c/archive_write.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write.c 201099 2009-12-28 03:03:00Z kientzle $"); /* * This file contains the "essential" portions of the write API, that @@ -115,7 +114,7 @@ archive_write_new(void) /* Initialize a block of nulls for padding purposes. */ a->null_length = 1024; - nulls = (unsigned char *)calloc(1, a->null_length); + nulls = (unsigned char *)calloc(a->null_length, sizeof(unsigned char)); if (nulls == NULL) { free(a); return (NULL); diff --git a/libarchive-clib/c/archive_write_add_filter.c b/libarchive-clib/c/archive_write_add_filter.c index 203f414..aa96251 100644 --- a/libarchive-clib/c/archive_write_add_filter.c +++ b/libarchive-clib/c/archive_write_add_filter.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_add_filter_b64encode.c b/libarchive-clib/c/archive_write_add_filter_b64encode.c index 87fdb73..084d195 100644 --- a/libarchive-clib/c/archive_write_add_filter_b64encode.c +++ b/libarchive-clib/c/archive_write_add_filter_b64encode.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_by_name.c b/libarchive-clib/c/archive_write_add_filter_by_name.c index ffa633c..fc62458 100644 --- a/libarchive-clib/c/archive_write_add_filter_by_name.c +++ b/libarchive-clib/c/archive_write_add_filter_by_name.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_add_filter_bzip2.c b/libarchive-clib/c/archive_write_add_filter_bzip2.c index 3e5c089..561e11b 100644 --- a/libarchive-clib/c/archive_write_add_filter_bzip2.c +++ b/libarchive-clib/c/archive_write_add_filter_bzip2.c @@ -26,8 +26,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_bzip2.c 201091 2009-12-28 02:22:41Z kientzle $"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_compress.c b/libarchive-clib/c/archive_write_add_filter_compress.c index 3ed269f..78afebd 100644 --- a/libarchive-clib/c/archive_write_add_filter_compress.c +++ b/libarchive-clib/c/archive_write_add_filter_compress.c @@ -58,8 +58,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_compress.c 201111 2009-12-28 03:33:05Z kientzle $"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_grzip.c b/libarchive-clib/c/archive_write_add_filter_grzip.c index 371102d..f8bb886 100644 --- a/libarchive-clib/c/archive_write_add_filter_grzip.c +++ b/libarchive-clib/c/archive_write_add_filter_grzip.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_gzip.c b/libarchive-clib/c/archive_write_add_filter_gzip.c index 8670d5c..a7fabbf 100644 --- a/libarchive-clib/c/archive_write_add_filter_gzip.c +++ b/libarchive-clib/c/archive_write_add_filter_gzip.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_gzip.c 201081 2009-12-28 02:04:42Z kientzle $"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_lrzip.c b/libarchive-clib/c/archive_write_add_filter_lrzip.c index e215f89..fe974c9 100644 --- a/libarchive-clib/c/archive_write_add_filter_lrzip.c +++ b/libarchive-clib/c/archive_write_add_filter_lrzip.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_lz4.c b/libarchive-clib/c/archive_write_add_filter_lz4.c index 6ac4503..24061a1 100644 --- a/libarchive-clib/c/archive_write_add_filter_lz4.c +++ b/libarchive-clib/c/archive_write_add_filter_lz4.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_lzop.c b/libarchive-clib/c/archive_write_add_filter_lzop.c index 3bd9062..8580e58 100644 --- a/libarchive-clib/c/archive_write_add_filter_lzop.c +++ b/libarchive-clib/c/archive_write_add_filter_lzop.c @@ -25,7 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); //#undef HAVE_LZO_LZOCONF_H //#undef HAVE_LZO_LZO1X_H diff --git a/libarchive-clib/c/archive_write_add_filter_none.c b/libarchive-clib/c/archive_write_add_filter_none.c index 3c06c64..b7aa6d4 100644 --- a/libarchive-clib/c/archive_write_add_filter_none.c +++ b/libarchive-clib/c/archive_write_add_filter_none.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_none.c 201080 2009-12-28 02:03:54Z kientzle $"); #include "archive.h" diff --git a/libarchive-clib/c/archive_write_add_filter_program.c b/libarchive-clib/c/archive_write_add_filter_program.c index c096e72..c661cc7 100644 --- a/libarchive-clib/c/archive_write_add_filter_program.c +++ b/libarchive-clib/c/archive_write_add_filter_program.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_program.c 201104 2009-12-28 03:14:30Z kientzle $"); #ifdef HAVE_SYS_WAIT_H # include diff --git a/libarchive-clib/c/archive_write_add_filter_uuencode.c b/libarchive-clib/c/archive_write_add_filter_uuencode.c index 1ad4589..42dec8d 100644 --- a/libarchive-clib/c/archive_write_add_filter_uuencode.c +++ b/libarchive-clib/c/archive_write_add_filter_uuencode.c @@ -25,8 +25,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_xz.c b/libarchive-clib/c/archive_write_add_filter_xz.c index 04bee90..18da082 100644 --- a/libarchive-clib/c/archive_write_add_filter_xz.c +++ b/libarchive-clib/c/archive_write_add_filter_xz.c @@ -26,8 +26,6 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_xz.c 201108 2009-12-28 03:28:21Z kientzle $"); - #ifdef HAVE_ERRNO_H #include #endif diff --git a/libarchive-clib/c/archive_write_add_filter_zstd.c b/libarchive-clib/c/archive_write_add_filter_zstd.c index c78e840..7ea3d18 100644 --- a/libarchive-clib/c/archive_write_add_filter_zstd.c +++ b/libarchive-clib/c/archive_write_add_filter_zstd.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2017 Sean Purcell + * Copyright (c) 2023-2024 Klara, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,12 +26,12 @@ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - - #ifdef HAVE_ERRNO_H #include #endif +#ifdef HAVE_LIMITS_H +#include +#endif #ifdef HAVE_STDINT_H #include #endif @@ -40,6 +41,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_ZSTD_H #include #endif @@ -55,15 +59,17 @@ struct private_data { int compression_level; int threads; int long_distance; -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream enum { running, finishing, resetting, } state; int frame_per_file; - size_t min_frame_size; - size_t max_frame_size; + size_t min_frame_in; + size_t max_frame_in; + size_t min_frame_out; + size_t max_frame_out; size_t cur_frame; size_t cur_frame_in; size_t cur_frame_out; @@ -96,7 +102,7 @@ static int archive_compressor_zstd_write(struct archive_write_filter *, static int archive_compressor_zstd_flush(struct archive_write_filter *); static int archive_compressor_zstd_close(struct archive_write_filter *); static int archive_compressor_zstd_free(struct archive_write_filter *); -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream static int drive_compressor(struct archive_write_filter *, struct private_data *, int, const void *, size_t); #endif @@ -130,10 +136,12 @@ archive_write_add_filter_zstd(struct archive *_a) data->compression_level = CLEVEL_DEFAULT; data->threads = 0; data->long_distance = 0; -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream data->frame_per_file = 0; - data->min_frame_size = 0; - data->max_frame_size = SIZE_MAX; + data->min_frame_in = 0; + data->max_frame_in = SIZE_MAX; + data->min_frame_out = 0; + data->max_frame_out = SIZE_MAX; data->cur_frame_in = 0; data->cur_frame_out = 0; data->cstream = ZSTD_createCStream(); @@ -162,7 +170,7 @@ static int archive_compressor_zstd_free(struct archive_write_filter *f) { struct private_data *data = (struct private_data *)f->data; -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream ZSTD_freeCStream(data->cstream); free(data->out.dst); #else @@ -173,7 +181,8 @@ archive_compressor_zstd_free(struct archive_write_filter *f) return (ARCHIVE_OK); } -static int string_to_number(const char *string, intmax_t *numberp) +static int +string_to_number(const char *string, intmax_t *numberp) { char *end; @@ -187,6 +196,43 @@ static int string_to_number(const char *string, intmax_t *numberp) return (ARCHIVE_OK); } +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream +static int +string_to_size(const char *string, size_t *numberp) +{ + uintmax_t number; + char *end; + unsigned int shift = 0; + + if (string == NULL || *string == '\0' || *string == '-') + return (ARCHIVE_WARN); + number = strtoumax(string, &end, 10); + if (end > string) { + if (*end == 'K' || *end == 'k') { + shift = 10; + end++; + } else if (*end == 'M' || *end == 'm') { + shift = 20; + end++; + } else if (*end == 'G' || *end == 'g') { + shift = 30; + end++; + } + if (*end == 'B' || *end == 'b') { + end++; + } + } + if (end == string || *end != '\0' || errno == EOVERFLOW) { + return (ARCHIVE_WARN); + } + if (number > (uintmax_t)SIZE_MAX >> shift) { + return (ARCHIVE_WARN); + } + *numberp = (size_t)(number << shift); + return (ARCHIVE_OK); +} +#endif + /* * Set write options. */ @@ -204,7 +250,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, /* If we don't have the library, hard-code the max level */ int minimum = CLEVEL_MIN; int maximum = CLEVEL_MAX; -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream maximum = ZSTD_maxCLevel(); #if ZSTD_VERSION_NUMBER >= MINVER_MINCLEVEL if (ZSTD_versionNumber() >= MINVER_MINCLEVEL) { @@ -226,34 +272,51 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, if (string_to_number(value, &threads) != ARCHIVE_OK) { return (ARCHIVE_WARN); } - if (threads < 0) { + +#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) + if (threads == 0) { + threads = sysconf(_SC_NPROCESSORS_ONLN); + } +#elif !defined(__CYGWIN__) && defined(_WIN32_WINNT) && \ + _WIN32_WINNT >= 0x0601 /* _WIN32_WINNT_WIN7 */ + if (threads == 0) { + DWORD winCores = GetActiveProcessorCount( + ALL_PROCESSOR_GROUPS); + threads = (intmax_t)winCores; + } +#endif + if (threads < 0 || threads > INT_MAX) { return (ARCHIVE_WARN); } data->threads = (int)threads; return (ARCHIVE_OK); -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream } else if (strcmp(key, "frame-per-file") == 0) { data->frame_per_file = 1; return (ARCHIVE_OK); - } else if (strcmp(key, "min-frame-size") == 0) { - intmax_t min_frame_size; - if (string_to_number(value, &min_frame_size) != ARCHIVE_OK) { + } else if (strcmp(key, "min-frame-in") == 0) { + if (string_to_size(value, &data->min_frame_in) != ARCHIVE_OK) { return (ARCHIVE_WARN); } - if (min_frame_size < 0) { + return (ARCHIVE_OK); + } else if (strcmp(key, "min-frame-out") == 0 || + strcmp(key, "min-frame-size") == 0) { + if (string_to_size(value, &data->min_frame_out) != ARCHIVE_OK) { return (ARCHIVE_WARN); } - data->min_frame_size = min_frame_size; return (ARCHIVE_OK); - } else if (strcmp(key, "max-frame-size") == 0) { - intmax_t max_frame_size; - if (string_to_number(value, &max_frame_size) != ARCHIVE_OK) { + } else if (strcmp(key, "max-frame-in") == 0 || + strcmp(key, "max-frame-size") == 0) { + if (string_to_size(value, &data->max_frame_in) != ARCHIVE_OK || + data->max_frame_in < 1024) { return (ARCHIVE_WARN); } - if (max_frame_size < 1024) { + return (ARCHIVE_OK); + } else if (strcmp(key, "max-frame-out") == 0) { + if (string_to_size(value, &data->max_frame_out) != ARCHIVE_OK || + data->max_frame_out < 1024) { return (ARCHIVE_WARN); } - data->max_frame_size = max_frame_size; return (ARCHIVE_OK); #endif } @@ -262,7 +325,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, if (string_to_number(value, &long_distance) != ARCHIVE_OK) { return (ARCHIVE_WARN); } -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR && ZSTD_VERSION_NUMBER >= MINVER_LONG +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream && ZSTD_VERSION_NUMBER >= MINVER_LONG ZSTD_bounds bounds = ZSTD_cParam_getBounds(ZSTD_c_windowLog); if (ZSTD_isError(bounds.error)) { int max_distance = ((int)(sizeof(size_t) == 4 ? 30 : 31)); @@ -287,7 +350,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, return (ARCHIVE_WARN); } -#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR +#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream /* * Setup callback. */ @@ -356,9 +419,12 @@ archive_compressor_zstd_flush(struct archive_write_filter *f) { struct private_data *data = (struct private_data *)f->data; - if (data->frame_per_file && data->state == running && - data->cur_frame_out > data->min_frame_size) - data->state = finishing; + if (data->frame_per_file && data->state == running) { + if (data->cur_frame_in > data->min_frame_in && + data->cur_frame_out > data->min_frame_out) { + data->state = finishing; + } + } return (drive_compressor(f, data, 1, NULL, 0)); } @@ -417,9 +483,11 @@ drive_compressor(struct archive_write_filter *f, data->total_in += in.pos - ipos; data->cur_frame_in += in.pos - ipos; data->cur_frame_out += data->out.pos - opos; - if (data->state == running && - data->cur_frame_in >= data->max_frame_size) { - data->state = finishing; + if (data->state == running) { + if (data->cur_frame_in >= data->max_frame_in || + data->cur_frame_out >= data->max_frame_out) { + data->state = finishing; + } } if (data->out.pos == data->out.size || (flush && data->out.pos > 0)) { @@ -438,7 +506,7 @@ drive_compressor(struct archive_write_filter *f, return (ARCHIVE_FATAL); } -#else /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */ +#else /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */ static int archive_compressor_zstd_open(struct archive_write_filter *f) @@ -500,4 +568,4 @@ archive_compressor_zstd_close(struct archive_write_filter *f) return __archive_write_program_close(f, data->pdata); } -#endif /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */ +#endif /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */ diff --git a/libarchive-clib/c/archive_write_disk_posix.c b/libarchive-clib/c/archive_write_disk_posix.c index c8c2e10..92db4ff 100644 --- a/libarchive-clib/c/archive_write_disk_posix.c +++ b/libarchive-clib/c/archive_write_disk_posix.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #if !defined(_WIN32) || defined(__CYGWIN__) @@ -4428,7 +4427,8 @@ fixup_appledouble(struct archive_write_disk *a, const char *pathname) #else la_stat(datafork.s, &st) == -1 || #endif - (st.st_mode & AE_IFMT) != AE_IFREG) + (((st.st_mode & AE_IFMT) != AE_IFREG) && + ((st.st_mode & AE_IFMT) != AE_IFDIR))) goto skip_appledouble; /* diff --git a/libarchive-clib/c/archive_write_disk_private.h b/libarchive-clib/c/archive_write_disk_private.h index 557d7e2..3efe2ba 100644 --- a/libarchive-clib/c/archive_write_disk_private.h +++ b/libarchive-clib/c/archive_write_disk_private.h @@ -22,8 +22,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_write_disk_private.h 201086 2009-12-28 02:17:53Z kientzle $ */ #ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_write_disk_set_standard_lookup.c b/libarchive-clib/c/archive_write_disk_set_standard_lookup.c index 5fccdb9..9641698 100644 --- a/libarchive-clib/c/archive_write_disk_set_standard_lookup.c +++ b/libarchive-clib/c/archive_write_disk_set_standard_lookup.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_disk_set_standard_lookup.c 201083 2009-12-28 02:09:57Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_disk_windows.c b/libarchive-clib/c/archive_write_disk_windows.c index 7b9ea74..774151a 100644 --- a/libarchive-clib/c/archive_write_disk_windows.c +++ b/libarchive-clib/c/archive_write_disk_windows.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #if defined(_WIN32) && !defined(__CYGWIN__) @@ -2595,7 +2594,7 @@ set_times(struct archive_write_disk *a, { #define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) #define WINTIME(sec, nsec) ((Int32x32To64(sec, 10000000) + EPOC_TIME)\ - + (((nsec)/1000)*10)) + + ((nsec)/100)) HANDLE hw = 0; ULARGE_INTEGER wintm; diff --git a/libarchive-clib/c/archive_write_open_fd.c b/libarchive-clib/c/archive_write_open_fd.c index b8d491f..a58ae04 100644 --- a/libarchive-clib/c/archive_write_open_fd.c +++ b/libarchive-clib/c/archive_write_open_fd.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_open_fd.c 201093 2009-12-28 02:28:44Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_write_open_file.c b/libarchive-clib/c/archive_write_open_file.c index bf5b55a..d787da3 100644 --- a/libarchive-clib/c/archive_write_open_file.c +++ b/libarchive-clib/c/archive_write_open_file.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_file.c,v 1.19 2007/01/09 08:05:56 kientzle Exp $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_write_open_filename.c b/libarchive-clib/c/archive_write_open_filename.c index 9ceefb1..7dc73d5 100644 --- a/libarchive-clib/c/archive_write_open_filename.c +++ b/libarchive-clib/c/archive_write_open_filename.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_open_filename.c 191165 2009-04-17 00:39:35Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include diff --git a/libarchive-clib/c/archive_write_open_memory.c b/libarchive-clib/c/archive_write_open_memory.c index a8a0b81..609cc47 100644 --- a/libarchive-clib/c/archive_write_open_memory.c +++ b/libarchive-clib/c/archive_write_open_memory.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_memory.c,v 1.3 2007/01/09 08:05:56 kientzle Exp $"); #include #include diff --git a/libarchive-clib/c/archive_write_private.h b/libarchive-clib/c/archive_write_private.h index 6522e65..f259ccb 100644 --- a/libarchive-clib/c/archive_write_private.h +++ b/libarchive-clib/c/archive_write_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $ */ #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED @@ -160,7 +158,7 @@ int __archive_write_program_write(struct archive_write_filter *, struct archive_write_program_data *, const void *, size_t); /* - * Get a encryption passphrase. + * Get an encryption passphrase. */ const char * __archive_write_get_passphrase(struct archive_write *a); #endif diff --git a/libarchive-clib/c/archive_write_set_format.c b/libarchive-clib/c/archive_write_set_format.c index 1f65fa4..f636cff 100644 --- a/libarchive-clib/c/archive_write_set_format.c +++ b/libarchive-clib/c/archive_write_set_format.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_set_format_7zip.c b/libarchive-clib/c/archive_write_set_format_7zip.c index bca48ba..c0ea9d6 100644 --- a/libarchive-clib/c/archive_write_set_format_7zip.c +++ b/libarchive-clib/c/archive_write_set_format_7zip.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_ar.c b/libarchive-clib/c/archive_write_set_format_ar.c index fc0de1e..38689d8 100644 --- a/libarchive-clib/c/archive_write_set_format_ar.c +++ b/libarchive-clib/c/archive_write_set_format_ar.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ar.c 201108 2009-12-28 03:28:21Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_by_name.c b/libarchive-clib/c/archive_write_set_format_by_name.c index bfb4b35..09519b1 100644 --- a/libarchive-clib/c/archive_write_set_format_by_name.c +++ b/libarchive-clib/c/archive_write_set_format_by_name.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_set_format_cpio_binary.c b/libarchive-clib/c/archive_write_set_format_cpio_binary.c index d6ce35a..7a010ee 100644 --- a/libarchive-clib/c/archive_write_set_format_cpio_binary.c +++ b/libarchive-clib/c/archive_write_set_format_cpio_binary.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_cpio_newc.c b/libarchive-clib/c/archive_write_set_format_cpio_newc.c index f0f3980..006736a 100644 --- a/libarchive-clib/c/archive_write_set_format_cpio_newc.c +++ b/libarchive-clib/c/archive_write_set_format_cpio_newc.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201160 2009-12-29 05:41:57Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_cpio_odc.c b/libarchive-clib/c/archive_write_set_format_cpio_odc.c index 091925a..426f779 100644 --- a/libarchive-clib/c/archive_write_set_format_cpio_odc.c +++ b/libarchive-clib/c/archive_write_set_format_cpio_odc.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_filter_by_ext.c b/libarchive-clib/c/archive_write_set_format_filter_by_ext.c index 9fe21e4..1bb33b0 100644 --- a/libarchive-clib/c/archive_write_set_format_filter_by_ext.c +++ b/libarchive-clib/c/archive_write_set_format_filter_by_ext.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_set_format_gnutar.c b/libarchive-clib/c/archive_write_set_format_gnutar.c index ec29c5c..a88350b 100644 --- a/libarchive-clib/c/archive_write_set_format_gnutar.c +++ b/libarchive-clib/c/archive_write_set_format_gnutar.c @@ -27,8 +27,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_gnu_tar.c 191579 2009-04-27 18:35:03Z gastal $"); - #ifdef HAVE_ERRNO_H #include @@ -389,7 +387,7 @@ archive_write_gnutar_header(struct archive_write *a, if (r != 0) { if (errno == ENOMEM) { archive_set_error(&a->archive, ENOMEM, - "Can't allocate memory for Pathame"); + "Can't allocate memory for pathname"); ret = ARCHIVE_FATAL; goto exit_write_header; } diff --git a/libarchive-clib/c/archive_write_set_format_mtree.c b/libarchive-clib/c/archive_write_set_format_mtree.c index 619b771..6db9d27 100644 --- a/libarchive-clib/c/archive_write_set_format_mtree.c +++ b/libarchive-clib/c/archive_write_set_format_mtree.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_mtree.c 201171 2009-12-29 06:39:07Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include diff --git a/libarchive-clib/c/archive_write_set_format_pax.c b/libarchive-clib/c/archive_write_set_format_pax.c index 1eb9a9a..e933330 100644 --- a/libarchive-clib/c/archive_write_set_format_pax.c +++ b/libarchive-clib/c/archive_write_set_format_pax.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_pax.c 201162 2009-12-29 05:47:46Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_private.h b/libarchive-clib/c/archive_write_set_format_private.h index e200227..ef9dee9 100644 --- a/libarchive-clib/c/archive_write_set_format_private.h +++ b/libarchive-clib/c/archive_write_set_format_private.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #ifndef ARCHIVE_WRITE_SET_FORMAT_PRIVATE_H_INCLUDED diff --git a/libarchive-clib/c/archive_write_set_format_shar.c b/libarchive-clib/c/archive_write_set_format_shar.c index 9e4931c..52ea6ad 100644 --- a/libarchive-clib/c/archive_write_set_format_shar.c +++ b/libarchive-clib/c/archive_write_set_format_shar.c @@ -25,7 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_shar.c 189438 2009-03-06 05:58:56Z kientzle $"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_ustar.c b/libarchive-clib/c/archive_write_set_format_ustar.c index d1a06bc..673487b 100644 --- a/libarchive-clib/c/archive_write_set_format_ustar.c +++ b/libarchive-clib/c/archive_write_set_format_ustar.c @@ -25,8 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ustar.c 191579 2009-04-27 18:35:03Z kientzle $"); - #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_v7tar.c b/libarchive-clib/c/archive_write_set_format_v7tar.c index 5994071..e3724a0 100644 --- a/libarchive-clib/c/archive_write_set_format_v7tar.c +++ b/libarchive-clib/c/archive_write_set_format_v7tar.c @@ -25,8 +25,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); - #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_warc.c b/libarchive-clib/c/archive_write_set_format_warc.c index 0ef003e..3d22e1f 100644 --- a/libarchive-clib/c/archive_write_set_format_warc.c +++ b/libarchive-clib/c/archive_write_set_format_warc.c @@ -26,7 +26,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_xar.c b/libarchive-clib/c/archive_write_set_format_xar.c index 7307757..2cf655d 100644 --- a/libarchive-clib/c/archive_write_set_format_xar.c +++ b/libarchive-clib/c/archive_write_set_format_xar.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include diff --git a/libarchive-clib/c/archive_write_set_format_zip.c b/libarchive-clib/c/archive_write_set_format_zip.c index 6821049..e37e7b5 100644 --- a/libarchive-clib/c/archive_write_set_format_zip.c +++ b/libarchive-clib/c/archive_write_set_format_zip.c @@ -30,7 +30,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_zip.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -132,7 +131,6 @@ struct zip { enum compression entry_compression; enum encryption entry_encryption; int entry_flags; - int entry_uses_zip64; int experiments; struct trad_enc_ctx tctx; char tctx_valid; @@ -523,6 +521,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) int ret, ret2 = ARCHIVE_OK; mode_t type; int version_needed = 10; +#define MIN_VERSION_NEEDED(x) do { if (version_needed < x) { version_needed = x; } } while (0) /* Ignore types of entries that we don't support. */ type = archive_entry_filetype(entry); @@ -557,12 +556,12 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) /* Reset information from last entry. */ zip->entry_offset = zip->written_bytes; zip->entry_uncompressed_limit = INT64_MAX; + /* Zero size values implies that we're using a trailing data descriptor */ zip->entry_compressed_size = 0; zip->entry_uncompressed_size = 0; zip->entry_compressed_written = 0; zip->entry_uncompressed_written = 0; zip->entry_flags = 0; - zip->entry_uses_zip64 = 0; zip->entry_crc32 = zip->crc32func(0, NULL, 0); zip->entry_encryption = 0; archive_entry_free(zip->entry); @@ -672,11 +671,11 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) zip->entry_crc32 = zip->crc32func(zip->entry_crc32, (const unsigned char *)slink, slink_size); zip->entry_compression = COMPRESSION_STORE; - version_needed = 20; + MIN_VERSION_NEEDED(20); } else if (type != AE_IFREG) { zip->entry_compression = COMPRESSION_STORE; zip->entry_uncompressed_limit = 0; - version_needed = 20; + MIN_VERSION_NEEDED(20); } else if (archive_entry_size_is_set(zip->entry)) { int64_t size = archive_entry_size(zip->entry); int64_t additional_size = 0; @@ -689,27 +688,27 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) if (zip->entry_compression == COMPRESSION_STORE) { zip->entry_compressed_size = size; zip->entry_uncompressed_size = size; - version_needed = 10; + MIN_VERSION_NEEDED(10); } else { zip->entry_uncompressed_size = size; - version_needed = 20; + MIN_VERSION_NEEDED(20); } if (zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) { switch (zip->entry_encryption) { case ENCRYPTION_TRADITIONAL: additional_size = TRAD_HEADER_SIZE; - version_needed = 20; + MIN_VERSION_NEEDED(20); break; case ENCRYPTION_WINZIP_AES128: additional_size = WINZIP_AES128_HEADER_SIZE + AUTH_CODE_SIZE; - version_needed = 20; + MIN_VERSION_NEEDED(20); break; case ENCRYPTION_WINZIP_AES256: additional_size = WINZIP_AES256_HEADER_SIZE + AUTH_CODE_SIZE; - version_needed = 20; + MIN_VERSION_NEEDED(20); break; case ENCRYPTION_NONE: default: @@ -733,8 +732,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) || (zip->entry_uncompressed_size + additional_size > ZIP_4GB_MAX) || (zip->entry_uncompressed_size > ZIP_4GB_MAX_UNCOMPRESSED && zip->entry_compression != COMPRESSION_STORE)) { - zip->entry_uses_zip64 = 1; - version_needed = 45; + MIN_VERSION_NEEDED(45); } /* We may know the size, but never the CRC. */ @@ -742,7 +740,6 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) } else { /* We don't know the size. Use the default * compression unless specified otherwise. - * We enable Zip64 extensions unless we're told not to. */ zip->entry_compression = zip->requested_compression; @@ -752,12 +749,12 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) zip->entry_flags |= ZIP_ENTRY_FLAG_LENGTH_AT_END; if ((zip->flags & ZIP_FLAG_AVOID_ZIP64) == 0) { - zip->entry_uses_zip64 = 1; - version_needed = 45; + /* We might use zip64 extensions, so require 4.5 */ + MIN_VERSION_NEEDED(45); } else if (zip->entry_compression == COMPRESSION_STORE) { - version_needed = 10; + MIN_VERSION_NEEDED(10); } else { - version_needed = 20; + MIN_VERSION_NEEDED(20); } if (zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) { @@ -765,8 +762,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) case ENCRYPTION_TRADITIONAL: case ENCRYPTION_WINZIP_AES128: case ENCRYPTION_WINZIP_AES256: - if (version_needed < 20) - version_needed = 20; + MIN_VERSION_NEEDED(20); break; case ENCRYPTION_NONE: default: @@ -787,16 +783,8 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) archive_le16enc(local_header + 8, zip->entry_compression); archive_le32enc(local_header + 10, dos_time(archive_entry_mtime(zip->entry))); - archive_le32enc(local_header + 14, zip->entry_crc32); - if (zip->entry_uses_zip64) { - /* Zip64 data in the local header "must" include both - * compressed and uncompressed sizes AND those fields - * are included only if these are 0xffffffff; - * THEREFORE these must be set this way, even if we - * know one of them is smaller. */ - archive_le32enc(local_header + 18, ZIP_4GB_MAX); - archive_le32enc(local_header + 22, ZIP_4GB_MAX); - } else { + if ((zip->entry_flags & ZIP_ENTRY_FLAG_LENGTH_AT_END) == 0) { + archive_le32enc(local_header + 14, zip->entry_crc32); archive_le32enc(local_header + 18, (uint32_t)zip->entry_compressed_size); archive_le32enc(local_header + 22, (uint32_t)zip->entry_uncompressed_size); } @@ -842,42 +830,19 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) * the local file header and the central directory. * We format them once and then duplicate them. */ - /* UT timestamp, length depends on what timestamps are set. */ - memcpy(e, "UT", 2); - archive_le16enc(e + 2, - 1 - + (archive_entry_mtime_is_set(entry) ? 4 : 0) - + (archive_entry_atime_is_set(entry) ? 4 : 0) - + (archive_entry_ctime_is_set(entry) ? 4 : 0)); - e += 4; - *e++ = - (archive_entry_mtime_is_set(entry) ? 1 : 0) - | (archive_entry_atime_is_set(entry) ? 2 : 0) - | (archive_entry_ctime_is_set(entry) ? 4 : 0); - if (archive_entry_mtime_is_set(entry)) { - archive_le32enc(e, (uint32_t)archive_entry_mtime(entry)); - e += 4; - } - if (archive_entry_atime_is_set(entry)) { - archive_le32enc(e, (uint32_t)archive_entry_atime(entry)); + /* ux Unix extra data, length 11, version 1 */ + if (archive_entry_uid_is_set(entry) || archive_entry_gid_is_set(entry)) { + /* TODO: If uid < 64k, use 2 bytes, ditto for gid. */ + memcpy(e, "ux\013\000\001", 5); + e += 5; + *e++ = 4; /* Length of following UID */ + archive_le32enc(e, (uint32_t)archive_entry_uid(entry)); e += 4; - } - if (archive_entry_ctime_is_set(entry)) { - archive_le32enc(e, (uint32_t)archive_entry_ctime(entry)); + *e++ = 4; /* Length of following GID */ + archive_le32enc(e, (uint32_t)archive_entry_gid(entry)); e += 4; } - /* ux Unix extra data, length 11, version 1 */ - /* TODO: If uid < 64k, use 2 bytes, ditto for gid. */ - memcpy(e, "ux\013\000\001", 5); - e += 5; - *e++ = 4; /* Length of following UID */ - archive_le32enc(e, (uint32_t)archive_entry_uid(entry)); - e += 4; - *e++ = 4; /* Length of following GID */ - archive_le32enc(e, (uint32_t)archive_entry_gid(entry)); - e += 4; - /* AES extra data field: WinZIP AES information, ID=0x9901 */ if ((zip->entry_flags & ZIP_ENTRY_FLAG_ENCRYPTED) && (zip->entry_encryption == ENCRYPTION_WINZIP_AES128 @@ -904,7 +869,7 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) e += 2; } - /* Copy UT ,ux, and AES-extra into central directory as well. */ + /* Copy ux, AES-extra into central directory as well. */ zip->file_header_extra_offset = zip->central_directory_bytes; cd_extra = cd_alloc(zip, e - local_extra); memcpy(cd_extra, local_extra, e - local_extra); @@ -916,17 +881,50 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) * archive_write_zip_finish_entry() below. */ - /* "[Zip64 entry] in the local header MUST include BOTH - * original [uncompressed] and compressed size fields." */ - if (zip->entry_uses_zip64) { - unsigned char *zip64_start = e; - memcpy(e, "\001\000\020\000", 4); + /* UT timestamp: length depends on what timestamps are set. + * This header appears in the Central Directory also, but + * according to Info-Zip specification, the CD form + * only holds mtime, so we format it separately. */ + if (archive_entry_mtime_is_set(entry) + || archive_entry_atime_is_set(entry) + || archive_entry_ctime_is_set(entry)) { + unsigned char *ut = e; + memcpy(e, "UT\000\000", 4); + e += 4; + *e++ = (archive_entry_mtime_is_set(entry) ? 1 : 0) + | (archive_entry_atime_is_set(entry) ? 2 : 0) + | (archive_entry_ctime_is_set(entry) ? 4 : 0); + if (archive_entry_mtime_is_set(entry)) { + archive_le32enc(e, (uint32_t)archive_entry_mtime(entry)); + e += 4; + } + if (archive_entry_atime_is_set(entry)) { + archive_le32enc(e, (uint32_t)archive_entry_atime(entry)); + e += 4; + } + if (archive_entry_ctime_is_set(entry)) { + archive_le32enc(e, (uint32_t)archive_entry_ctime(entry)); + e += 4; + } + archive_le16enc(ut + 2, e - ut - 4); + } + + /* + * Note about Zip64 Extended Information Extra Field: + * Because libarchive always writes in a streaming + * fashion, we never know the CRC when we're writing + * the local header. So we have to use length-at-end, which + * prevents us from putting size information into a Zip64 + * extra field. However, apparently some readers find it + * a helpful clue to have an empty such field so they + * can expect a 64-bit length-at-end marker. + */ + if (archive_entry_size_is_set(zip->entry) + && (zip->entry_uncompressed_size > ZIP_4GB_MAX + || zip->entry_compressed_size > ZIP_4GB_MAX)) { + /* Header ID 0x0001, size 0 */ + memcpy(e, "\001\000\000\000", 4); e += 4; - archive_le64enc(e, zip->entry_uncompressed_size); - e += 8; - archive_le64enc(e, zip->entry_compressed_size); - e += 8; - archive_le16enc(zip64_start + 2, (uint16_t)(e - (zip64_start + 4))); } if (zip->flags & ZIP_FLAG_EXPERIMENT_xl) { @@ -1205,7 +1203,9 @@ archive_write_zip_finish_entry(struct archive_write *a) archive_le32enc(d + 4, 0);/* no CRC.*/ else archive_le32enc(d + 4, zip->entry_crc32); - if (zip->entry_uses_zip64) { + if (zip->entry_compressed_written > ZIP_4GB_MAX + || zip->entry_uncompressed_written > ZIP_4GB_MAX + || zip->flags & ZIP_FLAG_FORCE_ZIP64) { archive_le64enc(d + 8, (uint64_t)zip->entry_compressed_written); archive_le64enc(d + 16, @@ -1224,23 +1224,60 @@ archive_write_zip_finish_entry(struct archive_write *a) return (ARCHIVE_FATAL); } - /* Append Zip64 extra data to central directory information. */ - if (zip->entry_compressed_written > ZIP_4GB_MAX - || zip->entry_uncompressed_written > ZIP_4GB_MAX + /* UT timestamp: Info-Zip specifies that _only_ the mtime should + * be recorded here; ctime and atime are also included in the + * local file descriptor. */ + if (archive_entry_mtime_is_set(zip->entry)) { + unsigned char ut[9]; + unsigned char *u = ut, *ud; + memcpy(u, "UT\005\000\001", 5); + u += 5; + archive_le32enc(u, (uint32_t)archive_entry_mtime(zip->entry)); + u += 4; + ud = cd_alloc(zip, u - ut); + if (ud == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + memcpy(ud, ut, u - ut); + } + + /* Fill in size information in the central directory entry. */ + /* Fix up central directory file header. */ + if (zip->cctx_valid && zip->aes_vendor == AES_VENDOR_AE_2) + archive_le32enc(zip->file_header + 16, 0);/* no CRC.*/ + else + archive_le32enc(zip->file_header + 16, zip->entry_crc32); + /* Truncate to 32 bits; we'll fix up below. */ + archive_le32enc(zip->file_header + 20, (uint32_t)zip->entry_compressed_written); + archive_le32enc(zip->file_header + 24, (uint32_t)zip->entry_uncompressed_written); + archive_le16enc(zip->file_header + 30, + (uint16_t)(zip->central_directory_bytes - zip->file_header_extra_offset)); + archive_le32enc(zip->file_header + 42, (uint32_t)zip->entry_offset); + + /* If any of the values immediately above are too large, we'll + * need to put the corresponding value in a Zip64 extra field + * and set the central directory value to 0xffffffff as a flag. */ + if (zip->entry_compressed_written >= ZIP_4GB_MAX + || zip->entry_uncompressed_written >= ZIP_4GB_MAX || zip->entry_offset > ZIP_4GB_MAX) { unsigned char zip64[32]; unsigned char *z = zip64, *zd; memcpy(z, "\001\000\000\000", 4); z += 4; if (zip->entry_uncompressed_written >= ZIP_4GB_MAX) { + archive_le32enc(zip->file_header + 24, ZIP_4GB_MAX); archive_le64enc(z, zip->entry_uncompressed_written); z += 8; } if (zip->entry_compressed_written >= ZIP_4GB_MAX) { + archive_le32enc(zip->file_header + 20, ZIP_4GB_MAX); archive_le64enc(z, zip->entry_compressed_written); z += 8; } if (zip->entry_offset >= ZIP_4GB_MAX) { + archive_le32enc(zip->file_header + 42, ZIP_4GB_MAX); archive_le64enc(z, zip->entry_offset); z += 8; } diff --git a/libarchive-clib/c/archive_write_set_options.c b/libarchive-clib/c/archive_write_set_options.c index 962309a..be2a606 100644 --- a/libarchive-clib/c/archive_write_set_options.c +++ b/libarchive-clib/c/archive_write_set_options.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #include "archive_write_private.h" #include "archive_options_private.h" diff --git a/libarchive-clib/c/archive_write_set_passphrase.c b/libarchive-clib/c/archive_write_set_passphrase.c index 710ecba..f871c8e 100644 --- a/libarchive-clib/c/archive_write_set_passphrase.c +++ b/libarchive-clib/c/archive_write_set_passphrase.c @@ -24,21 +24,15 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include #endif #include "archive_write_private.h" -int -archive_write_set_passphrase(struct archive *_a, const char *p) +static int +set_passphrase(struct archive_write *a, const char *p) { - struct archive_write *a = (struct archive_write *)_a; - - archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, - "archive_write_set_passphrase"); - if (p == NULL || p[0] == '\0') { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Empty passphrase is unacceptable"); @@ -55,6 +49,18 @@ archive_write_set_passphrase(struct archive *_a, const char *p) } +int +archive_write_set_passphrase(struct archive *_a, const char *p) +{ + struct archive_write *a = (struct archive_write *)_a; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, + "archive_write_set_passphrase"); + + return (set_passphrase(a, p)); +} + + int archive_write_set_passphrase_callback(struct archive *_a, void *client_data, archive_passphrase_callback *cb) @@ -81,15 +87,9 @@ __archive_write_get_passphrase(struct archive_write *a) const char *p; p = a->passphrase_callback(&a->archive, a->passphrase_client_data); - if (p != NULL) { - a->passphrase = strdup(p); - if (a->passphrase == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for passphrase"); - return (NULL); - } - return (a->passphrase); - } + set_passphrase(a, p); + a->passphrase_callback = NULL; + a->passphrase_client_data = NULL; } - return (NULL); + return (a->passphrase); } diff --git a/libarchive-clib/c/config_freebsd.h b/libarchive-clib/c/config_freebsd.h index 669f272..d0f3e23 100644 --- a/libarchive-clib/c/config_freebsd.h +++ b/libarchive-clib/c/config_freebsd.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ */ #define __LIBARCHIVE_CONFIG_H_INCLUDED 1 diff --git a/libarchive-clib/c/filter_fork.h b/libarchive-clib/c/filter_fork.h index 2bf290c..aeab70a 100644 --- a/libarchive-clib/c/filter_fork.h +++ b/libarchive-clib/c/filter_fork.h @@ -21,8 +21,6 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: head/lib/libarchive/filter_fork.h 201087 2009-12-28 02:18:26Z kientzle $ */ #ifndef FILTER_FORK_H diff --git a/libarchive-clib/c/filter_fork_posix.c b/libarchive-clib/c/filter_fork_posix.c index 62085a7..c895c08 100644 --- a/libarchive-clib/c/filter_fork_posix.c +++ b/libarchive-clib/c/filter_fork_posix.c @@ -30,8 +30,6 @@ #if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \ (defined(HAVE_FORK) || defined(HAVE_VFORK) || defined(HAVE_POSIX_SPAWNP)) -__FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $"); - #if defined(HAVE_SYS_TYPES_H) # include #endif diff --git a/libarchive-clib/libarchive-clib.cabal b/libarchive-clib/libarchive-clib.cabal index a3a31e6..a29976f 100644 --- a/libarchive-clib/libarchive-clib.cabal +++ b/libarchive-clib/libarchive-clib.cabal @@ -1,6 +1,6 @@ cabal-version: 2.0 name: libarchive-clib -version: 3.7.2 +version: 3.7.4 license: OtherLicense license-file: LICENSE copyright: Copyright: (c) 2018-2020 Vanessa McHale