Delete the repo contents. Add a README.
flutter/engine now depends directly on the chrome fork. The contents of this repo are triggering false-alarms by overzealous security scanners. We need to keep this repo around to avoid breaking checkouts of old versions of fluttter/engine. This CL deletes the contents to avoid triggering scanners, and not break old checkouts.
Change-Id: I3f3188ce9c7ed74ac3838c02281f7014c620918f
Reviewed-on: https://flutter-review.googlesource.com/c/third_party/zlib/+/41920
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Jason Simmons <jsimmons@google.com>
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 1953972..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,26 +0,0 @@
-# commonly generated files
-*.pyc
-*~
-.*.sw?
-.ccls-cache
-.checkstyle
-.clangd
-.classpath
-.cproject
-.DS_Store
-.gdb_history
-.gdbinit
-.idea
-.ignore
-.landmines
-.packages
-.project
-.pub
-.pydevproject
-.vscode
-.cache
-compile_commands.json
-cscope.*
-Session.vim
-tags
-Thumbs.db
diff --git a/BUILD.gn b/BUILD.gn
deleted file mode 100644
index 722687b..0000000
--- a/BUILD.gn
+++ /dev/null
@@ -1,379 +0,0 @@
-# Copyright (c) 2013 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-
-if (current_cpu == "arm" || current_cpu == "arm64") {
- import("//build/config/arm.gni")
-}
-
-config("zlib_config") {
- include_dirs = [ "." ]
-}
-
-config("zlib_internal_config") {
- defines = [ "ZLIB_IMPLEMENTATION" ]
-}
-
-use_arm_neon_optimizations = false
-if ((current_cpu == "arm" || current_cpu == "arm64") &&
- !(is_win && !is_clang)) {
- # TODO(richard.townsend@arm.com): Optimizations temporarily disabled for
- # Windows on Arm MSVC builds, see http://crbug.com/v8/10012.
- if (arm_use_neon) {
- use_arm_neon_optimizations = true
- }
-}
-
-use_x86_x64_optimizations =
- (current_cpu == "x86" || current_cpu == "x64") && !is_ios
-
-config("zlib_adler32_simd_config") {
- if (use_x86_x64_optimizations) {
- defines = [ "ADLER32_SIMD_SSSE3" ]
- if (is_win) {
- defines += [ "X86_WINDOWS" ]
- } else {
- defines += [ "X86_NOT_WINDOWS" ]
- }
- }
-
- if (use_arm_neon_optimizations) {
- defines = [ "ADLER32_SIMD_NEON" ]
- }
-}
-
-source_set("zlib_adler32_simd") {
- visibility = [ ":*" ]
-
- if (use_x86_x64_optimizations) {
- sources = [
- "adler32_simd.c",
- "adler32_simd.h",
- ]
-
- if (!is_win || is_clang) {
- cflags = [ "-mssse3" ]
- }
- }
-
- if (use_arm_neon_optimizations) {
- sources = [
- "adler32_simd.c",
- "adler32_simd.h",
- ]
- }
-
- configs += [ ":zlib_internal_config" ]
-
- public_configs = [ ":zlib_adler32_simd_config" ]
-}
-
-if (use_arm_neon_optimizations) {
- config("zlib_arm_crc32_config") {
- # Disabled for iPhone, as described in DDI0487C_a_armv8_arm:
- # "All implementations of the ARMv8.1 architecture are required to
- # implement the CRC32* instructions. These are optional in ARMv8.0."
- if (!is_ios) {
- defines = [ "CRC32_ARMV8_CRC32" ]
- if (is_android) {
- defines += [ "ARMV8_OS_ANDROID" ]
- } else if (is_linux || is_chromeos) {
- defines += [ "ARMV8_OS_LINUX" ]
- } else if (is_mac) {
- defines += [ "ARMV8_OS_MACOS" ]
- } else if (is_fuchsia) {
- defines += [ "ARMV8_OS_FUCHSIA" ]
- } else if (is_win) {
- defines += [ "ARMV8_OS_WINDOWS" ]
- } else {
- assert(false, "Unsupported ARM OS")
- }
- }
- }
-
- source_set("zlib_arm_crc32") {
- visibility = [ ":*" ]
-
- if (!is_ios) {
- include_dirs = [ "." ]
-
- if (!is_win && !is_clang) {
- assert(!use_thin_lto,
- "ThinLTO fails mixing different module-level targets")
- cflags_c = [ "-march=armv8-a+crc" ]
- }
-
- sources = [
- "crc32_simd.c",
- "crc32_simd.h",
- ]
- }
-
- configs += [ ":zlib_internal_config" ]
-
- public_configs = [ ":zlib_arm_crc32_config" ]
- }
-}
-
-config("zlib_inflate_chunk_simd_config") {
- if (use_x86_x64_optimizations) {
- defines = [ "INFLATE_CHUNK_SIMD_SSE2" ]
-
- if (current_cpu == "x64") {
- defines += [ "INFLATE_CHUNK_READ_64LE" ]
- }
- }
-
- if (use_arm_neon_optimizations) {
- defines = [ "INFLATE_CHUNK_SIMD_NEON" ]
-
- if (current_cpu == "arm64") {
- defines += [ "INFLATE_CHUNK_READ_64LE" ]
- }
- }
-}
-
-source_set("zlib_inflate_chunk_simd") {
- visibility = [ ":*" ]
-
- if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
- include_dirs = [ "." ]
-
- sources = [
- "contrib/optimizations/chunkcopy.h",
- "contrib/optimizations/inffast_chunk.c",
- "contrib/optimizations/inffast_chunk.h",
- "contrib/optimizations/inflate.c",
- ]
- }
-
- configs += [ ":zlib_internal_config" ]
-
- # Needed for MSVC, which is still supported by V8 and PDFium. zlib uses K&R C
- # style function declarations, which triggers warning C4131.
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [ "//build/config/compiler:no_chromium_code" ]
-
- public_configs = [ ":zlib_inflate_chunk_simd_config" ]
-}
-
-config("zlib_crc32_simd_config") {
- if (use_x86_x64_optimizations) {
- defines = [ "CRC32_SIMD_SSE42_PCLMUL" ]
- }
-}
-
-source_set("zlib_crc32_simd") {
- visibility = [ ":*" ]
-
- if (use_x86_x64_optimizations) {
- sources = [
- "crc32_simd.c",
- "crc32_simd.h",
- ]
-
- if (!is_win || is_clang) {
- cflags = [
- "-msse4.2",
- "-mpclmul",
- ]
- }
- }
-
- configs += [ ":zlib_internal_config" ]
-
- public_configs = [ ":zlib_crc32_simd_config" ]
-}
-
-config("zlib_x86_simd_config") {
- if (use_x86_x64_optimizations) {
- defines = [
- "CRC32_SIMD_SSE42_PCLMUL",
- "DEFLATE_FILL_WINDOW_SSE2",
- ]
- }
-}
-
-source_set("zlib_x86_simd") {
- visibility = [ ":*" ]
-
- if (use_x86_x64_optimizations) {
- sources = [
- "crc_folding.c",
- "fill_window_sse.c",
- ]
-
- if (!is_win || is_clang) {
- cflags = [
- "-msse4.2",
- "-mpclmul",
- ]
- }
- }
-
- configs += [ ":zlib_internal_config" ]
-
- public_configs = [ ":zlib_x86_simd_config" ]
-}
-
-config("zlib_warnings") {
- if (is_clang && use_x86_x64_optimizations) {
- cflags = [ "-Wno-incompatible-pointer-types" ]
- }
-}
-
-component("zlib") {
- if (!is_win) {
- # Don't stomp on "libzlib" on other platforms.
- output_name = "chrome_zlib"
- }
-
- sources = [
- "adler32.c",
- "chromeconf.h",
- "compress.c",
- "contrib/optimizations/insert_string.h",
- "cpu_features.c",
- "cpu_features.h",
- "crc32.c",
- "crc32.h",
- "deflate.c",
- "deflate.h",
- "gzclose.c",
- "gzguts.h",
- "gzlib.c",
- "gzread.c",
- "gzwrite.c",
- "infback.c",
- "inffast.c",
- "inffast.h",
- "inffixed.h",
- "inflate.h",
- "inftrees.c",
- "inftrees.h",
- "trees.c",
- "trees.h",
- "uncompr.c",
- "zconf.h",
- "zlib.h",
- "zutil.c",
- "zutil.h",
- ]
-
- defines = []
- deps = []
-
- if (!use_x86_x64_optimizations && !use_arm_neon_optimizations) {
- # Apparently android_cronet bot builds with NEON disabled and
- # we also should disable optimizations for iOS@x86 (a.k.a. simulator).
- defines += [ "CPU_NO_SIMD" ]
- }
-
- if (is_ios) {
- # iOS@ARM is a special case where we always have NEON but don't check
- # for crypto extensions.
- # TODO(cavalcantii): verify what is the current state of CPU features
- # shipped on latest iOS devices.
- defines += [ "ARM_OS_IOS" ]
- }
-
- if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
- deps += [
- ":zlib_adler32_simd",
- ":zlib_inflate_chunk_simd",
- ]
-
- if (use_x86_x64_optimizations) {
- deps += [ ":zlib_crc32_simd" ]
- } else if (use_arm_neon_optimizations) {
- sources += [ "contrib/optimizations/slide_hash_neon.h" ]
- deps += [ ":zlib_arm_crc32" ]
- }
- } else {
- sources += [ "inflate.c" ]
- }
-
- deps += [ ":zlib_x86_simd" ]
-
- if (is_android) {
- import("//build/config/android/config.gni")
- if (defined(android_ndk_root) && android_ndk_root != "") {
- deps += [ "//third_party/android_tools:cpu_features" ]
- } else {
- assert(false, "CPU detection requires the Android NDK")
- }
- }
-
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [ "//build/config/compiler:no_chromium_code" ]
-
- public_configs = [ ":zlib_config" ]
-
- configs += [
- ":zlib_internal_config",
-
- # Must be after no_chromium_code for warning flags to be ordered correctly.
- ":zlib_warnings",
- ]
-
- allow_circular_includes_from = deps
-}
-
-config("minizip_warnings") {
- visibility = [ ":*" ]
-
- if (is_clang) {
- # zlib uses `if ((a == b))` for some reason.
- cflags = [ "-Wno-parentheses-equality" ]
- }
-}
-
-static_library("minizip") {
- sources = [
- "contrib/minizip/ioapi.c",
- "contrib/minizip/ioapi.h",
- "contrib/minizip/iowin32.c",
- "contrib/minizip/iowin32.h",
- "contrib/minizip/unzip.c",
- "contrib/minizip/unzip.h",
- "contrib/minizip/zip.c",
- "contrib/minizip/zip.h",
- ]
-
- if (!is_win) {
- sources -= [
- "contrib/minizip/iowin32.c",
- "contrib/minizip/iowin32.h",
- ]
- }
-
- if (is_mac || is_ios || is_android || is_fuchsia) {
- # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
- # use fopen, ftell, and fseek instead on these systems.
- defines = [ "USE_FILE32API" ]
- }
-
- deps = [ ":zlib" ]
-
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [ "//build/config/compiler:no_chromium_code" ]
-
- public_configs = [ ":zlib_config" ]
-
- configs += [
- # Must be after no_chromium_code for warning flags to be ordered correctly.
- ":minizip_warnings",
- ]
-}
-
-executable("zlib_bench") {
- include_dirs = [ "." ]
-
- sources = [ "contrib/bench/zlib_bench.cc" ]
-
- deps = [ ":zlib" ]
-
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [ "//build/config/compiler:no_chromium_code" ]
-}
diff --git a/DEPS b/DEPS
deleted file mode 100644
index b6dcfc6..0000000
--- a/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+testing/gtest",
-]
\ No newline at end of file
diff --git a/README b/README
new file mode 100644
index 0000000..2e753bf
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+This repo is no longer used, but should not be deleted so that old versions of flutter/engine can still be fetched.
diff --git a/README.chromium b/README.chromium
deleted file mode 100644
index c3c1ef6..0000000
--- a/README.chromium
+++ /dev/null
@@ -1,29 +0,0 @@
-Name: zlib
-Short Name: zlib
-URL: http://zlib.net/
-Version: 1.2.11
-CPEPrefix: cpe:/a:zlib:zlib:1.2.11
-Security Critical: yes
-License: Custom license
-License File: LICENSE
-License Android Compatible: yes
-
-Description:
-"A massively spiffy yet delicately unobtrusive compression library."
-
-zlib is a free, general-purpose, legally unencumbered lossless data-compression
-library. zlib implements the "deflate" compression algorithm described by RFC
-1951, which combines the LZ77 (Lempel-Ziv) algorithm with Huffman coding. zlib
-also implements the zlib (RFC 1950) and gzip (RFC 1952) wrapper formats.
-
-Local Modifications:
- - Only source code from the zlib distribution used to build the zlib and
- minizip libraries are present. Many other files have been omitted. Only *.c
- and *.h files from the upstream root directory and contrib/minizip were
- imported.
- - The contents of the google directory are original Chromium-specific
- additions.
- - Added chromeconf.h
- - Plus the changes in 'patches' folder.
- - Code in contrib/ other than contrib/minizip was added to match zlib's
- contributor layout.
diff --git a/adler32.c b/adler32.c
deleted file mode 100644
index 696773a..0000000
--- a/adler32.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-2011, 2016 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#include "zutil.h"
-
-local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
-
-#define BASE 65521U /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
-#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
-#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
-#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
-#define DO16(buf) DO8(buf,0); DO8(buf,8);
-
-/* use NO_DIVIDE if your processor does not do division in hardware --
- try it both ways to see which is faster */
-#ifdef NO_DIVIDE
-/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
- (thank you to John Reiser for pointing this out) */
-# define CHOP(a) \
- do { \
- unsigned long tmp = a >> 16; \
- a &= 0xffffUL; \
- a += (tmp << 4) - tmp; \
- } while (0)
-# define MOD28(a) \
- do { \
- CHOP(a); \
- if (a >= BASE) a -= BASE; \
- } while (0)
-# define MOD(a) \
- do { \
- CHOP(a); \
- MOD28(a); \
- } while (0)
-# define MOD63(a) \
- do { /* this assumes a is not negative */ \
- z_off64_t tmp = a >> 32; \
- a &= 0xffffffffL; \
- a += (tmp << 8) - (tmp << 5) + tmp; \
- tmp = a >> 16; \
- a &= 0xffffL; \
- a += (tmp << 4) - tmp; \
- tmp = a >> 16; \
- a &= 0xffffL; \
- a += (tmp << 4) - tmp; \
- if (a >= BASE) a -= BASE; \
- } while (0)
-#else
-# define MOD(a) a %= BASE
-# define MOD28(a) a %= BASE
-# define MOD63(a) a %= BASE
-#endif
-
-#include "cpu_features.h"
-#if defined(ADLER32_SIMD_SSSE3) || defined(ADLER32_SIMD_NEON)
-#include "adler32_simd.h"
-#endif
-
-/* ========================================================================= */
-uLong ZEXPORT adler32_z(adler, buf, len)
- uLong adler;
- const Bytef *buf;
- z_size_t len;
-{
- unsigned long sum2;
- unsigned n;
-
-#if defined(ADLER32_SIMD_SSSE3)
- if (x86_cpu_enable_ssse3 && buf && len >= 64)
- return adler32_simd_(adler, buf, len);
-#elif defined(ADLER32_SIMD_NEON)
- if (buf && len >= 64)
- return adler32_simd_(adler, buf, len);
-#endif
-
- /* split Adler-32 into component sums */
- sum2 = (adler >> 16) & 0xffff;
- adler &= 0xffff;
-
- /* in case user likes doing a byte at a time, keep it fast */
- if (len == 1) {
- adler += buf[0];
- if (adler >= BASE)
- adler -= BASE;
- sum2 += adler;
- if (sum2 >= BASE)
- sum2 -= BASE;
- return adler | (sum2 << 16);
- }
-
-#if defined(ADLER32_SIMD_SSSE3)
- /*
- * Use SSSE3 to compute the adler32. Since this routine can be
- * freely used, check CPU features here. zlib convention is to
- * call adler32(0, NULL, 0), before making calls to adler32().
- * So this is a good early (and infrequent) place to cache CPU
- * features for those later, more interesting adler32() calls.
- */
- if (buf == Z_NULL) {
- if (!len) /* Assume user is calling adler32(0, NULL, 0); */
- cpu_check_features();
- return 1L;
- }
-#else
- /* initial Adler-32 value (deferred check for len == 1 speed) */
- if (buf == Z_NULL)
- return 1L;
-#endif
-
- /* in case short lengths are provided, keep it somewhat fast */
- if (len < 16) {
- while (len--) {
- adler += *buf++;
- sum2 += adler;
- }
- if (adler >= BASE)
- adler -= BASE;
- MOD28(sum2); /* only added so many BASE's */
- return adler | (sum2 << 16);
- }
-
- /* do length NMAX blocks -- requires just one modulo operation */
- while (len >= NMAX) {
- len -= NMAX;
- n = NMAX / 16; /* NMAX is divisible by 16 */
- do {
- DO16(buf); /* 16 sums unrolled */
- buf += 16;
- } while (--n);
- MOD(adler);
- MOD(sum2);
- }
-
- /* do remaining bytes (less than NMAX, still just one modulo) */
- if (len) { /* avoid modulos if none remaining */
- while (len >= 16) {
- len -= 16;
- DO16(buf);
- buf += 16;
- }
- while (len--) {
- adler += *buf++;
- sum2 += adler;
- }
- MOD(adler);
- MOD(sum2);
- }
-
- /* return recombined sums */
- return adler | (sum2 << 16);
-}
-
-/* ========================================================================= */
-uLong ZEXPORT adler32(adler, buf, len)
- uLong adler;
- const Bytef *buf;
- uInt len;
-{
- return adler32_z(adler, buf, len);
-}
-
-/* ========================================================================= */
-local uLong adler32_combine_(adler1, adler2, len2)
- uLong adler1;
- uLong adler2;
- z_off64_t len2;
-{
- unsigned long sum1;
- unsigned long sum2;
- unsigned rem;
-
- /* for negative len, return invalid adler32 as a clue for debugging */
- if (len2 < 0)
- return 0xffffffffUL;
-
- /* the derivation of this formula is left as an exercise for the reader */
- MOD63(len2); /* assumes len2 >= 0 */
- rem = (unsigned)len2;
- sum1 = adler1 & 0xffff;
- sum2 = rem * sum1;
- MOD(sum2);
- sum1 += (adler2 & 0xffff) + BASE - 1;
- sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
- if (sum1 >= BASE) sum1 -= BASE;
- if (sum1 >= BASE) sum1 -= BASE;
- if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
- if (sum2 >= BASE) sum2 -= BASE;
- return sum1 | (sum2 << 16);
-}
-
-/* ========================================================================= */
-uLong ZEXPORT adler32_combine(adler1, adler2, len2)
- uLong adler1;
- uLong adler2;
- z_off_t len2;
-{
- return adler32_combine_(adler1, adler2, len2);
-}
-
-uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
- uLong adler1;
- uLong adler2;
- z_off64_t len2;
-{
- return adler32_combine_(adler1, adler2, len2);
-}
diff --git a/adler32_simd.c b/adler32_simd.c
deleted file mode 100644
index 1354915..0000000
--- a/adler32_simd.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/* adler32_simd.c
- *
- * Copyright 2017 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- *
- * Per http://en.wikipedia.org/wiki/Adler-32 the adler32 A value (aka s1) is
- * the sum of N input data bytes D1 ... DN,
- *
- * A = A0 + D1 + D2 + ... + DN
- *
- * where A0 is the initial value.
- *
- * SSE2 _mm_sad_epu8() can be used for byte sums (see http://bit.ly/2wpUOeD,
- * for example) and accumulating the byte sums can use SSE shuffle-adds (see
- * the "Integer" section of http://bit.ly/2erPT8t for details). Arm NEON has
- * similar instructions.
- *
- * The adler32 B value (aka s2) sums the A values from each step:
- *
- * B0 + (A0 + D1) + (A0 + D1 + D2) + ... + (A0 + D1 + D2 + ... + DN) or
- *
- * B0 + N.A0 + N.D1 + (N-1).D2 + (N-2).D3 + ... + (N-(N-1)).DN
- *
- * B0 being the initial value. For 32 bytes (ideal for garden-variety SIMD):
- *
- * B = B0 + 32.A0 + [D1 D2 D3 ... D32] x [32 31 30 ... 1].
- *
- * Adjacent blocks of 32 input bytes can be iterated with the expressions to
- * compute the adler32 s1 s2 of M >> 32 input bytes [1].
- *
- * As M grows, the s1 s2 sums grow. If left unchecked, they would eventually
- * overflow the precision of their integer representation (bad). However, s1
- * and s2 also need to be computed modulo the adler BASE value (reduced). If
- * at most NMAX bytes are processed before a reduce, s1 s2 _cannot_ overflow
- * a uint32_t type (the NMAX constraint) [2].
- *
- * [1] the iterative equations for s2 contain constant factors; these can be
- * hoisted from the n-blocks do loop of the SIMD code.
- *
- * [2] zlib adler32_z() uses this fact to implement NMAX-block-based updates
- * of the adler s1 s2 of uint32_t type (see adler32.c).
- */
-
-#include "adler32_simd.h"
-
-/* Definitions from adler32.c: largest prime smaller than 65536 */
-#define BASE 65521U
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-#define NMAX 5552
-
-#if defined(ADLER32_SIMD_SSSE3)
-
-#include <tmmintrin.h>
-
-uint32_t ZLIB_INTERNAL adler32_simd_( /* SSSE3 */
- uint32_t adler,
- const unsigned char *buf,
- z_size_t len)
-{
- /*
- * Split Adler-32 into component sums.
- */
- uint32_t s1 = adler & 0xffff;
- uint32_t s2 = adler >> 16;
-
- /*
- * Process the data in blocks.
- */
- const unsigned BLOCK_SIZE = 1 << 5;
-
- z_size_t blocks = len / BLOCK_SIZE;
- len -= blocks * BLOCK_SIZE;
-
- while (blocks)
- {
- unsigned n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */
- if (n > blocks)
- n = (unsigned) blocks;
- blocks -= n;
-
- const __m128i tap1 =
- _mm_setr_epi8(32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17);
- const __m128i tap2 =
- _mm_setr_epi8(16,15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
- const __m128i zero =
- _mm_setr_epi8( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- const __m128i ones =
- _mm_set_epi16( 1, 1, 1, 1, 1, 1, 1, 1);
-
- /*
- * Process n blocks of data. At most NMAX data bytes can be
- * processed before s2 must be reduced modulo BASE.
- */
- __m128i v_ps = _mm_set_epi32(0, 0, 0, s1 * n);
- __m128i v_s2 = _mm_set_epi32(0, 0, 0, s2);
- __m128i v_s1 = _mm_set_epi32(0, 0, 0, 0);
-
- do {
- /*
- * Load 32 input bytes.
- */
- const __m128i bytes1 = _mm_loadu_si128((__m128i*)(buf));
- const __m128i bytes2 = _mm_loadu_si128((__m128i*)(buf + 16));
-
- /*
- * Add previous block byte sum to v_ps.
- */
- v_ps = _mm_add_epi32(v_ps, v_s1);
-
- /*
- * Horizontally add the bytes for s1, multiply-adds the
- * bytes by [ 32, 31, 30, ... ] for s2.
- */
- v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes1, zero));
- const __m128i mad1 = _mm_maddubs_epi16(bytes1, tap1);
- v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(mad1, ones));
-
- v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes2, zero));
- const __m128i mad2 = _mm_maddubs_epi16(bytes2, tap2);
- v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(mad2, ones));
-
- buf += BLOCK_SIZE;
-
- } while (--n);
-
- v_s2 = _mm_add_epi32(v_s2, _mm_slli_epi32(v_ps, 5));
-
- /*
- * Sum epi32 ints v_s1(s2) and accumulate in s1(s2).
- */
-
-#define S23O1 _MM_SHUFFLE(2,3,0,1) /* A B C D -> B A D C */
-#define S1O32 _MM_SHUFFLE(1,0,3,2) /* A B C D -> C D A B */
-
- v_s1 = _mm_add_epi32(v_s1, _mm_shuffle_epi32(v_s1, S23O1));
- v_s1 = _mm_add_epi32(v_s1, _mm_shuffle_epi32(v_s1, S1O32));
-
- s1 += _mm_cvtsi128_si32(v_s1);
-
- v_s2 = _mm_add_epi32(v_s2, _mm_shuffle_epi32(v_s2, S23O1));
- v_s2 = _mm_add_epi32(v_s2, _mm_shuffle_epi32(v_s2, S1O32));
-
- s2 = _mm_cvtsi128_si32(v_s2);
-
-#undef S23O1
-#undef S1O32
-
- /*
- * Reduce.
- */
- s1 %= BASE;
- s2 %= BASE;
- }
-
- /*
- * Handle leftover data.
- */
- if (len) {
- if (len >= 16) {
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- len -= 16;
- }
-
- while (len--) {
- s2 += (s1 += *buf++);
- }
-
- if (s1 >= BASE)
- s1 -= BASE;
- s2 %= BASE;
- }
-
- /*
- * Return the recombined sums.
- */
- return s1 | (s2 << 16);
-}
-
-#elif defined(ADLER32_SIMD_NEON)
-
-#include <arm_neon.h>
-
-uint32_t ZLIB_INTERNAL adler32_simd_( /* NEON */
- uint32_t adler,
- const unsigned char *buf,
- z_size_t len)
-{
- /*
- * Split Adler-32 into component sums.
- */
- uint32_t s1 = adler & 0xffff;
- uint32_t s2 = adler >> 16;
-
- /*
- * Serially compute s1 & s2, until the data is 16-byte aligned.
- */
- if ((uintptr_t)buf & 15) {
- while ((uintptr_t)buf & 15) {
- s2 += (s1 += *buf++);
- --len;
- }
-
- if (s1 >= BASE)
- s1 -= BASE;
- s2 %= BASE;
- }
-
- /*
- * Process the data in blocks.
- */
- const unsigned BLOCK_SIZE = 1 << 5;
-
- z_size_t blocks = len / BLOCK_SIZE;
- len -= blocks * BLOCK_SIZE;
-
- while (blocks)
- {
- unsigned n = NMAX / BLOCK_SIZE; /* The NMAX constraint. */
- if (n > blocks)
- n = (unsigned) blocks;
- blocks -= n;
-
- /*
- * Process n blocks of data. At most NMAX data bytes can be
- * processed before s2 must be reduced modulo BASE.
- */
- uint32x4_t v_s2 = (uint32x4_t) { 0, 0, 0, s1 * n };
- uint32x4_t v_s1 = (uint32x4_t) { 0, 0, 0, 0 };
-
- uint16x8_t v_column_sum_1 = vdupq_n_u16(0);
- uint16x8_t v_column_sum_2 = vdupq_n_u16(0);
- uint16x8_t v_column_sum_3 = vdupq_n_u16(0);
- uint16x8_t v_column_sum_4 = vdupq_n_u16(0);
-
- do {
- /*
- * Load 32 input bytes.
- */
- const uint8x16_t bytes1 = vld1q_u8((uint8_t*)(buf));
- const uint8x16_t bytes2 = vld1q_u8((uint8_t*)(buf + 16));
-
- /*
- * Add previous block byte sum to v_s2.
- */
- v_s2 = vaddq_u32(v_s2, v_s1);
-
- /*
- * Horizontally add the bytes for s1.
- */
- v_s1 = vpadalq_u16(v_s1, vpadalq_u8(vpaddlq_u8(bytes1), bytes2));
-
- /*
- * Vertically add the bytes for s2.
- */
- v_column_sum_1 = vaddw_u8(v_column_sum_1, vget_low_u8 (bytes1));
- v_column_sum_2 = vaddw_u8(v_column_sum_2, vget_high_u8(bytes1));
- v_column_sum_3 = vaddw_u8(v_column_sum_3, vget_low_u8 (bytes2));
- v_column_sum_4 = vaddw_u8(v_column_sum_4, vget_high_u8(bytes2));
-
- buf += BLOCK_SIZE;
-
- } while (--n);
-
- v_s2 = vshlq_n_u32(v_s2, 5);
-
- /*
- * Multiply-add bytes by [ 32, 31, 30, ... ] for s2.
- */
- v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_1),
- (uint16x4_t) { 32, 31, 30, 29 });
- v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1),
- (uint16x4_t) { 28, 27, 26, 25 });
- v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_2),
- (uint16x4_t) { 24, 23, 22, 21 });
- v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_2),
- (uint16x4_t) { 20, 19, 18, 17 });
- v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_3),
- (uint16x4_t) { 16, 15, 14, 13 });
- v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_3),
- (uint16x4_t) { 12, 11, 10, 9 });
- v_s2 = vmlal_u16(v_s2, vget_low_u16 (v_column_sum_4),
- (uint16x4_t) { 8, 7, 6, 5 });
- v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_4),
- (uint16x4_t) { 4, 3, 2, 1 });
-
- /*
- * Sum epi32 ints v_s1(s2) and accumulate in s1(s2).
- */
- uint32x2_t sum1 = vpadd_u32(vget_low_u32(v_s1), vget_high_u32(v_s1));
- uint32x2_t sum2 = vpadd_u32(vget_low_u32(v_s2), vget_high_u32(v_s2));
- uint32x2_t s1s2 = vpadd_u32(sum1, sum2);
-
- s1 += vget_lane_u32(s1s2, 0);
- s2 += vget_lane_u32(s1s2, 1);
-
- /*
- * Reduce.
- */
- s1 %= BASE;
- s2 %= BASE;
- }
-
- /*
- * Handle leftover data.
- */
- if (len) {
- if (len >= 16) {
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
- s2 += (s1 += *buf++);
-
- len -= 16;
- }
-
- while (len--) {
- s2 += (s1 += *buf++);
- }
-
- if (s1 >= BASE)
- s1 -= BASE;
- s2 %= BASE;
- }
-
- /*
- * Return the recombined sums.
- */
- return s1 | (s2 << 16);
-}
-
-#endif /* ADLER32_SIMD_SSSE3 */
diff --git a/adler32_simd.h b/adler32_simd.h
deleted file mode 100644
index 52bb14d..0000000
--- a/adler32_simd.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* adler32_simd.h
- *
- * Copyright 2017 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#include <stdint.h>
-
-#include "zconf.h"
-#include "zutil.h"
-
-uint32_t ZLIB_INTERNAL adler32_simd_(
- uint32_t adler,
- const unsigned char *buf,
- z_size_t len);
diff --git a/chromeconf.h b/chromeconf.h
deleted file mode 100644
index 5ecf29e..0000000
--- a/chromeconf.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/* Copyright 2017 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file. */
-
-#ifndef THIRD_PARTY_ZLIB_CHROMECONF_H_
-#define THIRD_PARTY_ZLIB_CHROMECONF_H_
-
-#if defined(COMPONENT_BUILD)
-#if defined(WIN32)
-#if defined(ZLIB_IMPLEMENTATION)
-#define ZEXTERN __declspec(dllexport)
-#else
-#define ZEXTERN __declspec(dllimport)
-#endif
-#elif defined(ZLIB_IMPLEMENTATION)
-#define ZEXTERN __attribute__((visibility("default")))
-#endif
-#endif
-
-/* Rename all zlib names with a Cr_z_ prefix. This is based on the Z_PREFIX
- * option from zconf.h, but with a custom prefix. Where zconf.h would rename
- * both a macro and its underscore-suffixed internal implementation (such as
- * deflateInit2 and deflateInit2_), only the implementation is renamed here.
- * The Byte type is also omitted.
- *
- * To generate this list, run
- * sed -rn -e 's/^# *define +([^ ]+) +(z_[^ ]+)$/#define \1 Cr_\2/p' zconf.h
- * (use -E instead of -r on macOS).
- *
- * gzread is also addressed by modifications in gzread.c and zlib.h. */
-
-#define Z_CR_PREFIX_SET
-
-#define _dist_code Cr_z__dist_code
-#define _length_code Cr_z__length_code
-#define _tr_align Cr_z__tr_align
-#define _tr_flush_bits Cr_z__tr_flush_bits
-#define _tr_flush_block Cr_z__tr_flush_block
-#define _tr_init Cr_z__tr_init
-#define _tr_stored_block Cr_z__tr_stored_block
-#define _tr_tally Cr_z__tr_tally
-#define adler32 Cr_z_adler32
-#define adler32_combine Cr_z_adler32_combine
-#define adler32_combine64 Cr_z_adler32_combine64
-#define adler32_z Cr_z_adler32_z
-#define compress Cr_z_compress
-#define compress2 Cr_z_compress2
-#define compressBound Cr_z_compressBound
-#define crc32 Cr_z_crc32
-#define crc32_combine Cr_z_crc32_combine
-#define crc32_combine64 Cr_z_crc32_combine64
-#define crc32_z Cr_z_crc32_z
-#define deflate Cr_z_deflate
-#define deflateBound Cr_z_deflateBound
-#define deflateCopy Cr_z_deflateCopy
-#define deflateEnd Cr_z_deflateEnd
-#define deflateGetDictionary Cr_z_deflateGetDictionary
-/* #undef deflateInit */
-/* #undef deflateInit2 */
-#define deflateInit2_ Cr_z_deflateInit2_
-#define deflateInit_ Cr_z_deflateInit_
-#define deflateParams Cr_z_deflateParams
-#define deflatePending Cr_z_deflatePending
-#define deflatePrime Cr_z_deflatePrime
-#define deflateReset Cr_z_deflateReset
-#define deflateResetKeep Cr_z_deflateResetKeep
-#define deflateSetDictionary Cr_z_deflateSetDictionary
-#define deflateSetHeader Cr_z_deflateSetHeader
-#define deflateTune Cr_z_deflateTune
-#define deflate_copyright Cr_z_deflate_copyright
-#define get_crc_table Cr_z_get_crc_table
-#define gz_error Cr_z_gz_error
-#define gz_intmax Cr_z_gz_intmax
-#define gz_strwinerror Cr_z_gz_strwinerror
-#define gzbuffer Cr_z_gzbuffer
-#define gzclearerr Cr_z_gzclearerr
-#define gzclose Cr_z_gzclose
-#define gzclose_r Cr_z_gzclose_r
-#define gzclose_w Cr_z_gzclose_w
-#define gzdirect Cr_z_gzdirect
-#define gzdopen Cr_z_gzdopen
-#define gzeof Cr_z_gzeof
-#define gzerror Cr_z_gzerror
-#define gzflush Cr_z_gzflush
-#define gzfread Cr_z_gzfread
-#define gzfwrite Cr_z_gzfwrite
-#define gzgetc Cr_z_gzgetc
-#define gzgetc_ Cr_z_gzgetc_
-#define gzgets Cr_z_gzgets
-#define gzoffset Cr_z_gzoffset
-#define gzoffset64 Cr_z_gzoffset64
-#define gzopen Cr_z_gzopen
-#define gzopen64 Cr_z_gzopen64
-#define gzopen_w Cr_z_gzopen_w
-#define gzprintf Cr_z_gzprintf
-#define gzputc Cr_z_gzputc
-#define gzputs Cr_z_gzputs
-#define gzread Cr_z_gzread
-#define gzrewind Cr_z_gzrewind
-#define gzseek Cr_z_gzseek
-#define gzseek64 Cr_z_gzseek64
-#define gzsetparams Cr_z_gzsetparams
-#define gztell Cr_z_gztell
-#define gztell64 Cr_z_gztell64
-#define gzungetc Cr_z_gzungetc
-#define gzvprintf Cr_z_gzvprintf
-#define gzwrite Cr_z_gzwrite
-#define inflate Cr_z_inflate
-#define inflateBack Cr_z_inflateBack
-#define inflateBackEnd Cr_z_inflateBackEnd
-/* #undef inflateBackInit */
-#define inflateBackInit_ Cr_z_inflateBackInit_
-#define inflateCodesUsed Cr_z_inflateCodesUsed
-#define inflateCopy Cr_z_inflateCopy
-#define inflateEnd Cr_z_inflateEnd
-#define inflateGetDictionary Cr_z_inflateGetDictionary
-#define inflateGetHeader Cr_z_inflateGetHeader
-/* #undef inflateInit */
-/* #undef inflateInit2 */
-#define inflateInit2_ Cr_z_inflateInit2_
-#define inflateInit_ Cr_z_inflateInit_
-#define inflateMark Cr_z_inflateMark
-#define inflatePrime Cr_z_inflatePrime
-#define inflateReset Cr_z_inflateReset
-#define inflateReset2 Cr_z_inflateReset2
-#define inflateResetKeep Cr_z_inflateResetKeep
-#define inflateSetDictionary Cr_z_inflateSetDictionary
-#define inflateSync Cr_z_inflateSync
-#define inflateSyncPoint Cr_z_inflateSyncPoint
-#define inflateUndermine Cr_z_inflateUndermine
-#define inflateValidate Cr_z_inflateValidate
-#define inflate_copyright Cr_z_inflate_copyright
-#define inflate_fast Cr_z_inflate_fast
-#define inflate_table Cr_z_inflate_table
-#define uncompress Cr_z_uncompress
-#define uncompress2 Cr_z_uncompress2
-#define zError Cr_z_zError
-#define zcalloc Cr_z_zcalloc
-#define zcfree Cr_z_zcfree
-#define zlibCompileFlags Cr_z_zlibCompileFlags
-#define zlibVersion Cr_z_zlibVersion
-/* #undef Byte */
-#define Bytef Cr_z_Bytef
-#define alloc_func Cr_z_alloc_func
-#define charf Cr_z_charf
-#define free_func Cr_z_free_func
-#define gzFile Cr_z_gzFile
-#define gz_header Cr_z_gz_header
-#define gz_headerp Cr_z_gz_headerp
-#define in_func Cr_z_in_func
-#define intf Cr_z_intf
-#define out_func Cr_z_out_func
-#define uInt Cr_z_uInt
-#define uIntf Cr_z_uIntf
-#define uLong Cr_z_uLong
-#define uLongf Cr_z_uLongf
-#define voidp Cr_z_voidp
-#define voidpc Cr_z_voidpc
-#define voidpf Cr_z_voidpf
-#define gz_header_s Cr_z_gz_header_s
-/* #undef internal_state */
-/* #undef z_off64_t */
-
-/* An exported symbol that isn't handled by Z_PREFIX in zconf.h */
-#define z_errmsg Cr_z_z_errmsg
-
-/* Symbols added in simd.patch */
-#define copy_with_crc Cr_z_copy_with_crc
-#define crc_finalize Cr_z_crc_finalize
-#define crc_fold_512to32 Cr_z_crc_fold_512to32
-#define crc_fold_copy Cr_z_crc_fold_copy
-#define crc_fold_init Cr_z_crc_fold_init
-#define crc_reset Cr_z_crc_reset
-#define fill_window_sse Cr_z_fill_window_sse
-#define deflate_read_buf Cr_z_deflate_read_buf
-#define x86_check_features Cr_z_x86_check_features
-#define x86_cpu_enable_simd Cr_z_x86_cpu_enable_simd
-
-/* Symbols added by adler_simd.c */
-#define adler32_simd_ Cr_z_adler32_simd_
-#define x86_cpu_enable_ssse3 Cr_z_x86_cpu_enable_ssse3
-
-/* Symbols added by contrib/optimizations/inffast_chunk */
-#define inflate_fast_chunk_ Cr_z_inflate_fast_chunk_
-
-/* Symbols added by crc32_simd.c */
-#define crc32_sse42_simd_ Cr_z_crc32_sse42_simd_
-
-/* Symbols added by armv8_crc32 */
-#define arm_cpu_enable_crc32 Cr_z_arm_cpu_enable_crc32
-#define arm_cpu_enable_pmull Cr_z_arm_cpu_enable_pmull
-#define arm_check_features Cr_z_arm_check_features
-#define armv8_crc32_little Cr_z_armv8_crc32_little
-
-/* Symbols added by cpu_features.c */
-#define cpu_check_features Cr_z_cpu_check_features
-#define x86_cpu_enable_sse2 Cr_z_x86_cpu_enable_sse2
-
-#endif /* THIRD_PARTY_ZLIB_CHROMECONF_H_ */
diff --git a/compress.c b/compress.c
deleted file mode 100644
index 6e85173..0000000
--- a/compress.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* compress.c -- compress a memory buffer
- * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* @(#) $Id$ */
-
-#define ZLIB_INTERNAL
-#include "zlib.h"
-
-/* ===========================================================================
- Compresses the source buffer into the destination buffer. The level
- parameter has the same meaning as in deflateInit. sourceLen is the byte
- length of the source buffer. Upon entry, destLen is the total size of the
- destination buffer, which must be at least 0.1% larger than sourceLen plus
- 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
-
- compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
- memory, Z_BUF_ERROR if there was not enough room in the output buffer,
- Z_STREAM_ERROR if the level parameter is invalid.
-*/
-int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
- Bytef *dest;
- uLongf *destLen;
- const Bytef *source;
- uLong sourceLen;
- int level;
-{
- z_stream stream;
- int err;
- const uInt max = (uInt)-1;
- uLong left;
-
- left = *destLen;
- *destLen = 0;
-
- stream.zalloc = (alloc_func)0;
- stream.zfree = (free_func)0;
- stream.opaque = (voidpf)0;
-
- err = deflateInit(&stream, level);
- if (err != Z_OK) return err;
-
- stream.next_out = dest;
- stream.avail_out = 0;
- stream.next_in = (z_const Bytef *)source;
- stream.avail_in = 0;
-
- do {
- if (stream.avail_out == 0) {
- stream.avail_out = left > (uLong)max ? max : (uInt)left;
- left -= stream.avail_out;
- }
- if (stream.avail_in == 0) {
- stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
- sourceLen -= stream.avail_in;
- }
- err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
- } while (err == Z_OK);
-
- *destLen = stream.total_out;
- deflateEnd(&stream);
- return err == Z_STREAM_END ? Z_OK : err;
-}
-
-/* ===========================================================================
- */
-int ZEXPORT compress (dest, destLen, source, sourceLen)
- Bytef *dest;
- uLongf *destLen;
- const Bytef *source;
- uLong sourceLen;
-{
- return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
-}
-
-/* ===========================================================================
- If the default memLevel or windowBits for deflateInit() is changed, then
- this function needs to be updated.
- */
-uLong ZEXPORT compressBound (sourceLen)
- uLong sourceLen;
-{
- sourceLen = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
- (sourceLen >> 25) + 13;
- /* FIXME(cavalcantii): usage of CRC32 Castagnoli as a hash function
- * for the hash table of symbols used for compression has a side effect
- * where for compression level [4, 5] it will increase the output buffer size
- * by 0.1% (i.e. less than 1%) for a high entropy input (i.e. random data).
- * To avoid a scenario where client code would fail, for safety we increase
- * the expected output size by 0.8% (i.e. 8x more than the worst scenario).
- * See: http://crbug.com/990489
- */
- sourceLen += sourceLen >> 7; // Equivalent to 1.0078125
- return sourceLen;
-}
diff --git a/contrib/bench/zlib_bench.cc b/contrib/bench/zlib_bench.cc
deleted file mode 100644
index bc2f741..0000000
--- a/contrib/bench/zlib_bench.cc
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Copyright 2018 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- *
- * A benchmark test harness for measuring decoding performance of gzip or zlib
- * (deflate) encoded compressed data. Given a file containing any data, encode
- * (compress) it into gzip or zlib format and then decode (uncompress). Output
- * the median and maximum encoding and decoding rates in MB/s.
- *
- * Raw deflate (no gzip or zlib stream wrapper) mode is also supported. Select
- * it with the [raw] argument. Use the [gzip] [zlib] arguments to select those
- * stream wrappers.
- *
- * Note this code can be compiled outside of the Chromium build system against
- * the system zlib (-lz) with g++ or clang++ as follows:
- *
- * g++|clang++ -O3 -Wall -std=c++11 -lstdc++ -lz zlib_bench.cc
- */
-
-#include <algorithm>
-#include <chrono>
-#include <fstream>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include <memory.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "zlib.h"
-
-void error_exit(const char* error, int code) {
- fprintf(stderr, "%s (%d)\n", error, code);
- exit(code);
-}
-
-inline char* string_data(std::string* s) {
- return s->empty() ? nullptr : &*s->begin();
-}
-
-struct Data {
- Data(size_t s) { data.reset(new (std::nothrow) char[size = s]); }
- std::unique_ptr<char[]> data;
- size_t size;
-};
-
-Data read_file_data_or_exit(const char* name) {
- std::ifstream file(name, std::ios::in | std::ios::binary);
- if (!file) {
- perror(name);
- exit(1);
- }
-
- file.seekg(0, std::ios::end);
- Data data(file.tellg());
- file.seekg(0, std::ios::beg);
-
- if (file && data.data)
- file.read(data.data.get(), data.size);
-
- if (!file || !data.data || !data.size) {
- perror((std::string("failed: reading ") + name).c_str());
- exit(1);
- }
-
- return data;
-}
-
-size_t zlib_estimate_compressed_size(size_t input_size) {
- return compressBound(input_size);
-}
-
-enum zlib_wrapper {
- kWrapperNONE,
- kWrapperZLIB,
- kWrapperGZIP,
- kWrapperZRAW,
-};
-
-inline int zlib_stream_wrapper_type(zlib_wrapper type) {
- if (type == kWrapperZLIB) // zlib DEFLATE stream wrapper
- return MAX_WBITS;
- if (type == kWrapperGZIP) // gzip DEFLATE stream wrapper
- return MAX_WBITS + 16;
- if (type == kWrapperZRAW) // no wrapper, use raw DEFLATE
- return -MAX_WBITS;
- error_exit("bad wrapper type", int(type));
- return 0;
-}
-
-const char* zlib_wrapper_name(zlib_wrapper type) {
- if (type == kWrapperZLIB)
- return "ZLIB";
- if (type == kWrapperGZIP)
- return "GZIP";
- if (type == kWrapperZRAW)
- return "RAW";
- error_exit("bad wrapper type", int(type));
- return nullptr;
-}
-
-static int zlib_strategy = Z_DEFAULT_STRATEGY;
-
-const char* zlib_level_strategy_name(int compression_level) {
- if (compression_level == 0)
- return ""; // strategy is meaningless at level 0
- if (zlib_strategy == Z_HUFFMAN_ONLY)
- return "huffman ";
- if (zlib_strategy == Z_RLE)
- return "rle ";
- if (zlib_strategy == Z_DEFAULT_STRATEGY)
- return "";
- error_exit("bad strategy", zlib_strategy);
- return nullptr;
-}
-
-static int zlib_compression_level = Z_DEFAULT_COMPRESSION;
-
-void zlib_compress(
- const zlib_wrapper type,
- const char* input,
- const size_t input_size,
- std::string* output,
- bool resize_output = false)
-{
- if (resize_output)
- output->resize(zlib_estimate_compressed_size(input_size));
- size_t output_size = output->size();
-
- z_stream stream;
- memset(&stream, 0, sizeof(stream));
-
- int result = deflateInit2(&stream, zlib_compression_level, Z_DEFLATED,
- zlib_stream_wrapper_type(type), MAX_MEM_LEVEL, zlib_strategy);
- if (result != Z_OK)
- error_exit("deflateInit2 failed", result);
-
- stream.next_out = (Bytef*)string_data(output);
- stream.avail_out = (uInt)output_size;
- stream.next_in = (z_const Bytef*)input;
- stream.avail_in = (uInt)input_size;
-
- result = deflate(&stream, Z_FINISH);
- if (result == Z_STREAM_END)
- output_size = stream.total_out;
- result |= deflateEnd(&stream);
- if (result != Z_STREAM_END)
- error_exit("compress failed", result);
-
- if (resize_output)
- output->resize(output_size);
-}
-
-void zlib_uncompress(
- const zlib_wrapper type,
- const std::string& input,
- const size_t output_size,
- std::string* output)
-{
- z_stream stream;
- memset(&stream, 0, sizeof(stream));
-
- int result = inflateInit2(&stream, zlib_stream_wrapper_type(type));
- if (result != Z_OK)
- error_exit("inflateInit2 failed", result);
-
- stream.next_out = (Bytef*)string_data(output);
- stream.avail_out = (uInt)output->size();
- stream.next_in = (z_const Bytef*)input.data();
- stream.avail_in = (uInt)input.size();
-
- result = inflate(&stream, Z_FINISH);
- if (stream.total_out != output_size)
- result = Z_DATA_ERROR;
- result |= inflateEnd(&stream);
- if (result == Z_STREAM_END)
- return;
-
- std::string error("uncompress failed: ");
- if (stream.msg)
- error.append(stream.msg);
- error_exit(error.c_str(), result);
-}
-
-void verify_equal(const char* input, size_t size, std::string* output) {
- const char* data = string_data(output);
- if (output->size() == size && !memcmp(data, input, size))
- return;
- fprintf(stderr, "uncompressed data does not match the input data\n");
- exit(3);
-}
-
-void zlib_file(const char* name, const zlib_wrapper type) {
- /*
- * Read the file data.
- */
- const auto file = read_file_data_or_exit(name);
- const int length = static_cast<int>(file.size);
- const char* data = file.data.get();
-
- /*
- * Report compression strategy and file name.
- */
- const char* strategy = zlib_level_strategy_name(zlib_compression_level);
- printf("%s%-40s :\n", strategy, name);
-
- /*
- * Chop the data into blocks.
- */
- const int block_size = 1 << 20;
- const int blocks = (length + block_size - 1) / block_size;
-
- std::vector<const char*> input(blocks);
- std::vector<size_t> input_length(blocks);
- std::vector<std::string> compressed(blocks);
- std::vector<std::string> output(blocks);
-
- for (int b = 0; b < blocks; ++b) {
- int input_start = b * block_size;
- int input_limit = std::min<int>((b + 1) * block_size, length);
- input[b] = data + input_start;
- input_length[b] = input_limit - input_start;
- }
-
- /*
- * Run the zlib compress/uncompress loop a few times with |repeats| to
- * process about 10MB of data if the length is small relative to 10MB.
- * If length is large relative to 10MB, process the data once.
- */
- const int mega_byte = 1024 * 1024;
- const int repeats = (10 * mega_byte + length) / (length + 1);
- const int runs = 5;
- double ctime[runs];
- double utime[runs];
-
- for (int run = 0; run < runs; ++run) {
- const auto now = [] { return std::chrono::steady_clock::now(); };
-
- // Pre-grow the output buffer so we don't measure string resize time.
- for (int b = 0; b < blocks; ++b)
- compressed[b].resize(zlib_estimate_compressed_size(block_size));
-
- auto start = now();
- for (int b = 0; b < blocks; ++b)
- for (int r = 0; r < repeats; ++r)
- zlib_compress(type, input[b], input_length[b], &compressed[b]);
- ctime[run] = std::chrono::duration<double>(now() - start).count();
-
- // Compress again, resizing compressed, so we don't leave junk at the
- // end of the compressed string that could confuse zlib_uncompress().
- for (int b = 0; b < blocks; ++b)
- zlib_compress(type, input[b], input_length[b], &compressed[b], true);
-
- for (int b = 0; b < blocks; ++b)
- output[b].resize(input_length[b]);
-
- start = now();
- for (int r = 0; r < repeats; ++r)
- for (int b = 0; b < blocks; ++b)
- zlib_uncompress(type, compressed[b], input_length[b], &output[b]);
- utime[run] = std::chrono::duration<double>(now() - start).count();
-
- for (int b = 0; b < blocks; ++b)
- verify_equal(input[b], input_length[b], &output[b]);
- }
-
- /*
- * Output the median/maximum compress/uncompress rates in MB/s.
- */
- size_t output_length = 0;
- for (size_t i = 0; i < compressed.size(); ++i)
- output_length += compressed[i].size();
-
- std::sort(ctime, ctime + runs);
- std::sort(utime, utime + runs);
-
- double deflate_rate_med = length * repeats / mega_byte / ctime[runs / 2];
- double inflate_rate_med = length * repeats / mega_byte / utime[runs / 2];
- double deflate_rate_max = length * repeats / mega_byte / ctime[0];
- double inflate_rate_max = length * repeats / mega_byte / utime[0];
-
- // type, block size, compression ratio, etc
- printf("%s: [b %dM] bytes %6d -> %6u %4.1f%%",
- zlib_wrapper_name(type), block_size / (1 << 20), length,
- static_cast<unsigned>(output_length), output_length * 100.0 / length);
-
- // compress / uncompress median (max) rates
- printf(" comp %5.1f (%5.1f) MB/s uncomp %5.1f (%5.1f) MB/s\n",
- deflate_rate_med, deflate_rate_max, inflate_rate_med, inflate_rate_max);
-}
-
-static int argn = 1;
-
-char* get_option(int argc, char* argv[], const char* option) {
- if (argn < argc)
- return !strcmp(argv[argn], option) ? argv[argn++] : nullptr;
- return nullptr;
-}
-
-bool get_compression(int argc, char* argv[], int* value) {
- if (argn < argc)
- *value = isdigit(argv[argn][0]) ? atoi(argv[argn++]) : -1;
- return *value >= 0 && *value <= 9;
-}
-
-void usage_exit(const char* program) {
- printf(
- "usage: %s gzip|zlib|raw [--compression 0:9] [--huffman|--rle] "
- "files...\n",
- program);
- exit(1);
-}
-
-int main(int argc, char* argv[]) {
- zlib_wrapper type;
- if (get_option(argc, argv, "zlib"))
- type = kWrapperZLIB;
- else if (get_option(argc, argv, "gzip"))
- type = kWrapperGZIP;
- else if (get_option(argc, argv, "raw"))
- type = kWrapperZRAW;
- else
- usage_exit(argv[0]);
-
- while (argn < argc && argv[argn][0] == '-') {
- if (get_option(argc, argv, "--compression")) {
- if (!get_compression(argc, argv, &zlib_compression_level))
- usage_exit(argv[0]);
- } else if (get_option(argc, argv, "--huffman")) {
- zlib_strategy = Z_HUFFMAN_ONLY;
- } else if (get_option(argc, argv, "--rle")) {
- zlib_strategy = Z_RLE;
- } else {
- usage_exit(argv[0]);
- }
- }
-
- if (argn >= argc)
- usage_exit(argv[0]);
- while (argn < argc)
- zlib_file(argv[argn++], type);
-
- return 0;
-}
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip
deleted file mode 100644
index e62af14..0000000
--- a/contrib/minizip/ChangeLogUnzip
+++ /dev/null
@@ -1,67 +0,0 @@
-Change in 1.01e (12 feb 05)
-- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
-- Fix possible memory leak in unzip.c (Zoran Stevanovic)
-
-Change in 1.01b (20 may 04)
-- Integrate patch from Debian package (submited by Mark Brown)
-- Add tools mztools from Xavier Roche
-
-Change in 1.01 (8 may 04)
-- fix buffer overrun risk in unzip.c (Xavier Roche)
-- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
-
-Change in 1.00: (10 sept 03)
-- rename to 1.00
-- cosmetic code change
-
-Change in 0.22: (19 May 03)
-- crypting support (unless you define NOCRYPT)
-- append file in existing zipfile
-
-Change in 0.21: (10 Mar 03)
-- bug fixes
-
-Change in 0.17: (27 Jan 02)
-- bug fixes
-
-Change in 0.16: (19 Jan 02)
-- Support of ioapi for virtualize zip file access
-
-Change in 0.15: (19 Mar 98)
-- fix memory leak in minizip.c
-
-Change in 0.14: (10 Mar 98)
-- fix bugs in minizip.c sample for zipping big file
-- fix problem in month in date handling
-- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
- comment handling
-
-Change in 0.13: (6 Mar 98)
-- fix bugs in zip.c
-- add real minizip sample
-
-Change in 0.12: (4 Mar 98)
-- add zip.c and zip.h for creates .zip file
-- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
-- fix miniunz.c for file without specific record for directory
-
-Change in 0.11: (3 Mar 98)
-- fix bug in unzGetCurrentFileInfo for get extra field and comment
-- enhance miniunz sample, remove the bad unztst.c sample
-
-Change in 0.10: (2 Mar 98)
-- fix bug in unzReadCurrentFile
-- rename unzip* to unz* function and structure
-- remove Windows-like hungary notation variable name
-- modify some structure in unzip.h
-- add somes comment in source
-- remove unzipGetcCurrentFile function
-- replace ZUNZEXPORT by ZEXPORT
-- add unzGetLocalExtrafield for get the local extrafield info
-- add a new sample, miniunz.c
-
-Change in 0.4: (25 Feb 98)
-- suppress the type unzipFileInZip.
- Only on file in the zipfile can be open at the same time
-- fix somes typo in code
-- added tm_unz structure in unzip_file_info (date/time in readable format)
diff --git a/contrib/minizip/Makefile b/contrib/minizip/Makefile
deleted file mode 100644
index 84eaad2..0000000
--- a/contrib/minizip/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-CC=cc
-CFLAGS=-O -I../..
-
-UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
-ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
-
-.c.o:
- $(CC) -c $(CFLAGS) $*.c
-
-all: miniunz minizip
-
-miniunz: $(UNZ_OBJS)
- $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
-
-minizip: $(ZIP_OBJS)
- $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
-
-test: miniunz minizip
- ./minizip test readme.txt
- ./miniunz -l test.zip
- mv readme.txt readme.old
- ./miniunz test.zip
-
-clean:
- /bin/rm -f *.o *~ minizip miniunz
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h
deleted file mode 100644
index 1e9e820..0000000
--- a/contrib/minizip/crypt.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/* crypt.h -- base code for crypt/uncrypt ZIPfile
-
-
- Version 1.01e, February 12th, 2005
-
- Copyright (C) 1998-2005 Gilles Vollant
-
- This code is a modified version of crypting code in Infozip distribution
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
-
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
-
- If you don't need crypting in your application, just define symbols
- NOCRYPT and NOUNCRYPT.
-
- This code support the "Traditional PKWARE Encryption".
-
- The new AES encryption added on Zip format by Winzip (see the page
- http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
- Encryption is not supported.
-*/
-
-#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
-
-/***********************************************************************
- * Return the next byte in the pseudo-random sequence
- */
-static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
-{
- unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
- * unpredictable manner on 16-bit systems; not a problem
- * with any known compiler so far, though */
-
- temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
- return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
-}
-
-/***********************************************************************
- * Update the encryption keys with the next byte of plain text
- */
-static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
-{
- (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
- (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
- (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
- {
- register int keyshift = (int)((*(pkeys+1)) >> 24);
- (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
- }
- return c;
-}
-
-
-/***********************************************************************
- * Initialize the encryption keys and the random header according to
- * the given password.
- */
-static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
-{
- *(pkeys+0) = 305419896L;
- *(pkeys+1) = 591751049L;
- *(pkeys+2) = 878082192L;
- while (*passwd != '\0') {
- update_keys(pkeys,pcrc_32_tab,(int)*passwd);
- passwd++;
- }
-}
-
-#define zdecode(pkeys,pcrc_32_tab,c) \
- (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
-
-#define zencode(pkeys,pcrc_32_tab,c,t) \
- (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
-
-#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-
-#define RAND_HEAD_LEN 12
- /* "last resort" source for second part of crypt seed pattern */
-# ifndef ZCR_SEED2
-# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
-# endif
-
-static int crypthead(const char* passwd, /* password string */
- unsigned char* buf, /* where to write header */
- int bufSize,
- unsigned long* pkeys,
- const z_crc_t* pcrc_32_tab,
- unsigned long crcForCrypting)
-{
- int n; /* index in random header */
- int t; /* temporary */
- int c; /* random byte */
- unsigned char header[RAND_HEAD_LEN-2]; /* random header */
- static unsigned calls = 0; /* ensure different random header each time */
-
- if (bufSize<RAND_HEAD_LEN)
- return 0;
-
- /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
- * output of rand() to get less predictability, since rand() is
- * often poorly implemented.
- */
- if (++calls == 1)
- {
- srand((unsigned)(time(NULL) ^ ZCR_SEED2));
- }
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- c = (rand() >> 7) & 0xff;
- header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
- }
- /* Encrypt random header (last two bytes is high word of crc) */
- init_keys(passwd, pkeys, pcrc_32_tab);
- for (n = 0; n < RAND_HEAD_LEN-2; n++)
- {
- buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
- }
- buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
- buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
- return n;
-}
-
-#endif
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
deleted file mode 100644
index 543910b..0000000
--- a/contrib/minizip/ioapi.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
- #define _CRT_SECURE_NO_WARNINGS
-#endif
-
-#if defined(__APPLE__) || defined(__Fuchsia__) || defined(IOAPI_NO_64)
-// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
-#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
-#define FTELLO_FUNC(stream) ftello(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
-#else
-#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
-#define FTELLO_FUNC(stream) ftello64(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
-#endif
-
-
-#include "ioapi.h"
-
-voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
-{
- if (pfilefunc->zfile_func64.zopen64_file != NULL)
- return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
- else
- {
- return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
- }
-}
-
-long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
-{
- if (pfilefunc->zfile_func64.zseek64_file != NULL)
- return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
- else
- {
- uLong offsetTruncated = (uLong)offset;
- if (offsetTruncated != offset)
- return -1;
- else
- return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
- }
-}
-
-ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
-{
- if (pfilefunc->zfile_func64.zseek64_file != NULL)
- return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
- else
- {
- uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
- if ((tell_uLong) == MAXU32)
- return (ZPOS64_T)-1;
- else
- return tell_uLong;
- }
-}
-
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
-{
- p_filefunc64_32->zfile_func64.zopen64_file = NULL;
- p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
- p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
- p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
- p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
- p_filefunc64_32->zfile_func64.ztell64_file = NULL;
- p_filefunc64_32->zfile_func64.zseek64_file = NULL;
- p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
- p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
- p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
- p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
- p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
-}
-
-
-
-static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
-static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
-static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
-static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
-static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
-
-static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
-{
- FILE* file = NULL;
- const char* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = "rb";
- else
- if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = "r+b";
- else
- if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = "wb";
-
- if ((filename!=NULL) && (mode_fopen != NULL))
- file = fopen(filename, mode_fopen);
- return file;
-}
-
-static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
-{
- FILE* file = NULL;
- const char* mode_fopen = NULL;
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- mode_fopen = "rb";
- else
- if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- mode_fopen = "r+b";
- else
- if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- mode_fopen = "wb";
-
- if ((filename!=NULL) && (mode_fopen != NULL))
- file = FOPEN_FUNC((const char*)filename, mode_fopen);
- return file;
-}
-
-
-static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
-{
- uLong ret;
- ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
-{
- uLong ret;
- ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
- return ret;
-}
-
-static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
-{
- long ret;
- ret = ftell((FILE *)stream);
- return ret;
-}
-
-
-static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
-{
- ZPOS64_T ret;
- ret = FTELLO_FUNC((FILE *)stream);
- return ret;
-}
-
-static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
-{
- int fseek_origin=0;
- long ret;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- fseek_origin = SEEK_CUR;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- fseek_origin = SEEK_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- fseek_origin = SEEK_SET;
- break;
- default: return -1;
- }
- ret = 0;
- if (fseek((FILE *)stream, offset, fseek_origin) != 0)
- ret = -1;
- return ret;
-}
-
-static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
-{
- int fseek_origin=0;
- long ret;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- fseek_origin = SEEK_CUR;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- fseek_origin = SEEK_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- fseek_origin = SEEK_SET;
- break;
- default: return -1;
- }
- ret = 0;
-
- if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
- ret = -1;
-
- return ret;
-}
-
-
-static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
-{
- int ret;
- ret = fclose((FILE *)stream);
- return ret;
-}
-
-static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
-{
- int ret;
- ret = ferror((FILE *)stream);
- return ret;
-}
-
-void fill_fopen_filefunc (pzlib_filefunc_def)
- zlib_filefunc_def* pzlib_filefunc_def;
-{
- pzlib_filefunc_def->zopen_file = fopen_file_func;
- pzlib_filefunc_def->zread_file = fread_file_func;
- pzlib_filefunc_def->zwrite_file = fwrite_file_func;
- pzlib_filefunc_def->ztell_file = ftell_file_func;
- pzlib_filefunc_def->zseek_file = fseek_file_func;
- pzlib_filefunc_def->zclose_file = fclose_file_func;
- pzlib_filefunc_def->zerror_file = ferror_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = fopen64_file_func;
- pzlib_filefunc_def->zread_file = fread_file_func;
- pzlib_filefunc_def->zwrite_file = fwrite_file_func;
- pzlib_filefunc_def->ztell64_file = ftell64_file_func;
- pzlib_filefunc_def->zseek64_file = fseek64_file_func;
- pzlib_filefunc_def->zclose_file = fclose_file_func;
- pzlib_filefunc_def->zerror_file = ferror_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h
deleted file mode 100644
index c1b7a54..0000000
--- a/contrib/minizip/ioapi.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/* ioapi.h -- IO base function header for compress/uncompress .zip
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- Changes
-
- Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
- Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
- More if/def section may be needed to support other platforms
- Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
- (but you should use iowin32.c for windows instead)
-
-*/
-
-#ifndef _ZLIBIOAPI64_H
-#define _ZLIBIOAPI64_H
-
-#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
-
- // Linux needs this to support file operation on files larger then 4+GB
- // But might need better if/def to select just the platforms that needs them.
-
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "third_party/zlib/zlib.h"
-
-#if defined(USE_FILE32API)
-#define fopen64 fopen
-#define ftello64 ftell
-#define fseeko64 fseek
-#else
-#ifdef __FreeBSD__
-#define fopen64 fopen
-#define ftello64 ftello
-#define fseeko64 fseeko
-#endif
-#ifdef _MSC_VER
- #define fopen64 fopen
- #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
- #define ftello64 _ftelli64
- #define fseeko64 _fseeki64
- #else // old MSC
- #define ftello64 ftell
- #define fseeko64 fseek
- #endif
-#endif
-#endif
-
-/*
-#ifndef ZPOS64_T
- #ifdef _WIN32
- #define ZPOS64_T fpos_t
- #else
- #include <stdint.h>
- #define ZPOS64_T uint64_t
- #endif
-#endif
-*/
-
-#ifdef HAVE_MINIZIP64_CONF_H
-#include "mz64conf.h"
-#endif
-
-/* a type choosen by DEFINE */
-#ifdef HAVE_64BIT_INT_CUSTOM
-typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
-#else
-#ifdef HAS_STDINT_H
-#include "stdint.h"
-typedef uint64_t ZPOS64_T;
-#else
-
-/* Maximum unsigned 32-bit value used as placeholder for zip64 */
-#define MAXU32 0xffffffff
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef unsigned __int64 ZPOS64_T;
-#else
-typedef unsigned long long int ZPOS64_T;
-#endif
-#endif
-#endif
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define ZLIB_FILEFUNC_SEEK_CUR (1)
-#define ZLIB_FILEFUNC_SEEK_END (2)
-#define ZLIB_FILEFUNC_SEEK_SET (0)
-
-#define ZLIB_FILEFUNC_MODE_READ (1)
-#define ZLIB_FILEFUNC_MODE_WRITE (2)
-#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
-
-#define ZLIB_FILEFUNC_MODE_EXISTING (4)
-#define ZLIB_FILEFUNC_MODE_CREATE (8)
-
-
-#ifndef ZCALLBACK
- #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
- #define ZCALLBACK CALLBACK
- #else
- #define ZCALLBACK
- #endif
-#endif
-
-
-
-
-typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
-typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
-typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
-
-typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
-typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
-
-
-/* here is the "old" 32 bits structure structure */
-typedef struct zlib_filefunc_def_s
-{
- open_file_func zopen_file;
- read_file_func zread_file;
- write_file_func zwrite_file;
- tell_file_func ztell_file;
- seek_file_func zseek_file;
- close_file_func zclose_file;
- testerror_file_func zerror_file;
- voidpf opaque;
-} zlib_filefunc_def;
-
-typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
-typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
-
-typedef struct zlib_filefunc64_def_s
-{
- open64_file_func zopen64_file;
- read_file_func zread_file;
- write_file_func zwrite_file;
- tell64_file_func ztell64_file;
- seek64_file_func zseek64_file;
- close_file_func zclose_file;
- testerror_file_func zerror_file;
- voidpf opaque;
-} zlib_filefunc64_def;
-
-void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-
-/* now internal definition, only for zip.c and unzip.h */
-typedef struct zlib_filefunc64_32_def_s
-{
- zlib_filefunc64_def zfile_func64;
- open_file_func zopen32_file;
- tell_file_func ztell32_file;
- seek_file_func zseek32_file;
-} zlib_filefunc64_32_def;
-
-
-#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
-#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
-//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
-//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
-#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
-#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
-
-voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
-long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
-ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
-
-void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
-
-#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
-#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
-#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
deleted file mode 100644
index c6bc314..0000000
--- a/contrib/minizip/iowin32.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/* iowin32.c -- IO base function header for compress/uncompress .zip
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#include <stdlib.h>
-
-#include "zlib.h"
-#include "ioapi.h"
-#include "iowin32.h"
-
-#ifndef INVALID_HANDLE_VALUE
-#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
-#endif
-
-#ifndef INVALID_SET_FILE_POINTER
-#define INVALID_SET_FILE_POINTER ((DWORD)-1)
-#endif
-
-
-#ifdef _WIN32_WINNT
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x601
-#endif
-
-#if !defined(IOWIN32_USING_WINRT_API)
-#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
-// Windows Store or Universal Windows Platform
-#define IOWIN32_USING_WINRT_API 1
-#endif
-#endif
-
-voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
-uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
-uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
-ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
-long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
-int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
-int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
-
-typedef struct
-{
- HANDLE hf;
- int error;
-} WIN32FILE_IOWIN;
-
-
-static void win32_translate_open_mode(int mode,
- DWORD* lpdwDesiredAccess,
- DWORD* lpdwCreationDisposition,
- DWORD* lpdwShareMode,
- DWORD* lpdwFlagsAndAttributes)
-{
- *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
-
- if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
- {
- *lpdwDesiredAccess = GENERIC_READ;
- *lpdwCreationDisposition = OPEN_EXISTING;
- *lpdwShareMode = FILE_SHARE_READ;
- }
- else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
- {
- *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
- *lpdwCreationDisposition = OPEN_EXISTING;
- }
- else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
- {
- *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
- *lpdwCreationDisposition = CREATE_ALWAYS;
- }
-}
-
-static voidpf win32_build_iowin(HANDLE hFile)
-{
- voidpf ret=NULL;
-
- if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
- {
- WIN32FILE_IOWIN w32fiow;
- w32fiow.hf = hFile;
- w32fiow.error = 0;
- ret = malloc(sizeof(WIN32FILE_IOWIN));
-
- if (ret==NULL)
- CloseHandle(hFile);
- else
- *((WIN32FILE_IOWIN*)ret) = w32fiow;
- }
- return ret;
-}
-
-voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
-#ifdef IOWIN32_USING_WINRT_API
-#ifdef UNICODE
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- {
- WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
- MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
- hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
- }
-#endif
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-#endif
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
-#ifdef IOWIN32_USING_WINRT_API
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- {
- WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
- MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
- hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
- }
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-#endif
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
-#ifdef IOWIN32_USING_WINRT_API
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL);
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-#endif
-
- return win32_build_iowin(hFile);
-}
-
-
-voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
-{
- const char* mode_fopen = NULL;
- DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
- HANDLE hFile = NULL;
-
- win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
-
-#ifdef IOWIN32_USING_WINRT_API
-#ifdef UNICODE
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- {
- WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
- MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
- hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
- }
-#endif
-#else
- if ((filename!=NULL) && (dwDesiredAccess != 0))
- hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
-#endif
-
- return win32_build_iowin(hFile);
-}
-
-
-uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
-{
- uLong ret=0;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-
- if (hFile != NULL)
- {
- if (!ReadFile(hFile, buf, size, &ret, NULL))
- {
- DWORD dwErr = GetLastError();
- if (dwErr == ERROR_HANDLE_EOF)
- dwErr = 0;
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- }
- }
-
- return ret;
-}
-
-
-uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
-{
- uLong ret=0;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
-
- if (hFile != NULL)
- {
- if (!WriteFile(hFile, buf, size, &ret, NULL))
- {
- DWORD dwErr = GetLastError();
- if (dwErr == ERROR_HANDLE_EOF)
- dwErr = 0;
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- }
- }
-
- return ret;
-}
-
-static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
-{
-#ifdef IOWIN32_USING_WINRT_API
- return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
-#else
- LONG lHigh = pos.HighPart;
- DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
- BOOL fOk = TRUE;
- if (dwNewPos == 0xFFFFFFFF)
- if (GetLastError() != NO_ERROR)
- fOk = FALSE;
- if ((newPos != NULL) && (fOk))
- {
- newPos->LowPart = dwNewPos;
- newPos->HighPart = lHigh;
- }
- return fOk;
-#endif
-}
-
-long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
-{
- long ret=-1;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- if (hFile != NULL)
- {
- LARGE_INTEGER pos;
- pos.QuadPart = 0;
-
- if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=(long)pos.LowPart;
- }
- return ret;
-}
-
-ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
-{
- ZPOS64_T ret= (ZPOS64_T)-1;
- HANDLE hFile = NULL;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream)->hf;
-
- if (hFile)
- {
- LARGE_INTEGER pos;
- pos.QuadPart = 0;
-
- if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = (ZPOS64_T)-1;
- }
- else
- ret=pos.QuadPart;
- }
- return ret;
-}
-
-
-long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
-{
- DWORD dwMoveMethod=0xFFFFFFFF;
- HANDLE hFile = NULL;
-
- long ret=-1;
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- dwMoveMethod = FILE_CURRENT;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- dwMoveMethod = FILE_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- dwMoveMethod = FILE_BEGIN;
- break;
- default: return -1;
- }
-
- if (hFile != NULL)
- {
- LARGE_INTEGER pos;
- pos.QuadPart = offset;
- if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=0;
- }
- return ret;
-}
-
-long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
-{
- DWORD dwMoveMethod=0xFFFFFFFF;
- HANDLE hFile = NULL;
- long ret=-1;
-
- if (stream!=NULL)
- hFile = ((WIN32FILE_IOWIN*)stream)->hf;
-
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- dwMoveMethod = FILE_CURRENT;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- dwMoveMethod = FILE_END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- dwMoveMethod = FILE_BEGIN;
- break;
- default: return -1;
- }
-
- if (hFile)
- {
- LARGE_INTEGER pos;
- pos.QuadPart = offset;
- if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
- {
- DWORD dwErr = GetLastError();
- ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
- ret = -1;
- }
- else
- ret=0;
- }
- return ret;
-}
-
-int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
-{
- int ret=-1;
-
- if (stream!=NULL)
- {
- HANDLE hFile;
- hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
- if (hFile != NULL)
- {
- CloseHandle(hFile);
- ret=0;
- }
- free(stream);
- }
- return ret;
-}
-
-int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
-{
- int ret=-1;
- if (stream!=NULL)
- {
- ret = ((WIN32FILE_IOWIN*)stream) -> error;
- }
- return ret;
-}
-
-void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen_file = win32_open_file_func;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell_file = win32_tell_file_func;
- pzlib_filefunc_def->zseek_file = win32_seek_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-
-void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
-
-
-void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
-{
- pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
- pzlib_filefunc_def->zread_file = win32_read_file_func;
- pzlib_filefunc_def->zwrite_file = win32_write_file_func;
- pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
- pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
- pzlib_filefunc_def->zclose_file = win32_close_file_func;
- pzlib_filefunc_def->zerror_file = win32_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
-}
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h
deleted file mode 100644
index 0ca0969..0000000
--- a/contrib/minizip/iowin32.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* iowin32.h -- IO base function header for compress/uncompress .zip
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-*/
-
-#include <windows.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
-void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
-void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c
deleted file mode 100644
index 3d65401..0000000
--- a/contrib/minizip/miniunz.c
+++ /dev/null
@@ -1,660 +0,0 @@
-/*
- miniunz.c
- Version 1.1, February 14h, 2010
- sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-*/
-
-#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-#endif
-
-#ifdef __APPLE__
-// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
-#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
-#define FTELLO_FUNC(stream) ftello(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
-#else
-#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
-#define FTELLO_FUNC(stream) ftello64(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
-#endif
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef _WIN32
-# include <direct.h>
-# include <io.h>
-#else
-# include <unistd.h>
-# include <utime.h>
-#endif
-
-
-#include "unzip.h"
-
-#define CASESENSITIVITY (0)
-#define WRITEBUFFERSIZE (8192)
-#define MAXFILENAME (256)
-
-#ifdef _WIN32
-#define USEWIN32IOAPI
-#include "iowin32.h"
-#endif
-/*
- mini unzip, demo of unzip package
-
- usage :
- Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]
-
- list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
- if it exists
-*/
-
-
-/* change_file_date : change the date/time of a file
- filename : the filename of the file where date/time must be modified
- dosdate : the new date at the MSDos format (4 bytes)
- tmu_date : the SAME new date at the tm_unz format */
-void change_file_date(filename,dosdate,tmu_date)
- const char *filename;
- uLong dosdate;
- tm_unz tmu_date;
-{
-#ifdef _WIN32
- HANDLE hFile;
- FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
-
- hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
- 0,NULL,OPEN_EXISTING,0,NULL);
- GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
- DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
- LocalFileTimeToFileTime(&ftLocal,&ftm);
- SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
- CloseHandle(hFile);
-#else
-#ifdef unix || __APPLE__
- struct utimbuf ut;
- struct tm newdate;
- newdate.tm_sec = tmu_date.tm_sec;
- newdate.tm_min=tmu_date.tm_min;
- newdate.tm_hour=tmu_date.tm_hour;
- newdate.tm_mday=tmu_date.tm_mday;
- newdate.tm_mon=tmu_date.tm_mon;
- if (tmu_date.tm_year > 1900)
- newdate.tm_year=tmu_date.tm_year - 1900;
- else
- newdate.tm_year=tmu_date.tm_year ;
- newdate.tm_isdst=-1;
-
- ut.actime=ut.modtime=mktime(&newdate);
- utime(filename,&ut);
-#endif
-#endif
-}
-
-
-/* mymkdir and change_file_date are not 100 % portable
- As I don't know well Unix, I wait feedback for the unix portion */
-
-int mymkdir(dirname)
- const char* dirname;
-{
- int ret=0;
-#ifdef _WIN32
- ret = _mkdir(dirname);
-#elif unix
- ret = mkdir (dirname,0775);
-#elif __APPLE__
- ret = mkdir (dirname,0775);
-#endif
- return ret;
-}
-
-int makedir (newdir)
- char *newdir;
-{
- char *buffer ;
- char *p;
- int len = (int)strlen(newdir);
-
- if (len <= 0)
- return 0;
-
- buffer = (char*)malloc(len+1);
- if (buffer==NULL)
- {
- printf("Error allocating memory\n");
- return UNZ_INTERNALERROR;
- }
- strcpy(buffer,newdir);
-
- if (buffer[len-1] == '/') {
- buffer[len-1] = '\0';
- }
- if (mymkdir(buffer) == 0)
- {
- free(buffer);
- return 1;
- }
-
- p = buffer+1;
- while (1)
- {
- char hold;
-
- while(*p && *p != '\\' && *p != '/')
- p++;
- hold = *p;
- *p = 0;
- if ((mymkdir(buffer) == -1) && (errno == ENOENT))
- {
- printf("couldn't create directory %s\n",buffer);
- free(buffer);
- return 0;
- }
- if (hold == 0)
- break;
- *p++ = hold;
- }
- free(buffer);
- return 1;
-}
-
-void do_banner()
-{
- printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
- printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
-}
-
-void do_help()
-{
- printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
- " -e Extract without pathname (junk paths)\n" \
- " -x Extract with pathname\n" \
- " -v list files\n" \
- " -l list files\n" \
- " -d directory to extract into\n" \
- " -o overwrite files without prompting\n" \
- " -p extract crypted file using password\n\n");
-}
-
-void Display64BitsSize(ZPOS64_T n, int size_char)
-{
- /* to avoid compatibility problem , we do here the conversion */
- char number[21];
- int offset=19;
- int pos_string = 19;
- number[20]=0;
- for (;;) {
- number[offset]=(char)((n%10)+'0');
- if (number[offset] != '0')
- pos_string=offset;
- n/=10;
- if (offset==0)
- break;
- offset--;
- }
- {
- int size_display_string = 19-pos_string;
- while (size_char > size_display_string)
- {
- size_char--;
- printf(" ");
- }
- }
-
- printf("%s",&number[pos_string]);
-}
-
-int do_list(uf)
- unzFile uf;
-{
- uLong i;
- unz_global_info64 gi;
- int err;
-
- err = unzGetGlobalInfo64(uf,&gi);
- if (err!=UNZ_OK)
- printf("error %d with zipfile in unzGetGlobalInfo \n",err);
- printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
- printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
- for (i=0;i<gi.number_entry;i++)
- {
- char filename_inzip[256];
- unz_file_info64 file_info;
- uLong ratio=0;
- const char *string_method;
- char charCrypt=' ';
- err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
- break;
- }
- if (file_info.uncompressed_size>0)
- ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
-
- /* display a '*' if the file is crypted */
- if ((file_info.flag & 1) != 0)
- charCrypt='*';
-
- if (file_info.compression_method==0)
- string_method="Stored";
- else
- if (file_info.compression_method==Z_DEFLATED)
- {
- uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
- if (iLevel==0)
- string_method="Defl:N";
- else if (iLevel==1)
- string_method="Defl:X";
- else if ((iLevel==2) || (iLevel==3))
- string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
- }
- else
- if (file_info.compression_method==Z_BZIP2ED)
- {
- string_method="BZip2 ";
- }
- else
- string_method="Unkn. ";
-
- Display64BitsSize(file_info.uncompressed_size,7);
- printf(" %6s%c",string_method,charCrypt);
- Display64BitsSize(file_info.compressed_size,7);
- printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
- ratio,
- (uLong)file_info.tmu_date.tm_mon + 1,
- (uLong)file_info.tmu_date.tm_mday,
- (uLong)file_info.tmu_date.tm_year % 100,
- (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
- (uLong)file_info.crc,filename_inzip);
- if ((i+1)<gi.number_entry)
- {
- err = unzGoToNextFile(uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGoToNextFile\n",err);
- break;
- }
- }
- }
-
- return 0;
-}
-
-
-int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
- unzFile uf;
- const int* popt_extract_without_path;
- int* popt_overwrite;
- const char* password;
-{
- char filename_inzip[256];
- char* filename_withoutpath;
- char* p;
- int err=UNZ_OK;
- FILE *fout=NULL;
- void* buf;
- uInt size_buf;
-
- unz_file_info64 file_info;
- uLong ratio=0;
- err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
-
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
- return err;
- }
-
- size_buf = WRITEBUFFERSIZE;
- buf = (void*)malloc(size_buf);
- if (buf==NULL)
- {
- printf("Error allocating memory\n");
- return UNZ_INTERNALERROR;
- }
-
- p = filename_withoutpath = filename_inzip;
- while ((*p) != '\0')
- {
- if (((*p)=='/') || ((*p)=='\\'))
- filename_withoutpath = p+1;
- p++;
- }
-
- if ((*filename_withoutpath)=='\0')
- {
- if ((*popt_extract_without_path)==0)
- {
- printf("creating directory: %s\n",filename_inzip);
- mymkdir(filename_inzip);
- }
- }
- else
- {
- const char* write_filename;
- int skip=0;
-
- if ((*popt_extract_without_path)==0)
- write_filename = filename_inzip;
- else
- write_filename = filename_withoutpath;
-
- err = unzOpenCurrentFilePassword(uf,password);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
- }
-
- if (((*popt_overwrite)==0) && (err==UNZ_OK))
- {
- char rep=0;
- FILE* ftestexist;
- ftestexist = FOPEN_FUNC(write_filename,"rb");
- if (ftestexist!=NULL)
- {
- fclose(ftestexist);
- do
- {
- char answer[128];
- int ret;
-
- printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
- ret = scanf("%1s",answer);
- if (ret != 1)
- {
- exit(EXIT_FAILURE);
- }
- rep = answer[0] ;
- if ((rep>='a') && (rep<='z'))
- rep -= 0x20;
- }
- while ((rep!='Y') && (rep!='N') && (rep!='A'));
- }
-
- if (rep == 'N')
- skip = 1;
-
- if (rep == 'A')
- *popt_overwrite=1;
- }
-
- if ((skip==0) && (err==UNZ_OK))
- {
- fout=FOPEN_FUNC(write_filename,"wb");
- /* some zipfile don't contain directory alone before file */
- if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
- (filename_withoutpath!=(char*)filename_inzip))
- {
- char c=*(filename_withoutpath-1);
- *(filename_withoutpath-1)='\0';
- makedir(write_filename);
- *(filename_withoutpath-1)=c;
- fout=FOPEN_FUNC(write_filename,"wb");
- }
-
- if (fout==NULL)
- {
- printf("error opening %s\n",write_filename);
- }
- }
-
- if (fout!=NULL)
- {
- printf(" extracting: %s\n",write_filename);
-
- do
- {
- err = unzReadCurrentFile(uf,buf,size_buf);
- if (err<0)
- {
- printf("error %d with zipfile in unzReadCurrentFile\n",err);
- break;
- }
- if (err>0)
- if (fwrite(buf,err,1,fout)!=1)
- {
- printf("error in writing extracted file\n");
- err=UNZ_ERRNO;
- break;
- }
- }
- while (err>0);
- if (fout)
- fclose(fout);
-
- if (err==0)
- change_file_date(write_filename,file_info.dosDate,
- file_info.tmu_date);
- }
-
- if (err==UNZ_OK)
- {
- err = unzCloseCurrentFile (uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzCloseCurrentFile\n",err);
- }
- }
- else
- unzCloseCurrentFile(uf); /* don't lose the error */
- }
-
- free(buf);
- return err;
-}
-
-
-int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
- unzFile uf;
- int opt_extract_without_path;
- int opt_overwrite;
- const char* password;
-{
- uLong i;
- unz_global_info64 gi;
- int err;
- FILE* fout=NULL;
-
- err = unzGetGlobalInfo64(uf,&gi);
- if (err!=UNZ_OK)
- printf("error %d with zipfile in unzGetGlobalInfo \n",err);
-
- for (i=0;i<gi.number_entry;i++)
- {
- if (do_extract_currentfile(uf,&opt_extract_without_path,
- &opt_overwrite,
- password) != UNZ_OK)
- break;
-
- if ((i+1)<gi.number_entry)
- {
- err = unzGoToNextFile(uf);
- if (err!=UNZ_OK)
- {
- printf("error %d with zipfile in unzGoToNextFile\n",err);
- break;
- }
- }
- }
-
- return 0;
-}
-
-int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
- unzFile uf;
- const char* filename;
- int opt_extract_without_path;
- int opt_overwrite;
- const char* password;
-{
- int err = UNZ_OK;
- if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
- {
- printf("file %s not found in the zipfile\n",filename);
- return 2;
- }
-
- if (do_extract_currentfile(uf,&opt_extract_without_path,
- &opt_overwrite,
- password) == UNZ_OK)
- return 0;
- else
- return 1;
-}
-
-
-int main(argc,argv)
- int argc;
- char *argv[];
-{
- const char *zipfilename=NULL;
- const char *filename_to_extract=NULL;
- const char *password=NULL;
- char filename_try[MAXFILENAME+16] = "";
- int i;
- int ret_value=0;
- int opt_do_list=0;
- int opt_do_extract=1;
- int opt_do_extract_withoutpath=0;
- int opt_overwrite=0;
- int opt_extractdir=0;
- const char *dirname=NULL;
- unzFile uf=NULL;
-
- do_banner();
- if (argc==1)
- {
- do_help();
- return 0;
- }
- else
- {
- for (i=1;i<argc;i++)
- {
- if ((*argv[i])=='-')
- {
- const char *p=argv[i]+1;
-
- while ((*p)!='\0')
- {
- char c=*(p++);;
- if ((c=='l') || (c=='L'))
- opt_do_list = 1;
- if ((c=='v') || (c=='V'))
- opt_do_list = 1;
- if ((c=='x') || (c=='X'))
- opt_do_extract = 1;
- if ((c=='e') || (c=='E'))
- opt_do_extract = opt_do_extract_withoutpath = 1;
- if ((c=='o') || (c=='O'))
- opt_overwrite=1;
- if ((c=='d') || (c=='D'))
- {
- opt_extractdir=1;
- dirname=argv[i+1];
- }
-
- if (((c=='p') || (c=='P')) && (i+1<argc))
- {
- password=argv[i+1];
- i++;
- }
- }
- }
- else
- {
- if (zipfilename == NULL)
- zipfilename = argv[i];
- else if ((filename_to_extract==NULL) && (!opt_extractdir))
- filename_to_extract = argv[i] ;
- }
- }
- }
-
- if (zipfilename!=NULL)
- {
-
-# ifdef USEWIN32IOAPI
- zlib_filefunc64_def ffunc;
-# endif
-
- strncpy(filename_try, zipfilename,MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- filename_try[ MAXFILENAME ] = '\0';
-
-# ifdef USEWIN32IOAPI
- fill_win32_filefunc64A(&ffunc);
- uf = unzOpen2_64(zipfilename,&ffunc);
-# else
- uf = unzOpen64(zipfilename);
-# endif
- if (uf==NULL)
- {
- strcat(filename_try,".zip");
-# ifdef USEWIN32IOAPI
- uf = unzOpen2_64(filename_try,&ffunc);
-# else
- uf = unzOpen64(filename_try);
-# endif
- }
- }
-
- if (uf==NULL)
- {
- printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
- return 1;
- }
- printf("%s opened\n",filename_try);
-
- if (opt_do_list==1)
- ret_value = do_list(uf);
- else if (opt_do_extract==1)
- {
-#ifdef _WIN32
- if (opt_extractdir && _chdir(dirname))
-#else
- if (opt_extractdir && chdir(dirname))
-#endif
- {
- printf("Error changing into %s, aborting\n", dirname);
- exit(-1);
- }
-
- if (filename_to_extract == NULL)
- ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
- else
- ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
- }
-
- unzClose(uf);
-
- return ret_value;
-}
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c
deleted file mode 100644
index 4288962..0000000
--- a/contrib/minizip/minizip.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- minizip.c
- Version 1.1, February 14h, 2010
- sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-*/
-
-
-#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
- #ifndef __USE_FILE_OFFSET64
- #define __USE_FILE_OFFSET64
- #endif
- #ifndef __USE_LARGEFILE64
- #define __USE_LARGEFILE64
- #endif
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
- #ifndef _FILE_OFFSET_BIT
- #define _FILE_OFFSET_BIT 64
- #endif
-#endif
-
-#ifdef __APPLE__
-// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
-#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
-#define FTELLO_FUNC(stream) ftello(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
-#else
-#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
-#define FTELLO_FUNC(stream) ftello64(stream)
-#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
-#endif
-
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#ifdef _WIN32
-# include <direct.h>
-# include <io.h>
-#else
-# include <unistd.h>
-# include <utime.h>
-# include <sys/types.h>
-# include <sys/stat.h>
-#endif
-
-#include "zip.h"
-
-#ifdef _WIN32
- #define USEWIN32IOAPI
- #include "iowin32.h"
-#endif
-
-
-
-#define WRITEBUFFERSIZE (16384)
-#define MAXFILENAME (256)
-
-#ifdef _WIN32
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- int ret = 0;
- {
- FILETIME ftLocal;
- HANDLE hFind;
- WIN32_FIND_DATAA ff32;
-
- hFind = FindFirstFileA(f,&ff32);
- if (hFind != INVALID_HANDLE_VALUE)
- {
- FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
- FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
- FindClose(hFind);
- ret = 1;
- }
- }
- return ret;
-}
-#else
-#ifdef unix || __APPLE__
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- int ret=0;
- struct stat s; /* results of stat() */
- struct tm* filedate;
- time_t tm_t=0;
-
- if (strcmp(f,"-")!=0)
- {
- char name[MAXFILENAME+1];
- int len = strlen(f);
- if (len > MAXFILENAME)
- len = MAXFILENAME;
-
- strncpy(name, f,MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- name[ MAXFILENAME ] = '\0';
-
- if (name[len - 1] == '/')
- name[len - 1] = '\0';
- /* not all systems allow stat'ing a file with / appended */
- if (stat(name,&s)==0)
- {
- tm_t = s.st_mtime;
- ret = 1;
- }
- }
- filedate = localtime(&tm_t);
-
- tmzip->tm_sec = filedate->tm_sec;
- tmzip->tm_min = filedate->tm_min;
- tmzip->tm_hour = filedate->tm_hour;
- tmzip->tm_mday = filedate->tm_mday;
- tmzip->tm_mon = filedate->tm_mon ;
- tmzip->tm_year = filedate->tm_year;
-
- return ret;
-}
-#else
-uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
- uLong *dt; /* dostime */
-{
- return 0;
-}
-#endif
-#endif
-
-
-
-
-int check_exist_file(filename)
- const char* filename;
-{
- FILE* ftestexist;
- int ret = 1;
- ftestexist = FOPEN_FUNC(filename,"rb");
- if (ftestexist==NULL)
- ret = 0;
- else
- fclose(ftestexist);
- return ret;
-}
-
-void do_banner()
-{
- printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
- printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
-}
-
-void do_help()
-{
- printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
- " -o Overwrite existing file.zip\n" \
- " -a Append to existing file.zip\n" \
- " -0 Store only\n" \
- " -1 Compress faster\n" \
- " -9 Compress better\n\n" \
- " -j exclude path. store only the file name.\n\n");
-}
-
-/* calculate the CRC32 of a file,
- because to encrypt a file, we need known the CRC32 of the file before */
-int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
-{
- unsigned long calculate_crc=0;
- int err=ZIP_OK;
- FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
-
- unsigned long size_read = 0;
- unsigned long total_read = 0;
- if (fin==NULL)
- {
- err = ZIP_ERRNO;
- }
-
- if (err == ZIP_OK)
- do
- {
- err = ZIP_OK;
- size_read = (int)fread(buf,1,size_buf,fin);
- if (size_read < size_buf)
- if (feof(fin)==0)
- {
- printf("error in reading %s\n",filenameinzip);
- err = ZIP_ERRNO;
- }
-
- if (size_read>0)
- calculate_crc = crc32(calculate_crc,buf,size_read);
- total_read += size_read;
-
- } while ((err == ZIP_OK) && (size_read>0));
-
- if (fin)
- fclose(fin);
-
- *result_crc=calculate_crc;
- printf("file %s crc %lx\n", filenameinzip, calculate_crc);
- return err;
-}
-
-int isLargeFile(const char* filename)
-{
- int largeFile = 0;
- ZPOS64_T pos = 0;
- FILE* pFile = FOPEN_FUNC(filename, "rb");
-
- if(pFile != NULL)
- {
- int n = FSEEKO_FUNC(pFile, 0, SEEK_END);
- pos = FTELLO_FUNC(pFile);
-
- printf("File : %s is %lld bytes\n", filename, pos);
-
- if(pos >= 0xffffffff)
- largeFile = 1;
-
- fclose(pFile);
- }
-
- return largeFile;
-}
-
-int main(argc,argv)
- int argc;
- char *argv[];
-{
- int i;
- int opt_overwrite=0;
- int opt_compress_level=Z_DEFAULT_COMPRESSION;
- int opt_exclude_path=0;
- int zipfilenamearg = 0;
- char filename_try[MAXFILENAME+16];
- int zipok;
- int err=0;
- int size_buf=0;
- void* buf=NULL;
- const char* password=NULL;
-
-
- do_banner();
- if (argc==1)
- {
- do_help();
- return 0;
- }
- else
- {
- for (i=1;i<argc;i++)
- {
- if ((*argv[i])=='-')
- {
- const char *p=argv[i]+1;
-
- while ((*p)!='\0')
- {
- char c=*(p++);;
- if ((c=='o') || (c=='O'))
- opt_overwrite = 1;
- if ((c=='a') || (c=='A'))
- opt_overwrite = 2;
- if ((c>='0') && (c<='9'))
- opt_compress_level = c-'0';
- if ((c=='j') || (c=='J'))
- opt_exclude_path = 1;
-
- if (((c=='p') || (c=='P')) && (i+1<argc))
- {
- password=argv[i+1];
- i++;
- }
- }
- }
- else
- {
- if (zipfilenamearg == 0)
- {
- zipfilenamearg = i ;
- }
- }
- }
- }
-
- size_buf = WRITEBUFFERSIZE;
- buf = (void*)malloc(size_buf);
- if (buf==NULL)
- {
- printf("Error allocating memory\n");
- return ZIP_INTERNALERROR;
- }
-
- if (zipfilenamearg==0)
- {
- zipok=0;
- }
- else
- {
- int i,len;
- int dot_found=0;
-
- zipok = 1 ;
- strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
- /* strncpy doesnt append the trailing NULL, of the string is too long. */
- filename_try[ MAXFILENAME ] = '\0';
-
- len=(int)strlen(filename_try);
- for (i=0;i<len;i++)
- if (filename_try[i]=='.')
- dot_found=1;
-
- if (dot_found==0)
- strcat(filename_try,".zip");
-
- if (opt_overwrite==2)
- {
- /* if the file don't exist, we not append file */
- if (check_exist_file(filename_try)==0)
- opt_overwrite=1;
- }
- else
- if (opt_overwrite==0)
- if (check_exist_file(filename_try)!=0)
- {
- char rep=0;
- do
- {
- char answer[128];
- int ret;
- printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
- ret = scanf("%1s",answer);
- if (ret != 1)
- {
- exit(EXIT_FAILURE);
- }
- rep = answer[0] ;
- if ((rep>='a') && (rep<='z'))
- rep -= 0x20;
- }
- while ((rep!='Y') && (rep!='N') && (rep!='A'));
- if (rep=='N')
- zipok = 0;
- if (rep=='A')
- opt_overwrite = 2;
- }
- }
-
- if (zipok==1)
- {
- zipFile zf;
- int errclose;
-# ifdef USEWIN32IOAPI
- zlib_filefunc64_def ffunc;
- fill_win32_filefunc64A(&ffunc);
- zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
-# else
- zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
-# endif
-
- if (zf == NULL)
- {
- printf("error opening %s\n",filename_try);
- err= ZIP_ERRNO;
- }
- else
- printf("creating %s\n",filename_try);
-
- for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
- {
- if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
- ((argv[i][1]=='o') || (argv[i][1]=='O') ||
- (argv[i][1]=='a') || (argv[i][1]=='A') ||
- (argv[i][1]=='p') || (argv[i][1]=='P') ||
- ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
- (strlen(argv[i]) == 2)))
- {
- FILE * fin;
- int size_read;
- const char* filenameinzip = argv[i];
- const char *savefilenameinzip;
- zip_fileinfo zi;
- unsigned long crcFile=0;
- int zip64 = 0;
-
- zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
- zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
- zi.dosDate = 0;
- zi.internal_fa = 0;
- zi.external_fa = 0;
- filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
-
-/*
- err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
- NULL,0,NULL,0,NULL / * comment * /,
- (opt_compress_level != 0) ? Z_DEFLATED : 0,
- opt_compress_level);
-*/
- if ((password != NULL) && (err==ZIP_OK))
- err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
-
- zip64 = isLargeFile(filenameinzip);
-
- /* The path name saved, should not include a leading slash. */
- /*if it did, windows/xp and dynazip couldn't read the zip file. */
- savefilenameinzip = filenameinzip;
- while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
- {
- savefilenameinzip++;
- }
-
- /*should the zip file contain any path at all?*/
- if( opt_exclude_path )
- {
- const char *tmpptr;
- const char *lastslash = 0;
- for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
- {
- if( *tmpptr == '\\' || *tmpptr == '/')
- {
- lastslash = tmpptr;
- }
- }
- if( lastslash != NULL )
- {
- savefilenameinzip = lastslash+1; // base filename follows last slash.
- }
- }
-
- /**/
- err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
- NULL,0,NULL,0,NULL /* comment*/,
- (opt_compress_level != 0) ? Z_DEFLATED : 0,
- opt_compress_level,0,
- /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- password,crcFile, zip64);
-
- if (err != ZIP_OK)
- printf("error in opening %s in zipfile\n",filenameinzip);
- else
- {
- fin = FOPEN_FUNC(filenameinzip,"rb");
- if (fin==NULL)
- {
- err=ZIP_ERRNO;
- printf("error in opening %s for reading\n",filenameinzip);
- }
- }
-
- if (err == ZIP_OK)
- do
- {
- err = ZIP_OK;
- size_read = (int)fread(buf,1,size_buf,fin);
- if (size_read < size_buf)
- if (feof(fin)==0)
- {
- printf("error in reading %s\n",filenameinzip);
- err = ZIP_ERRNO;
- }
-
- if (size_read>0)
- {
- err = zipWriteInFileInZip (zf,buf,size_read);
- if (err<0)
- {
- printf("error in writing %s in the zipfile\n",
- filenameinzip);
- }
-
- }
- } while ((err == ZIP_OK) && (size_read>0));
-
- if (fin)
- fclose(fin);
-
- if (err<0)
- err=ZIP_ERRNO;
- else
- {
- err = zipCloseFileInZip(zf);
- if (err!=ZIP_OK)
- printf("error in closing %s in the zipfile\n",
- filenameinzip);
- }
- }
- }
- errclose = zipClose(zf,NULL);
- if (errclose != ZIP_OK)
- printf("error in closing %s\n",filename_try);
- }
- else
- {
- do_help();
- }
-
- free(buf);
- return 0;
-}
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c
deleted file mode 100644
index 8bf9cca..0000000
--- a/contrib/minizip/mztools.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- Additional tools for Minizip
- Code: Xavier Roche '2004
- License: Same as ZLIB (www.gzip.org)
-*/
-
-/* Code */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "third_party/zlib/zlib.h"
-#include "unzip.h"
-
-#define READ_8(adr) ((unsigned char)*(adr))
-#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
-#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
-
-#define WRITE_8(buff, n) do { \
- *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
-} while(0)
-#define WRITE_16(buff, n) do { \
- WRITE_8((unsigned char*)(buff), n); \
- WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
-} while(0)
-#define WRITE_32(buff, n) do { \
- WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
- WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
-} while(0)
-
-extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
-const char* file;
-const char* fileOut;
-const char* fileOutTmp;
-uLong* nRecovered;
-uLong* bytesRecovered;
-{
- int err = Z_OK;
- FILE* fpZip = fopen(file, "rb");
- FILE* fpOut = fopen(fileOut, "wb");
- FILE* fpOutCD = fopen(fileOutTmp, "wb");
- if (fpZip != NULL && fpOut != NULL) {
- int entries = 0;
- uLong totalBytes = 0;
- char header[30];
- char filename[1024];
- char extra[1024];
- int offset = 0;
- int offsetCD = 0;
- while ( fread(header, 1, 30, fpZip) == 30 ) {
- int currentOffset = offset;
-
- /* File entry */
- if (READ_32(header) == 0x04034b50) {
- unsigned int version = READ_16(header + 4);
- unsigned int gpflag = READ_16(header + 6);
- unsigned int method = READ_16(header + 8);
- unsigned int filetime = READ_16(header + 10);
- unsigned int filedate = READ_16(header + 12);
- unsigned int crc = READ_32(header + 14); /* crc */
- unsigned int cpsize = READ_32(header + 18); /* compressed size */
- unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
- unsigned int fnsize = READ_16(header + 26); /* file name length */
- unsigned int extsize = READ_16(header + 28); /* extra field length */
- filename[0] = extra[0] = '\0';
-
- /* Header */
- if (fwrite(header, 1, 30, fpOut) == 30) {
- offset += 30;
- } else {
- err = Z_ERRNO;
- break;
- }
-
- /* Filename */
- if (fnsize > 0) {
- if (fnsize < sizeof(filename)) {
- if (fread(filename, 1, fnsize, fpZip) == fnsize) {
- if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
- offset += fnsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_STREAM_ERROR;
- break;
- }
-
- /* Extra field */
- if (extsize > 0) {
- if (extsize < sizeof(extra)) {
- if (fread(extra, 1, extsize, fpZip) == extsize) {
- if (fwrite(extra, 1, extsize, fpOut) == extsize) {
- offset += extsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Data */
- {
- int dataSize = cpsize;
- if (dataSize == 0) {
- dataSize = uncpsize;
- }
- if (dataSize > 0) {
- char* data = malloc(dataSize);
- if (data != NULL) {
- if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
- if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
- offset += dataSize;
- totalBytes += dataSize;
- } else {
- err = Z_ERRNO;
- }
- } else {
- err = Z_ERRNO;
- }
- free(data);
- if (err != Z_OK) {
- break;
- }
- } else {
- err = Z_MEM_ERROR;
- break;
- }
- }
- }
-
- /* Central directory entry */
- {
- char header[46];
- char* comment = "";
- int comsize = (int) strlen(comment);
- WRITE_32(header, 0x02014b50);
- WRITE_16(header + 4, version);
- WRITE_16(header + 6, version);
- WRITE_16(header + 8, gpflag);
- WRITE_16(header + 10, method);
- WRITE_16(header + 12, filetime);
- WRITE_16(header + 14, filedate);
- WRITE_32(header + 16, crc);
- WRITE_32(header + 20, cpsize);
- WRITE_32(header + 24, uncpsize);
- WRITE_16(header + 28, fnsize);
- WRITE_16(header + 30, extsize);
- WRITE_16(header + 32, comsize);
- WRITE_16(header + 34, 0); /* disk # */
- WRITE_16(header + 36, 0); /* int attrb */
- WRITE_32(header + 38, 0); /* ext attrb */
- WRITE_32(header + 42, currentOffset);
- /* Header */
- if (fwrite(header, 1, 46, fpOutCD) == 46) {
- offsetCD += 46;
-
- /* Filename */
- if (fnsize > 0) {
- if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
- offsetCD += fnsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- } else {
- err = Z_STREAM_ERROR;
- break;
- }
-
- /* Extra field */
- if (extsize > 0) {
- if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
- offsetCD += extsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Comment field */
- if (comsize > 0) {
- if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
- offsetCD += comsize;
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
-
- } else {
- err = Z_ERRNO;
- break;
- }
- }
-
- /* Success */
- entries++;
-
- } else {
- break;
- }
- }
-
- /* Final central directory */
- {
- int entriesZip = entries;
- char header[22];
- char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
- int comsize = (int) strlen(comment);
- if (entriesZip > 0xffff) {
- entriesZip = 0xffff;
- }
- WRITE_32(header, 0x06054b50);
- WRITE_16(header + 4, 0); /* disk # */
- WRITE_16(header + 6, 0); /* disk # */
- WRITE_16(header + 8, entriesZip); /* hack */
- WRITE_16(header + 10, entriesZip); /* hack */
- WRITE_32(header + 12, offsetCD); /* size of CD */
- WRITE_32(header + 16, offset); /* offset to CD */
- WRITE_16(header + 20, comsize); /* comment */
-
- /* Header */
- if (fwrite(header, 1, 22, fpOutCD) == 22) {
-
- /* Comment field */
- if (comsize > 0) {
- if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
- err = Z_ERRNO;
- }
- }
-
- } else {
- err = Z_ERRNO;
- }
- }
-
- /* Final merge (file + central directory) */
- fclose(fpOutCD);
- if (err == Z_OK) {
- fpOutCD = fopen(fileOutTmp, "rb");
- if (fpOutCD != NULL) {
- int nRead;
- char buffer[8192];
- while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
- if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
- err = Z_ERRNO;
- break;
- }
- }
- fclose(fpOutCD);
- }
- }
-
- /* Close */
- fclose(fpZip);
- fclose(fpOut);
-
- /* Wipe temporary file */
- (void)remove(fileOutTmp);
-
- /* Number of recovered entries */
- if (err == Z_OK) {
- if (nRecovered != NULL) {
- *nRecovered = entries;
- }
- if (bytesRecovered != NULL) {
- *bytesRecovered = totalBytes;
- }
- }
- } else {
- err = Z_STREAM_ERROR;
- }
- return err;
-}
diff --git a/contrib/minizip/mztools.h b/contrib/minizip/mztools.h
deleted file mode 100644
index f295ffe..0000000
--- a/contrib/minizip/mztools.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- Additional tools for Minizip
- Code: Xavier Roche '2004
- License: Same as ZLIB (www.gzip.org)
-*/
-
-#ifndef _zip_tools_H
-#define _zip_tools_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "third_party/zlib/zlib.h"
-#endif
-
-#include "unzip.h"
-
-/* Repair a ZIP file (missing central directory)
- file: file to recover
- fileOut: output file after recovery
- fileOutTmp: temporary file name used for recovery
-*/
-extern int ZEXPORT unzRepair(const char* file,
- const char* fileOut,
- const char* fileOutTmp,
- uLong* nRecovered,
- uLong* bytesRecovered);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
deleted file mode 100644
index e8b2bc5..0000000
--- a/contrib/minizip/unzip.c
+++ /dev/null
@@ -1,2117 +0,0 @@
-/* unzip.c -- IO for uncompress .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
-
- ------------------------------------------------------------------------------------
- Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
- compatibility with older software. The following is from the original crypt.c.
- Code woven in by Terry Thorsen 1/2003.
-
- Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
-
- See the accompanying file LICENSE, version 2000-Apr-09 or later
- (the contents of which are also included in zip.h) for terms of use.
- If, for some reason, all these files are missing, the Info-ZIP license
- also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
-
- crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
-
- The encryption/decryption parts of this source code (as opposed to the
- non-echoing password parts) were originally written in Europe. The
- whole source package can be freely distributed, including from the USA.
- (Prior to January 2000, re-export from the US was a violation of US law.)
-
- This encryption code is a direct transcription of the algorithm from
- Roger Schlafly, described by Phil Katz in the file appnote.txt. This
- file (appnote.txt) is distributed with the PKZIP program (even in the
- version without encryption capabilities).
-
- ------------------------------------------------------------------------------------
-
- Changes in unzip.c
-
- 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
- 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
- 2007-2008 - Even Rouault - Remove old C style function prototypes
- 2007-2008 - Even Rouault - Add unzip support for ZIP64
-
- Copyright (C) 2007-2008 Even Rouault
-
-
- Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
- Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
- should only read the compressed/uncompressed size from the Zip64 format if
- the size from normal header was 0xFFFFFFFF
- Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
- Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
- Patch created by Daniel Borca
-
- Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
-
- Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
-
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "third_party/zlib/zlib.h"
-#include "unzip.h"
-
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
-#else
-# include <errno.h>
-#endif
-
-
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-
-#ifndef CASESENSITIVITYDEFAULT_NO
-# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
-# define CASESENSITIVITYDEFAULT_NO
-# endif
-#endif
-
-
-#ifndef UNZ_BUFSIZE
-#define UNZ_BUFSIZE (16384)
-#endif
-
-#ifndef UNZ_MAXFILENAMEINZIP
-#define UNZ_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-
-
-const char unz_copyright[] =
- " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info64_internal_s
-{
- ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
-} unz_file_info64_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
- when reading and decompress it */
-typedef struct
-{
- char *read_buffer; /* internal buffer for compressed data */
- z_stream stream; /* zLib stream structure for inflate */
-
-#ifdef HAVE_BZIP2
- bz_stream bstream; /* bzLib stream structure for bziped */
-#endif
-
- ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
- uLong stream_initialised; /* flag set if stream structure is initialised*/
-
- ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
- uInt size_local_extrafield;/* size of the local extra field */
- ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
- ZPOS64_T total_out_64;
-
- uLong crc32; /* crc32 of all data uncompressed */
- uLong crc32_wait; /* crc32 we must obtain after decompress all */
- ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
- ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
- zlib_filefunc64_32_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- uLong compression_method; /* compression method (0==store) */
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- int raw;
-} file_in_zip64_read_info_s;
-
-
-/* unz64_s contain internal information about the zipfile
-*/
-typedef struct
-{
- zlib_filefunc64_32_def z_filefunc;
- int is64bitOpenFunction;
- voidpf filestream; /* io structore of the zipfile */
- unz_global_info64 gi; /* public global information */
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- ZPOS64_T num_file; /* number of the current file in the zipfile*/
- ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
- ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
- ZPOS64_T central_pos; /* position of the beginning of the central dir*/
-
- ZPOS64_T size_central_dir; /* size of the central directory */
- ZPOS64_T offset_central_dir; /* offset of start of central directory with
- respect to the starting disk number */
-
- unz_file_info64 cur_file_info; /* public info about the current file in zip*/
- unz_file_info64_internal cur_file_info_internal; /* private info about it*/
- file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
- file if we are decompressing it */
- int encrypted;
-
- int isZip64;
-
-# ifndef NOUNCRYPT
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
- const z_crc_t* pcrc_32_tab;
-# endif
-} unz64_s;
-
-
-#ifndef NOUNCRYPT
-#include "crypt.h"
-#endif
-
-/* ===========================================================================
- Read a byte from a gz_stream; update next_in and avail_in. Return EOF
- for end of file.
- IN assertion: the stream s has been successfully opened for reading.
-*/
-
-
-local int unz64local_getByte OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- int *pi));
-
-local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
-{
- unsigned char c;
- int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
- if (err==1)
- {
- *pi = (int)c;
- return UNZ_OK;
- }
- else
- {
- if (ZERROR64(*pzlib_filefunc_def,filestream))
- return UNZ_ERRNO;
- else
- return UNZ_EOF;
- }
-}
-
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int unz64local_getShort OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int unz64local_getLong OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX));
-
-local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- uLong *pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<8;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((uLong)i)<<16;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<24;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int unz64local_getLong64 OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- ZPOS64_T *pX));
-
-
-local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream,
- ZPOS64_T *pX)
-{
- ZPOS64_T x ;
- int i = 0;
- int err;
-
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (ZPOS64_T)i;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<8;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<16;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<24;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<32;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<40;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<48;
-
- if (err==UNZ_OK)
- err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
- x |= ((ZPOS64_T)i)<<56;
-
- if (err==UNZ_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
-{
- for (;;)
- {
- char c1=*(fileName1++);
- char c2=*(fileName2++);
- if ((c1>='a') && (c1<='z'))
- c1 -= 0x20;
- if ((c2>='a') && (c2<='z'))
- c2 -= 0x20;
- if (c1=='\0')
- return ((c2=='\0') ? 0 : -1);
- if (c2=='\0')
- return 1;
- if (c1<c2)
- return -1;
- if (c1>c2)
- return 1;
- }
-}
-
-
-#ifdef CASESENSITIVITYDEFAULT_NO
-#define CASESENSITIVITYDEFAULTVALUE 2
-#else
-#define CASESENSITIVITYDEFAULTVALUE 1
-#endif
-
-#ifndef STRCMPCASENOSENTIVEFUNCTION
-#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
-#endif
-
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-
-*/
-extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity)
-
-{
- if (iCaseSensitivity==0)
- iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
-
- if (iCaseSensitivity==1)
- return strcmp(fileName1,fileName2);
-
- return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-
-/*
- Locate the Central directory of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos ;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- return uPosFound;
-}
-
-
-/*
- Locate the Central directory 64 of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T unz64local_SearchCentralDir64 OF((
- const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream));
-
-local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
- voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
- uLong uL;
- ZPOS64_T relativeOffset;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- if (uPosFound == 0)
- return 0;
-
- /* Zip64 end of central directory locator */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature, already checked */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
-
- /* number of the disk with the start of the zip64 end of central directory */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
- if (uL != 0)
- return 0;
-
- /* relative offset of the zip64 end of central directory record */
- if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
- return 0;
-
- /* total number of disks */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
- if (uL != 1)
- return 0;
-
- /* Goto end of central directory record */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature */
- if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
- return 0;
-
- if (uL != 0x06064b50)
- return 0;
-
- return relativeOffset;
-}
-
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
- "zlib/zlib114.zip".
- If the zipfile cannot be opened (file doesn't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
-*/
-local unzFile unzOpenInternal (const void *path,
- zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
- int is64bitOpenFunction)
-{
- unz64_s us;
- unz64_s *s;
- ZPOS64_T central_pos;
- uLong uL;
-
- uLong number_disk; /* number of the current dist, used for
- spaning ZIP, unsupported, always 0*/
- uLong number_disk_with_CD; /* number the the disk with central dir, used
- for spaning ZIP, unsupported, always 0*/
- ZPOS64_T number_entry_CD; /* total number of entries in
- the central dir
- (same than number_entry on nospan) */
-
- int err=UNZ_OK;
-
- if (unz_copyright[0]!=' ')
- return NULL;
-
- us.z_filefunc.zseek32_file = NULL;
- us.z_filefunc.ztell32_file = NULL;
- if (pzlib_filefunc64_32_def==NULL)
- fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
- else
- us.z_filefunc = *pzlib_filefunc64_32_def;
- us.is64bitOpenFunction = is64bitOpenFunction;
-
-
-
- us.filestream = ZOPEN64(us.z_filefunc,
- path,
- ZLIB_FILEFUNC_MODE_READ |
- ZLIB_FILEFUNC_MODE_EXISTING);
- if (us.filestream==NULL)
- return NULL;
-
- central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
- if (central_pos)
- {
- uLong uS;
- ZPOS64_T uL64;
-
- us.isZip64 = 1;
-
- if (ZSEEK64(us.z_filefunc, us.filestream,
- central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
- /* the signature, already checked */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* size of zip64 end of central directory record */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* version made by */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* version needed to extract */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of this disk */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central directory on this disk */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central directory */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- if ((number_entry_CD!=us.gi.number_entry) ||
- (number_disk_with_CD!=0) ||
- (number_disk!=0))
- err=UNZ_BADZIPFILE;
-
- /* size of the central directory */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- us.gi.size_comment = 0;
- }
- else
- {
- central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
- if (central_pos==0)
- err=UNZ_ERRNO;
-
- us.isZip64 = 0;
-
- if (ZSEEK64(us.z_filefunc, us.filestream,
- central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
- /* the signature, already checked */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of this disk */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
- err=UNZ_ERRNO;
-
- /* total number of entries in the central dir on this disk */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.gi.number_entry = uL;
-
- /* total number of entries in the central dir */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- number_entry_CD = uL;
-
- if ((number_entry_CD!=us.gi.number_entry) ||
- (number_disk_with_CD!=0) ||
- (number_disk!=0))
- err=UNZ_BADZIPFILE;
-
- /* size of the central directory */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.size_central_dir = uL;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
- err=UNZ_ERRNO;
- us.offset_central_dir = uL;
-
- /* zipfile comment length */
- if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
- (err==UNZ_OK))
- err=UNZ_BADZIPFILE;
-
- if (err!=UNZ_OK)
- {
- ZCLOSE64(us.z_filefunc, us.filestream);
- return NULL;
- }
-
- us.byte_before_the_zipfile = central_pos -
- (us.offset_central_dir+us.size_central_dir);
- us.central_pos = central_pos;
- us.pfile_in_zip_read = NULL;
- us.encrypted = 0;
-
-
- s=(unz64_s*)ALLOC(sizeof(unz64_s));
- if( s != NULL)
- {
- *s=us;
- unzGoToFirstFile((unzFile)s);
- }
- return (unzFile)s;
-}
-
-
-extern unzFile ZEXPORT unzOpen2 (const char *path,
- zlib_filefunc_def* pzlib_filefunc32_def)
-{
- if (pzlib_filefunc32_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
- return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
- }
- else
- return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen2_64 (const void *path,
- zlib_filefunc64_def* pzlib_filefunc_def)
-{
- if (pzlib_filefunc_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
- return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
- }
- else
- return unzOpenInternal(path, NULL, 1);
-}
-
-extern unzFile ZEXPORT unzOpen (const char *path)
-{
- return unzOpenInternal(path, NULL, 0);
-}
-
-extern unzFile ZEXPORT unzOpen64 (const void *path)
-{
- return unzOpenInternal(path, NULL, 1);
-}
-
-/*
- Close a ZipFile opened with unzOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzCloseCurrentFile before call unzClose.
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (unzFile file)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- if (s->pfile_in_zip_read!=NULL)
- unzCloseCurrentFile(file);
-
- ZCLOSE64(s->z_filefunc, s->filestream);
- TRYFREE(s);
- return UNZ_OK;
-}
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- *pglobal_info=s->gi;
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
-{
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- /* to do : check if number_entry is not truncated */
- pglobal_info32->number_entry = (uLong)s->gi.number_entry;
- pglobal_info32->size_comment = s->gi.size_comment;
- return UNZ_OK;
-}
-/*
- Translate date/time from Dos format to tm_unz (readable more easilty)
-*/
-local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
-{
- ZPOS64_T uDate;
- uDate = (ZPOS64_T)(ulDosDate>>16);
- ptm->tm_mday = (uInt)(uDate&0x1f) ;
- ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
- ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
-
- ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
- ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
- ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
-}
-
-/*
- Get Info about the current file in the zipfile, with internal only info
-*/
-local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
- unz_file_info64 *pfile_info,
- unz_file_info64_internal
- *pfile_info_internal,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-
-local int unz64local_GetCurrentFileInfoInternal (unzFile file,
- unz_file_info64 *pfile_info,
- unz_file_info64_internal
- *pfile_info_internal,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize)
-{
- unz64_s* s;
- unz_file_info64 file_info;
- unz_file_info64_internal file_info_internal;
- int err=UNZ_OK;
- uLong uMagic;
- long lSeek=0;
- uLong uL;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (ZSEEK64(s->z_filefunc, s->filestream,
- s->pos_in_central_dir+s->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=UNZ_ERRNO;
-
-
- /* we check the magic */
- if (err==UNZ_OK)
- {
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- err=UNZ_ERRNO;
- else if (uMagic!=0x02014b50)
- err=UNZ_BADZIPFILE;
- }
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
- err=UNZ_ERRNO;
-
- unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info.compressed_size = uL;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info.uncompressed_size = uL;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
- err=UNZ_ERRNO;
-
- // relative offset of local header
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- file_info_internal.offset_curfile = uL;
-
- lSeek+=file_info.size_filename;
- if ((err==UNZ_OK) && (szFileName!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_filename<fileNameBufferSize)
- {
- *(szFileName+file_info.size_filename)='\0';
- uSizeRead = file_info.size_filename;
- }
- else
- uSizeRead = fileNameBufferSize;
-
- if ((file_info.size_filename>0) && (fileNameBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek -= uSizeRead;
- }
-
- // Read extrafield
- if ((err==UNZ_OK) && (extraField!=NULL))
- {
- ZPOS64_T uSizeRead ;
- if (file_info.size_file_extra<extraFieldBufferSize)
- uSizeRead = file_info.size_file_extra;
- else
- uSizeRead = extraFieldBufferSize;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
-
- lSeek += file_info.size_file_extra - (uLong)uSizeRead;
- }
- else
- lSeek += file_info.size_file_extra;
-
-
- if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
- {
- uLong acc = 0;
-
- // since lSeek now points to after the extra field we need to move back
- lSeek -= file_info.size_file_extra;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- while(acc < file_info.size_file_extra)
- {
- uLong headerId;
- uLong dataSize;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
- err=UNZ_ERRNO;
-
- /* ZIP64 extra fields */
- if (headerId == 0x0001)
- {
- uLong uL;
-
- if(file_info.uncompressed_size == MAXU32)
- {
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info.compressed_size == MAXU32)
- {
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info_internal.offset_curfile == MAXU32)
- {
- /* Relative Header offset */
- if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- if(file_info.disk_num_start == MAXU32)
- {
- /* Disk Start Number */
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
- err=UNZ_ERRNO;
- }
-
- }
- else
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
- err=UNZ_ERRNO;
- }
-
- acc += 2 + 2 + dataSize;
- }
- }
-
- if ((err==UNZ_OK) && (szComment!=NULL))
- {
- uLong uSizeRead ;
- if (file_info.size_file_comment<commentBufferSize)
- {
- *(szComment+file_info.size_file_comment)='\0';
- uSizeRead = file_info.size_file_comment;
- }
- else
- uSizeRead = commentBufferSize;
-
- if (lSeek!=0)
- {
- if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
- lSeek=0;
- else
- err=UNZ_ERRNO;
- }
-
- if ((file_info.size_file_comment>0) && (commentBufferSize>0))
- if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
- err=UNZ_ERRNO;
- lSeek+=file_info.size_file_comment - uSizeRead;
- }
- else
- lSeek+=file_info.size_file_comment;
-
-
- if ((err==UNZ_OK) && (pfile_info!=NULL))
- *pfile_info=file_info;
-
- if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
- *pfile_info_internal=file_info_internal;
-
- return err;
-}
-
-
-
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem.
-*/
-extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
- unz_file_info64 * pfile_info,
- char * szFileName, uLong fileNameBufferSize,
- void *extraField, uLong extraFieldBufferSize,
- char* szComment, uLong commentBufferSize)
-{
- return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
- szFileName,fileNameBufferSize,
- extraField,extraFieldBufferSize,
- szComment,commentBufferSize);
-}
-
-extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
- unz_file_info * pfile_info,
- char * szFileName, uLong fileNameBufferSize,
- void *extraField, uLong extraFieldBufferSize,
- char* szComment, uLong commentBufferSize)
-{
- int err;
- unz_file_info64 file_info64;
- err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
- szFileName,fileNameBufferSize,
- extraField,extraFieldBufferSize,
- szComment,commentBufferSize);
- if ((err==UNZ_OK) && (pfile_info != NULL))
- {
- pfile_info->version = file_info64.version;
- pfile_info->version_needed = file_info64.version_needed;
- pfile_info->flag = file_info64.flag;
- pfile_info->compression_method = file_info64.compression_method;
- pfile_info->dosDate = file_info64.dosDate;
- pfile_info->crc = file_info64.crc;
-
- pfile_info->size_filename = file_info64.size_filename;
- pfile_info->size_file_extra = file_info64.size_file_extra;
- pfile_info->size_file_comment = file_info64.size_file_comment;
-
- pfile_info->disk_num_start = file_info64.disk_num_start;
- pfile_info->internal_fa = file_info64.internal_fa;
- pfile_info->external_fa = file_info64.external_fa;
-
- pfile_info->tmu_date = file_info64.tmu_date,
-
-
- pfile_info->compressed_size = (uLong)file_info64.compressed_size;
- pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
-
- }
- return err;
-}
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-extern int ZEXPORT unzGoToFirstFile (unzFile file)
-{
- int err=UNZ_OK;
- unz64_s* s;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- s->pos_in_central_dir=s->offset_central_dir;
- s->num_file=0;
- err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-extern int ZEXPORT unzGoToNextFile (unzFile file)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
- if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
- if (s->num_file+1==s->gi.number_entry)
- return UNZ_END_OF_LIST_OF_FILE;
-
- s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
- s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
- s->num_file++;
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
-{
- unz64_s* s;
- int err;
-
- /* We remember the 'current' position in the file so that we can jump
- * back there if we fail.
- */
- unz_file_info64 cur_file_infoSaved;
- unz_file_info64_internal cur_file_info_internalSaved;
- ZPOS64_T num_fileSaved;
- ZPOS64_T pos_in_central_dirSaved;
-
-
- if (file==NULL)
- return UNZ_PARAMERROR;
-
- if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
- return UNZ_PARAMERROR;
-
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- /* Save the current state */
- num_fileSaved = s->num_file;
- pos_in_central_dirSaved = s->pos_in_central_dir;
- cur_file_infoSaved = s->cur_file_info;
- cur_file_info_internalSaved = s->cur_file_info_internal;
-
- err = unzGoToFirstFile(file);
-
- while (err == UNZ_OK)
- {
- char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
- err = unzGetCurrentFileInfo64(file,NULL,
- szCurrentFileName,sizeof(szCurrentFileName)-1,
- NULL,0,NULL,0);
- if (err == UNZ_OK)
- {
- if (unzStringFileNameCompare(szCurrentFileName,
- szFileName,iCaseSensitivity)==0)
- return UNZ_OK;
- err = unzGoToNextFile(file);
- }
- }
-
- /* We failed, so restore the state of the 'current file' to where we
- * were.
- */
- s->num_file = num_fileSaved ;
- s->pos_in_central_dir = pos_in_central_dirSaved ;
- s->cur_file_info = cur_file_infoSaved;
- s->cur_file_info_internal = cur_file_info_internalSaved;
- return err;
-}
-
-
-/*
-///////////////////////////////////////////
-// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
-// I need random access
-//
-// Further optimization could be realized by adding an ability
-// to cache the directory in memory. The goal being a single
-// comprehensive file read to put the file I need in a memory.
-*/
-
-/*
-typedef struct unz_file_pos_s
-{
- ZPOS64_T pos_in_zip_directory; // offset in file
- ZPOS64_T num_of_file; // # of file
-} unz_file_pos;
-*/
-
-extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
-{
- unz64_s* s;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_END_OF_LIST_OF_FILE;
-
- file_pos->pos_in_zip_directory = s->pos_in_central_dir;
- file_pos->num_of_file = s->num_file;
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos)
-{
- unz64_file_pos file_pos64;
- int err = unzGetFilePos64(file,&file_pos64);
- if (err==UNZ_OK)
- {
- file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
- file_pos->num_of_file = (uLong)file_pos64.num_of_file;
- }
- return err;
-}
-
-extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL || file_pos==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- /* jump to the right spot */
- s->pos_in_central_dir = file_pos->pos_in_zip_directory;
- s->num_file = file_pos->num_of_file;
-
- /* set the current file */
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- /* return results */
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos)
-{
- unz64_file_pos file_pos64;
- if (file_pos == NULL)
- return UNZ_PARAMERROR;
-
- file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
- file_pos64.num_of_file = file_pos->num_of_file;
- return unzGoToFilePos64(file,&file_pos64);
-}
-
-/*
-// Unzip Helper Functions - should be here?
-///////////////////////////////////////////
-*/
-
-/*
- Read the local header of the current zipfile
- Check the coherency of the local header and info in the end of central
- directory about this file
- store in *piSizeVar the size of extra info in local header
- (filename and size of extra field data)
-*/
-local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
- ZPOS64_T * poffset_local_extrafield,
- uInt * psize_local_extrafield)
-{
- uLong uMagic,uData,uFlags;
- uLong size_filename;
- uLong size_extra_field;
- int err=UNZ_OK;
-
- *piSizeVar = 0;
- *poffset_local_extrafield = 0;
- *psize_local_extrafield = 0;
-
- if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
- s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
-
- if (err==UNZ_OK)
- {
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
- err=UNZ_ERRNO;
- else if (uMagic!=0x04034b50)
- err=UNZ_BADZIPFILE;
- }
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
-/*
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
- err=UNZ_BADZIPFILE;
-*/
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
- err=UNZ_ERRNO;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
- err=UNZ_BADZIPFILE;
-
- if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
-/* #ifdef HAVE_BZIP2 */
- (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-/* #endif */
- (s->cur_file_info.compression_method!=Z_DEFLATED))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
- err=UNZ_ERRNO;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
- err=UNZ_ERRNO;
- else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
- err=UNZ_ERRNO;
- else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
- err=UNZ_BADZIPFILE;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
- err=UNZ_ERRNO;
- else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
- err=UNZ_BADZIPFILE;
-
- *piSizeVar += (uInt)size_filename;
-
- if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
- err=UNZ_ERRNO;
- *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
- SIZEZIPLOCALHEADER + size_filename;
- *psize_local_extrafield = (uInt)size_extra_field;
-
- *piSizeVar += (uInt)size_extra_field;
-
- return err;
-}
-
-/*
- Open for reading data the current file in the zipfile.
- If there is no error and the file is opened, the return value is UNZ_OK.
-*/
-extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
- int* level, int raw, const char* password)
-{
- int err=UNZ_OK;
- uInt iSizeVar;
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
- uInt size_local_extrafield; /* size of the local extra field */
-# ifndef NOUNCRYPT
- char source[12];
-# else
- if (password != NULL)
- return UNZ_PARAMERROR;
-# endif
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return UNZ_PARAMERROR;
-
- if (s->pfile_in_zip_read != NULL)
- unzCloseCurrentFile(file);
-
- if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
- return UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
- if (pfile_in_zip_read_info==NULL)
- return UNZ_INTERNALERROR;
-
- pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
- pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
- pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
- pfile_in_zip_read_info->pos_local_extrafield=0;
- pfile_in_zip_read_info->raw=raw;
-
- if (pfile_in_zip_read_info->read_buffer==NULL)
- {
- TRYFREE(pfile_in_zip_read_info);
- return UNZ_INTERNALERROR;
- }
-
- pfile_in_zip_read_info->stream_initialised=0;
-
- if (method!=NULL)
- *method = (int)s->cur_file_info.compression_method;
-
- if (level!=NULL)
- {
- *level = 6;
- switch (s->cur_file_info.flag & 0x06)
- {
- case 6 : *level = 1; break;
- case 4 : *level = 2; break;
- case 2 : *level = 9; break;
- }
- }
-
- if ((s->cur_file_info.compression_method!=0) &&
-/* #ifdef HAVE_BZIP2 */
- (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
-/* #endif */
- (s->cur_file_info.compression_method!=Z_DEFLATED))
-
- err=UNZ_BADZIPFILE;
-
- pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
- pfile_in_zip_read_info->crc32=0;
- pfile_in_zip_read_info->total_out_64=0;
- pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
- pfile_in_zip_read_info->filestream=s->filestream;
- pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
- pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
-
- pfile_in_zip_read_info->stream.total_out = 0;
-
- if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
- {
-#ifdef HAVE_BZIP2
- pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
- pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
- pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
- pfile_in_zip_read_info->bstream.state = (voidpf)0;
-
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
- pfile_in_zip_read_info->stream.zfree = (free_func)0;
- pfile_in_zip_read_info->stream.opaque = (voidpf)0;
- pfile_in_zip_read_info->stream.next_in = (voidpf)0;
- pfile_in_zip_read_info->stream.avail_in = 0;
-
- err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
- if (err == Z_OK)
- pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
- else
- {
- TRYFREE(pfile_in_zip_read_info);
- return err;
- }
-#else
- pfile_in_zip_read_info->raw=1;
-#endif
- }
- else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
- {
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
- pfile_in_zip_read_info->stream.zfree = (free_func)0;
- pfile_in_zip_read_info->stream.opaque = (voidpf)0;
- pfile_in_zip_read_info->stream.next_in = 0;
- pfile_in_zip_read_info->stream.avail_in = 0;
-
- err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
- if (err == Z_OK)
- pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
- else
- {
- TRYFREE(pfile_in_zip_read_info);
- return err;
- }
- /* windowBits is passed < 0 to tell that there is no zlib header.
- * Note that in this case inflate *requires* an extra "dummy" byte
- * after the compressed stream in order to complete decompression and
- * return Z_STREAM_END.
- * In unzip, i don't wait absolutely Z_STREAM_END because I known the
- * size of both compressed and uncompressed data
- */
- }
- pfile_in_zip_read_info->rest_read_compressed =
- s->cur_file_info.compressed_size ;
- pfile_in_zip_read_info->rest_read_uncompressed =
- s->cur_file_info.uncompressed_size ;
-
-
- pfile_in_zip_read_info->pos_in_zipfile =
- s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
- iSizeVar;
-
- pfile_in_zip_read_info->stream.avail_in = (uInt)0;
-
- s->pfile_in_zip_read = pfile_in_zip_read_info;
- s->encrypted = 0;
-
-# ifndef NOUNCRYPT
- if (password != NULL)
- {
- int i;
- s->pcrc_32_tab = get_crc_table();
- init_keys(password,s->keys,s->pcrc_32_tab);
- if (ZSEEK64(s->z_filefunc, s->filestream,
- s->pfile_in_zip_read->pos_in_zipfile +
- s->pfile_in_zip_read->byte_before_the_zipfile,
- SEEK_SET)!=0)
- return UNZ_INTERNALERROR;
- if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
- return UNZ_INTERNALERROR;
-
- for (i = 0; i<12; i++)
- zdecode(s->keys,s->pcrc_32_tab,source[i]);
-
- s->pfile_in_zip_read->pos_in_zipfile+=12;
- s->pfile_in_zip_read->rest_read_compressed-=12;
- s->encrypted=1;
- }
-# endif
-
-
- return UNZ_OK;
-}
-
-extern int ZEXPORT unzOpenCurrentFile (unzFile file)
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
-}
-
-extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
-{
- return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
-}
-
-extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
-{
- return unzOpenCurrentFile3(file, method, level, raw, NULL);
-}
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- s=(unz64_s*)file;
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
- if (pfile_in_zip_read_info==NULL)
- return 0; //UNZ_PARAMERROR;
- return pfile_in_zip_read_info->pos_in_zipfile +
- pfile_in_zip_read_info->byte_before_the_zipfile;
-}
-
-/** Addition for GDAL : END */
-
-/*
- Read bytes from the current file.
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
-{
- int err=UNZ_OK;
- uInt iRead = 0;
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if (pfile_in_zip_read_info->read_buffer == NULL)
- return UNZ_END_OF_LIST_OF_FILE;
- if (len==0)
- return 0;
-
- pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
-
- pfile_in_zip_read_info->stream.avail_out = (uInt)len;
-
- if ((len>pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in) &&
- (pfile_in_zip_read_info->raw))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_compressed+
- pfile_in_zip_read_info->stream.avail_in;
-
- while (pfile_in_zip_read_info->stream.avail_out>0)
- {
- if ((pfile_in_zip_read_info->stream.avail_in==0) &&
- (pfile_in_zip_read_info->rest_read_compressed>0))
- {
- uInt uReadThis = UNZ_BUFSIZE;
- if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
- uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
- if (uReadThis == 0)
- return UNZ_EOF;
- if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->pos_in_zipfile +
- pfile_in_zip_read_info->byte_before_the_zipfile,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
- if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->read_buffer,
- uReadThis)!=uReadThis)
- return UNZ_ERRNO;
-
-
-# ifndef NOUNCRYPT
- if(s->encrypted)
- {
- uInt i;
- for(i=0;i<uReadThis;i++)
- pfile_in_zip_read_info->read_buffer[i] =
- zdecode(s->keys,s->pcrc_32_tab,
- pfile_in_zip_read_info->read_buffer[i]);
- }
-# endif
-
-
- pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
-
- pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
-
- pfile_in_zip_read_info->stream.next_in =
- (Bytef*)pfile_in_zip_read_info->read_buffer;
- pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
- }
-
- if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
- {
- uInt uDoCopy,i ;
-
- if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- return (iRead==0) ? UNZ_EOF : iRead;
-
- if (pfile_in_zip_read_info->stream.avail_out <
- pfile_in_zip_read_info->stream.avail_in)
- uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
- else
- uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
-
- for (i=0;i<uDoCopy;i++)
- *(pfile_in_zip_read_info->stream.next_out+i) =
- *(pfile_in_zip_read_info->stream.next_in+i);
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
-
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
- pfile_in_zip_read_info->stream.next_out,
- uDoCopy);
- pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
- pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
- pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
- pfile_in_zip_read_info->stream.next_out += uDoCopy;
- pfile_in_zip_read_info->stream.next_in += uDoCopy;
- pfile_in_zip_read_info->stream.total_out += uDoCopy;
- iRead += uDoCopy;
- }
- else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
- {
-#ifdef HAVE_BZIP2
- uLong uTotalOutBefore,uTotalOutAfter;
- const Bytef *bufBefore;
- uLong uOutThis;
-
- pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
- pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
- pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
- pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
- pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
- pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
- pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
- pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
-
- uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
- bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
-
- err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
-
- uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
- pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
- pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
- pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
- pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
- pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
- pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
- pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
- pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
-
- if (err==BZ_STREAM_END)
- return (iRead==0) ? UNZ_EOF : iRead;
- if (err!=BZ_OK)
- break;
-#endif
- } // end Z_BZIP2ED
- else
- {
- ZPOS64_T uTotalOutBefore,uTotalOutAfter;
- const Bytef *bufBefore;
- ZPOS64_T uOutThis;
- int flush=Z_SYNC_FLUSH;
-
- uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
- bufBefore = pfile_in_zip_read_info->stream.next_out;
-
- /*
- if ((pfile_in_zip_read_info->rest_read_uncompressed ==
- pfile_in_zip_read_info->stream.avail_out) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- flush = Z_FINISH;
- */
- err=inflate(&pfile_in_zip_read_info->stream,flush);
-
- if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
- err = Z_DATA_ERROR;
-
- uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
-
- pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
-
- pfile_in_zip_read_info->crc32 =
- crc32(pfile_in_zip_read_info->crc32,bufBefore,
- (uInt)(uOutThis));
-
- pfile_in_zip_read_info->rest_read_uncompressed -=
- uOutThis;
-
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
-
- if (err==Z_STREAM_END)
- return (iRead==0) ? UNZ_EOF : iRead;
- if (err!=Z_OK)
- break;
- }
- }
-
- if (err==Z_OK)
- return iRead;
- return err;
-}
-
-
-/*
- Give the current position in uncompressed data
-*/
-extern z_off_t ZEXPORT unztell (unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- return (z_off_t)pfile_in_zip_read_info->stream.total_out;
-}
-
-extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
-{
-
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return (ZPOS64_T)-1;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return (ZPOS64_T)-1;
-
- return pfile_in_zip_read_info->total_out_64;
-}
-
-
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-extern int ZEXPORT unzeof (unzFile file)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
- return 1;
- else
- return 0;
-}
-
-
-
-/*
-Read extra field from the current file (opened by unzOpenCurrentFile)
-This is the local-header version of the extra field (sometimes, there is
-more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field that can be read
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
-{
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- uInt read_now;
- ZPOS64_T size_to_read;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
- size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
- pfile_in_zip_read_info->pos_local_extrafield);
-
- if (buf==NULL)
- return (int)size_to_read;
-
- if (len>size_to_read)
- read_now = (uInt)size_to_read;
- else
- read_now = (uInt)len ;
-
- if (read_now==0)
- return 0;
-
- if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- pfile_in_zip_read_info->offset_local_extrafield +
- pfile_in_zip_read_info->pos_local_extrafield,
- ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
- pfile_in_zip_read_info->filestream,
- buf,read_now)!=read_now)
- return UNZ_ERRNO;
-
- return (int)read_now;
-}
-
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-extern int ZEXPORT unzCloseCurrentFile (unzFile file)
-{
- int err=UNZ_OK;
-
- unz64_s* s;
- file_in_zip64_read_info_s* pfile_in_zip_read_info;
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
- pfile_in_zip_read_info=s->pfile_in_zip_read;
-
- if (pfile_in_zip_read_info==NULL)
- return UNZ_PARAMERROR;
-
-
- if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
- (!pfile_in_zip_read_info->raw))
- {
- if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
- err=UNZ_CRCERROR;
- }
-
-
- TRYFREE(pfile_in_zip_read_info->read_buffer);
- pfile_in_zip_read_info->read_buffer = NULL;
- if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
- inflateEnd(&pfile_in_zip_read_info->stream);
-#ifdef HAVE_BZIP2
- else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
- BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
-#endif
-
-
- pfile_in_zip_read_info->stream_initialised = 0;
- TRYFREE(pfile_in_zip_read_info);
-
- s->pfile_in_zip_read=NULL;
-
- return err;
-}
-
-
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
-{
- unz64_s* s;
- uLong uReadThis ;
- if (file==NULL)
- return (int)UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- uReadThis = uSizeBuf;
- if (uReadThis>s->gi.size_comment)
- uReadThis = s->gi.size_comment;
-
- if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return UNZ_ERRNO;
-
- if (uReadThis>0)
- {
- *szComment='\0';
- if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
- return UNZ_ERRNO;
- }
-
- if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
- *(szComment+s->gi.size_comment)='\0';
- return (int)uReadThis;
-}
-
-/* Additions by RX '2004 */
-extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
-{
- unz64_s* s;
-
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- s=(unz64_s*)file;
- if (!s->current_file_ok)
- return 0;
- if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
- if (s->num_file==s->gi.number_entry)
- return 0;
- return s->pos_in_central_dir;
-}
-
-extern uLong ZEXPORT unzGetOffset (unzFile file)
-{
- ZPOS64_T offset64;
-
- if (file==NULL)
- return 0; //UNZ_PARAMERROR;
- offset64 = unzGetOffset64(file);
- return (uLong)offset64;
-}
-
-extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
-{
- unz64_s* s;
- int err;
-
- if (file==NULL)
- return UNZ_PARAMERROR;
- s=(unz64_s*)file;
-
- s->pos_in_central_dir = pos;
- s->num_file = s->gi.number_entry; /* hack */
- err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
- &s->cur_file_info_internal,
- NULL,0,NULL,0,NULL,0);
- s->current_file_ok = (err == UNZ_OK);
- return err;
-}
-
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
-{
- return unzSetOffset64(file,pos);
-}
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h
deleted file mode 100644
index 3c01435..0000000
--- a/contrib/minizip/unzip.h
+++ /dev/null
@@ -1,437 +0,0 @@
-/* unzip.h -- IO for uncompress .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications of Unzip for Zip64
- Copyright (C) 2007-2008 Even Rouault
-
- Modifications for Zip64 support on both zip and unzip
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- ---------------------------------------------------------------------------------
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- ---------------------------------------------------------------------------------
-
- Changes
-
- See header of unzip64.c
-
-*/
-
-#ifndef _unz64_H
-#define _unz64_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef _ZLIB_H
-#include "third_party/zlib/zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#ifdef HAVE_BZIP2
-#include "bzlib.h"
-#endif
-
-#define Z_BZIP2ED 12
-
-#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagunzFile__ { int unused; } unzFile__;
-typedef unzFile__ *unzFile;
-#else
-typedef voidp unzFile;
-#endif
-
-
-#define UNZ_OK (0)
-#define UNZ_END_OF_LIST_OF_FILE (-100)
-#define UNZ_ERRNO (Z_ERRNO)
-#define UNZ_EOF (0)
-#define UNZ_PARAMERROR (-102)
-#define UNZ_BADZIPFILE (-103)
-#define UNZ_INTERNALERROR (-104)
-#define UNZ_CRCERROR (-105)
-
-/* tm_unz contain date/time info */
-typedef struct tm_unz_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_unz;
-
-/* unz_global_info structure contain global data about the ZIPfile
- These data comes from the end of central dir */
-typedef struct unz_global_info64_s
-{
- ZPOS64_T number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info64;
-
-typedef struct unz_global_info_s
-{
- uLong number_entry; /* total number of entries in
- the central dir on this disk */
- uLong size_comment; /* size of the global comment of the zipfile */
-} unz_global_info;
-
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_info64_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- ZPOS64_T compressed_size; /* compressed size 8 bytes */
- ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info64;
-
-typedef struct unz_file_info_s
-{
- uLong version; /* version made by 2 bytes */
- uLong version_needed; /* version needed to extract 2 bytes */
- uLong flag; /* general purpose bit flag 2 bytes */
- uLong compression_method; /* compression method 2 bytes */
- uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
- uLong crc; /* crc-32 4 bytes */
- uLong compressed_size; /* compressed size 4 bytes */
- uLong uncompressed_size; /* uncompressed size 4 bytes */
- uLong size_filename; /* filename length 2 bytes */
- uLong size_file_extra; /* extra field length 2 bytes */
- uLong size_file_comment; /* file comment length 2 bytes */
-
- uLong disk_num_start; /* disk number start 2 bytes */
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-
- tm_unz tmu_date;
-} unz_file_info;
-
-extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
- const char* fileName2,
- int iCaseSensitivity));
-/*
- Compare two filename (fileName1,fileName2).
- If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
- If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
- or strcasecmp)
- If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
- (like 1 on Unix, 2 on Windows)
-*/
-
-
-extern unzFile ZEXPORT unzOpen OF((const char *path));
-extern unzFile ZEXPORT unzOpen64 OF((const void *path));
-/*
- Open a Zip file. path contain the full pathname (by example,
- on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
- "zlib/zlib113.zip".
- If the zipfile cannot be opened (file don't exist or in not valid), the
- return value is NULL.
- Else, the return value is a unzFile Handle, usable with other function
- of this unzip package.
- the "64" function take a const void* pointer, because the path is just the
- value passed to the open64_file_func callback.
- Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
- is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
- does not describe the reality
-*/
-
-
-extern unzFile ZEXPORT unzOpen2 OF((const char *path,
- zlib_filefunc_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unzOpen, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
- zlib_filefunc64_def* pzlib_filefunc_def));
-/*
- Open a Zip file, like unz64Open, but provide a set of file low level API
- for read/write the zip file (see ioapi.h)
-*/
-
-extern int ZEXPORT unzClose OF((unzFile file));
-/*
- Close a ZipFile opened with unzOpen.
- If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
- these files MUST be closed with unzCloseCurrentFile before call unzClose.
- return UNZ_OK if there is no problem. */
-
-extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
- unz_global_info *pglobal_info));
-
-extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
- unz_global_info64 *pglobal_info));
-/*
- Write info about the ZipFile in the *pglobal_info structure.
- No preparation of the structure is needed
- return UNZ_OK if there is no problem. */
-
-
-extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
- char *szComment,
- uLong uSizeBuf));
-/*
- Get the global comment string of the ZipFile, in the szComment buffer.
- uSizeBuf is the size of the szComment buffer.
- return the number of byte copied or an error code <0
-*/
-
-
-/***************************************************************************/
-/* Unzip package allow you browse the directory of the zipfile */
-
-extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the first file.
- return UNZ_OK if there is no problem
-*/
-
-extern int ZEXPORT unzGoToNextFile OF((unzFile file));
-/*
- Set the current file of the zipfile to the next file.
- return UNZ_OK if there is no problem
- return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
-*/
-
-extern int ZEXPORT unzLocateFile OF((unzFile file,
- const char *szFileName,
- int iCaseSensitivity));
-/*
- Try locate the file szFileName in the zipfile.
- For the iCaseSensitivity signification, see unzStringFileNameCompare
-
- return value :
- UNZ_OK if the file is found. It becomes the current file.
- UNZ_END_OF_LIST_OF_FILE if the file is not found
-*/
-
-
-/* ****************************************** */
-/* Ryan supplied functions */
-/* unz_file_info contain information about a file in the zipfile */
-typedef struct unz_file_pos_s
-{
- uLong pos_in_zip_directory; /* offset in zip file directory */
- uLong num_of_file; /* # of file */
-} unz_file_pos;
-
-extern int ZEXPORT unzGetFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos(
- unzFile file,
- unz_file_pos* file_pos);
-
-typedef struct unz64_file_pos_s
-{
- ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
- ZPOS64_T num_of_file; /* # of file */
-} unz64_file_pos;
-
-extern int ZEXPORT unzGetFilePos64(
- unzFile file,
- unz64_file_pos* file_pos);
-
-extern int ZEXPORT unzGoToFilePos64(
- unzFile file,
- const unz64_file_pos* file_pos);
-
-/* ****************************************** */
-
-extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
- unz_file_info64 *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-
-extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
- unz_file_info *pfile_info,
- char *szFileName,
- uLong fileNameBufferSize,
- void *extraField,
- uLong extraFieldBufferSize,
- char *szComment,
- uLong commentBufferSize));
-/*
- Get Info about the current file
- if pfile_info!=NULL, the *pfile_info structure will contain somes info about
- the current file
- if szFileName!=NULL, the filemane string will be copied in szFileName
- (fileNameBufferSize is the size of the buffer)
- if extraField!=NULL, the extra field information will be copied in extraField
- (extraFieldBufferSize is the size of the buffer).
- This is the Central-header version of the extra field
- if szComment!=NULL, the comment string of the file will be copied in szComment
- (commentBufferSize is the size of the buffer)
-*/
-
-
-/** Addition for GDAL : START */
-
-extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
-
-/** Addition for GDAL : END */
-
-
-/***************************************************************************/
-/* for reading the content of the current zipfile, you can open it, read data
- from it, and close it (you can close it before reading all the file)
- */
-
-extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
-/*
- Open for reading data the current file in the zipfile.
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
- const char* password));
-/*
- Open for reading data the current file in the zipfile.
- password is a crypting password
- If there is no error, the return value is UNZ_OK.
-*/
-
-extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
- int* method,
- int* level,
- int raw));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
- int* method,
- int* level,
- int raw,
- const char* password));
-/*
- Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
- if raw==1
- *method will receive method of compression, *level will receive level of
- compression
- note : you can set level parameter as NULL (if you did not want known level,
- but you CANNOT set method parameter as NULL
-*/
-
-
-extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
-/*
- Close the file in zip opened with unzOpenCurrentFile
- Return UNZ_CRCERROR if all the file was read but the CRC is not good
-*/
-
-extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read bytes from the current file (opened by unzOpenCurrentFile)
- buf contain buffer where data must be copied
- len the size of buf.
-
- return the number of byte copied if somes bytes are copied
- return 0 if the end of file was reached
- return <0 with error code if there is an error
- (UNZ_ERRNO for IO error, or zLib error for uncompress error)
-*/
-
-extern z_off_t ZEXPORT unztell OF((unzFile file));
-
-extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
-/*
- Give the current position in uncompressed data
-*/
-
-extern int ZEXPORT unzeof OF((unzFile file));
-/*
- return 1 if the end of file was reached, 0 elsewhere
-*/
-
-extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
- voidp buf,
- unsigned len));
-/*
- Read extra field from the current file (opened by unzOpenCurrentFile)
- This is the local-header version of the extra field (sometimes, there is
- more info in the local-header version than in the central-header)
-
- if buf==NULL, it return the size of the local extra field
-
- if buf!=NULL, len is the size of the buffer, the extra header is copied in
- buf.
- the return value is the number of bytes copied in buf, or (if <0)
- the error code
-*/
-
-/***************************************************************************/
-
-/* Get the current file offset */
-extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
-extern uLong ZEXPORT unzGetOffset (unzFile file);
-
-/* Set the current file offset */
-extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
-extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _unz64_H */
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
deleted file mode 100644
index 65c0c72..0000000
--- a/contrib/minizip/zip.c
+++ /dev/null
@@ -1,2007 +0,0 @@
-/* zip.c -- IO on .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- Changes
- Oct-2009 - Mathias Svensson - Remove old C style function prototypes
- Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
- Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
- Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
- It is used when recreting zip archive with RAW when deleting items from a zip.
- ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed.
- Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
- Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
-
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "third_party/zlib/zlib.h"
-#include "zip.h"
-
-#ifdef STDC
-# include <stddef.h>
-# include <string.h>
-# include <stdlib.h>
-#endif
-#ifdef NO_ERRNO_H
- extern int errno;
-#else
-# include <errno.h>
-#endif
-
-
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-#ifndef VERSIONMADEBY
-# define VERSIONMADEBY (0x0) /* platform depedent */
-#endif
-
-#ifndef Z_BUFSIZE
-#define Z_BUFSIZE (64*1024) //(16384)
-#endif
-
-#ifndef Z_MAXFILENAMEINZIP
-#define Z_MAXFILENAMEINZIP (256)
-#endif
-
-#ifndef ALLOC
-# define ALLOC(size) (malloc(size))
-#endif
-#ifndef TRYFREE
-# define TRYFREE(p) {if (p) free(p);}
-#endif
-
-/*
-#define SIZECENTRALDIRITEM (0x2e)
-#define SIZEZIPLOCALHEADER (0x1e)
-*/
-
-/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
-
-
-// NOT sure that this work on ALL platform
-#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
-
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END 2
-#endif
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-
-#ifndef DEF_MEM_LEVEL
-#if MAX_MEM_LEVEL >= 8
-# define DEF_MEM_LEVEL 8
-#else
-# define DEF_MEM_LEVEL MAX_MEM_LEVEL
-#endif
-#endif
-const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
-
-
-#define SIZEDATA_INDATABLOCK (4096-(4*4))
-
-#define LOCALHEADERMAGIC (0x04034b50)
-#define CENTRALHEADERMAGIC (0x02014b50)
-#define ENDHEADERMAGIC (0x06054b50)
-#define ZIP64ENDHEADERMAGIC (0x6064b50)
-#define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
-
-#define FLAG_LOCALHEADER_OFFSET (0x06)
-#define CRC_LOCALHEADER_OFFSET (0x0e)
-
-#define SIZECENTRALHEADER (0x2e) /* 46 */
-
-typedef struct linkedlist_datablock_internal_s
-{
- struct linkedlist_datablock_internal_s* next_datablock;
- uLong avail_in_this_block;
- uLong filled_in_this_block;
- uLong unused; /* for future use and alignment */
- unsigned char data[SIZEDATA_INDATABLOCK];
-} linkedlist_datablock_internal;
-
-typedef struct linkedlist_data_s
-{
- linkedlist_datablock_internal* first_block;
- linkedlist_datablock_internal* last_block;
-} linkedlist_data;
-
-
-typedef struct
-{
- z_stream stream; /* zLib stream structure for inflate */
-#ifdef HAVE_BZIP2
- bz_stream bstream; /* bzLib stream structure for bziped */
-#endif
-
- int stream_initialised; /* 1 is stream is initialised */
- uInt pos_in_buffered_data; /* last written byte in buffered_data */
-
- ZPOS64_T pos_local_header; /* offset of the local header of the file
- currenty writing */
- char* central_header; /* central header data for the current file */
- uLong size_centralExtra;
- uLong size_centralheader; /* size of the central header for cur file */
- uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
- uLong flag; /* flag of the file currently writing */
-
- int method; /* compression method of file currenty wr.*/
- int raw; /* 1 for directly writing raw data */
- Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
- uLong dosDate;
- uLong crc32;
- int encrypt;
- int zip64; /* Add ZIP64 extened information in the extra field */
- ZPOS64_T pos_zip64extrainfo;
- ZPOS64_T totalCompressedData;
- ZPOS64_T totalUncompressedData;
-#ifndef NOCRYPT
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
- const z_crc_t* pcrc_32_tab;
- int crypt_header_size;
-#endif
-} curfile64_info;
-
-typedef struct
-{
- zlib_filefunc64_32_def z_filefunc;
- voidpf filestream; /* io structore of the zipfile */
- linkedlist_data central_dir;/* datablock with central dir in construction*/
- int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
- curfile64_info ci; /* info on the file curretly writing */
-
- ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
- ZPOS64_T add_position_when_writing_offset;
- ZPOS64_T number_entry;
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- char *globalcomment;
-#endif
-
-} zip64_internal;
-
-
-#ifndef NOCRYPT
-#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-#include "crypt.h"
-#endif
-
-local linkedlist_datablock_internal* allocate_new_datablock()
-{
- linkedlist_datablock_internal* ldi;
- ldi = (linkedlist_datablock_internal*)
- ALLOC(sizeof(linkedlist_datablock_internal));
- if (ldi!=NULL)
- {
- ldi->next_datablock = NULL ;
- ldi->filled_in_this_block = 0 ;
- ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
- }
- return ldi;
-}
-
-local void free_datablock(linkedlist_datablock_internal* ldi)
-{
- while (ldi!=NULL)
- {
- linkedlist_datablock_internal* ldinext = ldi->next_datablock;
- TRYFREE(ldi);
- ldi = ldinext;
- }
-}
-
-local void init_linkedlist(linkedlist_data* ll)
-{
- ll->first_block = ll->last_block = NULL;
-}
-
-local void free_linkedlist(linkedlist_data* ll)
-{
- free_datablock(ll->first_block);
- ll->first_block = ll->last_block = NULL;
-}
-
-
-local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
-{
- linkedlist_datablock_internal* ldi;
- const unsigned char* from_copy;
-
- if (ll==NULL)
- return ZIP_INTERNALERROR;
-
- if (ll->last_block == NULL)
- {
- ll->first_block = ll->last_block = allocate_new_datablock();
- if (ll->first_block == NULL)
- return ZIP_INTERNALERROR;
- }
-
- ldi = ll->last_block;
- from_copy = (unsigned char*)buf;
-
- while (len>0)
- {
- uInt copy_this;
- uInt i;
- unsigned char* to_copy;
-
- if (ldi->avail_in_this_block==0)
- {
- ldi->next_datablock = allocate_new_datablock();
- if (ldi->next_datablock == NULL)
- return ZIP_INTERNALERROR;
- ldi = ldi->next_datablock ;
- ll->last_block = ldi;
- }
-
- if (ldi->avail_in_this_block < len)
- copy_this = (uInt)ldi->avail_in_this_block;
- else
- copy_this = (uInt)len;
-
- to_copy = &(ldi->data[ldi->filled_in_this_block]);
-
- for (i=0;i<copy_this;i++)
- *(to_copy+i)=*(from_copy+i);
-
- ldi->filled_in_this_block += copy_this;
- ldi->avail_in_this_block -= copy_this;
- from_copy += copy_this ;
- len -= copy_this;
- }
- return ZIP_OK;
-}
-
-
-
-/****************************************************************************/
-
-#ifndef NO_ADDFILEINEXISTINGZIP
-/* ===========================================================================
- Inputs a long in LSB order to the given file
- nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
-*/
-
-local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
-local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
-{
- unsigned char buf[8];
- int n;
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = (unsigned char)(x & 0xff);
- x >>= 8;
- }
- if (x != 0)
- { /* data overflow - hack for ZIP64 (X Roche) */
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = 0xff;
- }
- }
-
- if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
- return ZIP_ERRNO;
- else
- return ZIP_OK;
-}
-
-local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
-local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
-{
- unsigned char* buf=(unsigned char*)dest;
- int n;
- for (n = 0; n < nbByte; n++) {
- buf[n] = (unsigned char)(x & 0xff);
- x >>= 8;
- }
-
- if (x != 0)
- { /* data overflow - hack for ZIP64 */
- for (n = 0; n < nbByte; n++)
- {
- buf[n] = 0xff;
- }
- }
-}
-
-/****************************************************************************/
-
-
-local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
-{
- uLong year = (uLong)ptm->tm_year;
- if (year>=1980)
- year-=1980;
- else if (year>=80)
- year-=80;
- return
- (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
- ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
-}
-
-
-/****************************************************************************/
-
-local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
-
-local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
-{
- unsigned char c;
- int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
- if (err==1)
- {
- *pi = (int)c;
- return ZIP_OK;
- }
- else
- {
- if (ZERROR64(*pzlib_filefunc_def,filestream))
- return ZIP_ERRNO;
- else
- return ZIP_EOF;
- }
-}
-
-
-/* ===========================================================================
- Reads a long in LSB order from the given gz_stream. Sets
-*/
-local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
-
-local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
-
-local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
-{
- uLong x ;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (uLong)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<8;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<16;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((uLong)i)<<24;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
- return err;
-}
-
-local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
-
-
-local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
-{
- ZPOS64_T x;
- int i = 0;
- int err;
-
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x = (ZPOS64_T)i;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<8;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<16;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<24;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<32;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<40;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<48;
-
- if (err==ZIP_OK)
- err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
- x += ((ZPOS64_T)i)<<56;
-
- if (err==ZIP_OK)
- *pX = x;
- else
- *pX = 0;
-
- return err;
-}
-
-#ifndef BUFREADCOMMENT
-#define BUFREADCOMMENT (0x400)
-#endif
-/*
- Locate the Central directory of a zipfile (at the end, just before
- the global comment)
-*/
-local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-
-local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos ;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
- ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
- {
- uPosFound = uReadPos+i;
- break;
- }
-
- if (uPosFound!=0)
- break;
- }
- TRYFREE(buf);
- return uPosFound;
-}
-
-/*
-Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
-the global comment)
-*/
-local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
-
-local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
-{
- unsigned char* buf;
- ZPOS64_T uSizeFile;
- ZPOS64_T uBackRead;
- ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
- ZPOS64_T uPosFound=0;
- uLong uL;
- ZPOS64_T relativeOffset;
-
- if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
- return 0;
-
- uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
-
- if (uMaxBack>uSizeFile)
- uMaxBack = uSizeFile;
-
- buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
- if (buf==NULL)
- return 0;
-
- uBackRead = 4;
- while (uBackRead<uMaxBack)
- {
- uLong uReadSize;
- ZPOS64_T uReadPos;
- int i;
- if (uBackRead+BUFREADCOMMENT>uMaxBack)
- uBackRead = uMaxBack;
- else
- uBackRead+=BUFREADCOMMENT;
- uReadPos = uSizeFile-uBackRead ;
-
- uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
- (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
- if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- break;
-
- if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
- break;
-
- for (i=(int)uReadSize-3; (i--)>0;)
- {
- // Signature "0x07064b50" Zip64 end of central directory locater
- if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
- {
- uPosFound = uReadPos+i;
- break;
- }
- }
-
- if (uPosFound!=0)
- break;
- }
-
- TRYFREE(buf);
- if (uPosFound == 0)
- return 0;
-
- /* Zip64 end of central directory locator */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature, already checked */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
-
- /* number of the disk with the start of the zip64 end of central directory */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
- if (uL != 0)
- return 0;
-
- /* relative offset of the zip64 end of central directory record */
- if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
- return 0;
-
- /* total number of disks */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
- if (uL != 1)
- return 0;
-
- /* Goto Zip64 end of central directory record */
- if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
- return 0;
-
- /* the signature */
- if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
- return 0;
-
- if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
- return 0;
-
- return relativeOffset;
-}
-
-int LoadCentralDirectoryRecord(zip64_internal* pziinit)
-{
- int err=ZIP_OK;
- ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-
- ZPOS64_T size_central_dir; /* size of the central directory */
- ZPOS64_T offset_central_dir; /* offset of start of central directory */
- ZPOS64_T central_pos;
- uLong uL;
-
- uLong number_disk; /* number of the current dist, used for
- spaning ZIP, unsupported, always 0*/
- uLong number_disk_with_CD; /* number the the disk with central dir, used
- for spaning ZIP, unsupported, always 0*/
- ZPOS64_T number_entry;
- ZPOS64_T number_entry_CD; /* total number of entries in
- the central dir
- (same than number_entry on nospan) */
- uLong VersionMadeBy;
- uLong VersionNeeded;
- uLong size_comment;
-
- int hasZIP64Record = 0;
-
- // check first if we find a ZIP64 record
- central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
- if(central_pos > 0)
- {
- hasZIP64Record = 1;
- }
- else if(central_pos == 0)
- {
- central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
- }
-
-/* disable to allow appending to empty ZIP archive
- if (central_pos==0)
- err=ZIP_ERRNO;
-*/
-
- if(hasZIP64Record)
- {
- ZPOS64_T sizeEndOfCentralDirectory;
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- /* the signature, already checked */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* size of zip64 end of central directory record */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* version made by */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* version needed to extract */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of this disk */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central directory on this disk */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central directory */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
- err=ZIP_BADZIPFILE;
-
- /* size of the central directory */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* offset of start of central directory with respect to the
- starting disk number */
- if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- // TODO..
- // read the comment from the standard central header.
- size_comment = 0;
- }
- else
- {
- // Read End of central Directory info
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err=ZIP_ERRNO;
-
- /* the signature, already checked */
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of this disk */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* number of the disk with the start of the central directory */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
- err=ZIP_ERRNO;
-
- /* total number of entries in the central dir on this disk */
- number_entry = 0;
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- number_entry = uL;
-
- /* total number of entries in the central dir */
- number_entry_CD = 0;
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- number_entry_CD = uL;
-
- if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
- err=ZIP_BADZIPFILE;
-
- /* size of the central directory */
- size_central_dir = 0;
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- size_central_dir = uL;
-
- /* offset of start of central directory with respect to the starting disk number */
- offset_central_dir = 0;
- if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
- err=ZIP_ERRNO;
- else
- offset_central_dir = uL;
-
-
- /* zipfile global comment length */
- if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
- err=ZIP_ERRNO;
- }
-
- if ((central_pos<offset_central_dir+size_central_dir) &&
- (err==ZIP_OK))
- err=ZIP_BADZIPFILE;
-
- if (err!=ZIP_OK)
- {
- ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
- return ZIP_ERRNO;
- }
-
- if (size_comment>0)
- {
- pziinit->globalcomment = (char*)ALLOC(size_comment+1);
- if (pziinit->globalcomment)
- {
- size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
- pziinit->globalcomment[size_comment]=0;
- }
- }
-
- byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
- pziinit->add_position_when_writing_offset = byte_before_the_zipfile;
-
- {
- ZPOS64_T size_central_dir_to_read = size_central_dir;
- size_t buf_size = SIZEDATA_INDATABLOCK;
- void* buf_read = (void*)ALLOC(buf_size);
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- while ((size_central_dir_to_read>0) && (err==ZIP_OK))
- {
- ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
- if (read_this > size_central_dir_to_read)
- read_this = size_central_dir_to_read;
-
- if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
- err=ZIP_ERRNO;
-
- if (err==ZIP_OK)
- err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
-
- size_central_dir_to_read-=read_this;
- }
- TRYFREE(buf_read);
- }
- pziinit->begin_pos = byte_before_the_zipfile;
- pziinit->number_entry = number_entry_CD;
-
- if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
- err=ZIP_ERRNO;
-
- return err;
-}
-
-
-#endif /* !NO_ADDFILEINEXISTINGZIP*/
-
-
-/************************************************************/
-extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
-{
- zip64_internal ziinit;
- zip64_internal* zi;
- int err=ZIP_OK;
-
- ziinit.z_filefunc.zseek32_file = NULL;
- ziinit.z_filefunc.ztell32_file = NULL;
- if (pzlib_filefunc64_32_def==NULL)
- fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
- else
- ziinit.z_filefunc = *pzlib_filefunc64_32_def;
-
- ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
- pathname,
- (append == APPEND_STATUS_CREATE) ?
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
-
- if (ziinit.filestream == NULL)
- return NULL;
-
- if (append == APPEND_STATUS_CREATEAFTER)
- ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
-
- ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
- ziinit.in_opened_file_inzip = 0;
- ziinit.ci.stream_initialised = 0;
- ziinit.number_entry = 0;
- ziinit.add_position_when_writing_offset = 0;
- init_linkedlist(&(ziinit.central_dir));
-
-
-
- zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
- if (zi==NULL)
- {
- ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
- return NULL;
- }
-
- /* now we add file in a zipfile */
-# ifndef NO_ADDFILEINEXISTINGZIP
- ziinit.globalcomment = NULL;
- if (append == APPEND_STATUS_ADDINZIP)
- {
- // Read and Cache Central Directory Records
- err = LoadCentralDirectoryRecord(&ziinit);
- }
-
- if (globalcomment)
- {
- *globalcomment = ziinit.globalcomment;
- }
-# endif /* !NO_ADDFILEINEXISTINGZIP*/
-
- if (err != ZIP_OK)
- {
-# ifndef NO_ADDFILEINEXISTINGZIP
- TRYFREE(ziinit.globalcomment);
-# endif /* !NO_ADDFILEINEXISTINGZIP*/
- TRYFREE(zi);
- return NULL;
- }
- else
- {
- *zi = ziinit;
- return (zipFile)zi;
- }
-}
-
-extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
-{
- if (pzlib_filefunc32_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
- return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
- }
- else
- return zipOpen3(pathname, append, globalcomment, NULL);
-}
-
-extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
-{
- if (pzlib_filefunc_def != NULL)
- {
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
- return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
- }
- else
- return zipOpen3(pathname, append, globalcomment, NULL);
-}
-
-
-
-extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
-{
- return zipOpen3((const void*)pathname,append,NULL,NULL);
-}
-
-extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
-{
- return zipOpen3(pathname,append,NULL,NULL);
-}
-
-int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
-{
- /* write the local header */
- int err;
- uInt size_filename = (uInt)strlen(filename);
- uInt size_extrafield = size_extrafield_local;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
-
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
-
- // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
- }
- if (err==ZIP_OK)
- {
- if(zi->ci.zip64)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
-
- if(zi->ci.zip64)
- {
- size_extrafield += 20;
- }
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
-
- if ((err==ZIP_OK) && (size_filename > 0))
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
- err = ZIP_ERRNO;
- }
-
- if ((err==ZIP_OK) && (size_extrafield_local > 0))
- {
- if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
- err = ZIP_ERRNO;
- }
-
-
- if ((err==ZIP_OK) && (zi->ci.zip64))
- {
- // write the Zip64 extended info
- short HeaderID = 1;
- short DataSize = 16;
- ZPOS64_T CompressedSize = 0;
- ZPOS64_T UncompressedSize = 0;
-
- // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
- zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
-
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
-
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
- }
-
- return err;
-}
-
-/*
- NOTE.
- When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
- before calling this function it can be done with zipRemoveExtraInfoBlock
-
- It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
- unnecessary allocations.
- */
-extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting,
- uLong versionMadeBy, uLong flagBase, int zip64)
-{
- zip64_internal* zi;
- uInt size_filename;
- uInt size_comment;
- uInt i;
- int err = ZIP_OK;
-
-# ifdef NOCRYPT
- (crcForCrypting);
- if (password != NULL)
- return ZIP_PARAMERROR;
-# endif
-
- if (file == NULL)
- return ZIP_PARAMERROR;
-
-#ifdef HAVE_BZIP2
- if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
- return ZIP_PARAMERROR;
-#else
- if ((method!=0) && (method!=Z_DEFLATED))
- return ZIP_PARAMERROR;
-#endif
-
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 1)
- {
- err = zipCloseFileInZip (file);
- if (err != ZIP_OK)
- return err;
- }
-
- if (filename==NULL)
- filename="-";
-
- if (comment==NULL)
- size_comment = 0;
- else
- size_comment = (uInt)strlen(comment);
-
- size_filename = (uInt)strlen(filename);
-
- if (zipfi == NULL)
- zi->ci.dosDate = 0;
- else
- {
- if (zipfi->dosDate != 0)
- zi->ci.dosDate = zipfi->dosDate;
- else
- zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
- }
-
- zi->ci.flag = flagBase;
- if ((level==8) || (level==9))
- zi->ci.flag |= 2;
- if (level==2)
- zi->ci.flag |= 4;
- if (level==1)
- zi->ci.flag |= 6;
- if (password != NULL)
- zi->ci.flag |= 1;
-
- zi->ci.crc32 = 0;
- zi->ci.method = method;
- zi->ci.encrypt = 0;
- zi->ci.stream_initialised = 0;
- zi->ci.pos_in_buffered_data = 0;
- zi->ci.raw = raw;
- zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
-
- zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
- zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
-
- zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
-
- zi->ci.size_centralExtra = size_extrafield_global;
- zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
- /* version info */
- zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
- zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
- zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
- zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
- zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
- zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
- zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
- zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
- zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
- zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
- zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
-
- if (zipfi==NULL)
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
-
- if (zipfi==NULL)
- zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
-
- if(zi->ci.pos_local_header >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
- else
- zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writing_offset,4);
-
- for (i=0;i<size_filename;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
-
- for (i=0;i<size_extrafield_global;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
- *(((const char*)extrafield_global)+i);
-
- for (i=0;i<size_comment;i++)
- *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
- size_extrafield_global+i) = *(comment+i);
- if (zi->ci.central_header == NULL)
- return ZIP_INTERNALERROR;
-
- zi->ci.zip64 = zip64;
- zi->ci.totalCompressedData = 0;
- zi->ci.totalUncompressedData = 0;
- zi->ci.pos_zip64extrainfo = 0;
-
- err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
-
-#ifdef HAVE_BZIP2
- zi->ci.bstream.avail_in = (uInt)0;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- zi->ci.bstream.total_in_hi32 = 0;
- zi->ci.bstream.total_in_lo32 = 0;
- zi->ci.bstream.total_out_hi32 = 0;
- zi->ci.bstream.total_out_lo32 = 0;
-#endif
-
- zi->ci.stream.avail_in = (uInt)0;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- zi->ci.stream.total_in = 0;
- zi->ci.stream.total_out = 0;
- zi->ci.stream.data_type = Z_BINARY;
-
-#ifdef HAVE_BZIP2
- if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
-#else
- if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
-#endif
- {
- if(zi->ci.method == Z_DEFLATED)
- {
- zi->ci.stream.zalloc = (alloc_func)0;
- zi->ci.stream.zfree = (free_func)0;
- zi->ci.stream.opaque = (voidpf)0;
-
- if (windowBits>0)
- windowBits = -windowBits;
-
- err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
-
- if (err==Z_OK)
- zi->ci.stream_initialised = Z_DEFLATED;
- }
- else if(zi->ci.method == Z_BZIP2ED)
- {
-#ifdef HAVE_BZIP2
- // Init BZip stuff here
- zi->ci.bstream.bzalloc = 0;
- zi->ci.bstream.bzfree = 0;
- zi->ci.bstream.opaque = (voidpf)0;
-
- err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
- if(err == BZ_OK)
- zi->ci.stream_initialised = Z_BZIP2ED;
-#endif
- }
-
- }
-
-# ifndef NOCRYPT
- zi->ci.crypt_header_size = 0;
- if ((err==Z_OK) && (password != NULL))
- {
- unsigned char bufHead[RAND_HEAD_LEN];
- unsigned int sizeHead;
- zi->ci.encrypt = 1;
- zi->ci.pcrc_32_tab = get_crc_table();
- /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
-
- sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
- zi->ci.crypt_header_size = sizeHead;
-
- if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
- err = ZIP_ERRNO;
- }
-# endif
-
- if (err==Z_OK)
- zi->in_opened_file_inzip = 1;
- return err;
-}
-
-extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting,
- uLong versionMadeBy, uLong flagBase)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, versionMadeBy, flagBase, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, VERSIONMADEBY, 0, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw,
- int windowBits,int memLevel, int strategy,
- const char* password, uLong crcForCrypting, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- windowBits, memLevel, strategy,
- password, crcForCrypting, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, 0);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void* extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int raw, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, raw,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void*extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level, int zip64)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, 0,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, zip64);
-}
-
-extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
- const void* extrafield_local, uInt size_extrafield_local,
- const void*extrafield_global, uInt size_extrafield_global,
- const char* comment, int method, int level)
-{
- return zipOpenNewFileInZip4_64 (file, filename, zipfi,
- extrafield_local, size_extrafield_local,
- extrafield_global, size_extrafield_global,
- comment, method, level, 0,
- -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- NULL, 0, VERSIONMADEBY, 0, 0);
-}
-
-local int zip64FlushWriteBuffer(zip64_internal* zi)
-{
- int err=ZIP_OK;
-
- if (zi->ci.encrypt != 0)
- {
-#ifndef NOCRYPT
- uInt i;
- int t;
- for (i=0;i<zi->ci.pos_in_buffered_data;i++)
- zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
-#endif
- }
-
- if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
- err = ZIP_ERRNO;
-
- zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
-
-#ifdef HAVE_BZIP2
- if(zi->ci.method == Z_BZIP2ED)
- {
- zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
- zi->ci.bstream.total_in_lo32 = 0;
- zi->ci.bstream.total_in_hi32 = 0;
- }
- else
-#endif
- {
- zi->ci.totalUncompressedData += zi->ci.stream.total_in;
- zi->ci.stream.total_in = 0;
- }
-
-
- zi->ci.pos_in_buffered_data = 0;
-
- return err;
-}
-
-extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
-{
- zip64_internal* zi;
- int err=ZIP_OK;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 0)
- return ZIP_PARAMERROR;
-
- zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
-
-#ifdef HAVE_BZIP2
- if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
- {
- zi->ci.bstream.next_in = (void*)buf;
- zi->ci.bstream.avail_in = len;
- err = BZ_RUN_OK;
-
- while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
- {
- if (zi->ci.bstream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- }
-
-
- if(err != BZ_RUN_OK)
- break;
-
- if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
- uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
-// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
- err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
- }
- }
-
- if(err == BZ_RUN_OK)
- err = ZIP_OK;
- }
- else
-#endif
- {
- zi->ci.stream.next_in = (Bytef*)buf;
- zi->ci.stream.avail_in = len;
-
- while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
- {
- if (zi->ci.stream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- }
-
-
- if(err != ZIP_OK)
- break;
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- uLong uTotalOutBefore = zi->ci.stream.total_out;
- err=deflate(&zi->ci.stream, Z_NO_FLUSH);
- if(uTotalOutBefore > zi->ci.stream.total_out)
- {
- int bBreak = 0;
- bBreak++;
- }
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
- }
- else
- {
- uInt copy_this,i;
- if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
- copy_this = zi->ci.stream.avail_in;
- else
- copy_this = zi->ci.stream.avail_out;
-
- for (i = 0; i < copy_this; i++)
- *(((char*)zi->ci.stream.next_out)+i) =
- *(((const char*)zi->ci.stream.next_in)+i);
- {
- zi->ci.stream.avail_in -= copy_this;
- zi->ci.stream.avail_out-= copy_this;
- zi->ci.stream.next_in+= copy_this;
- zi->ci.stream.next_out+= copy_this;
- zi->ci.stream.total_in+= copy_this;
- zi->ci.stream.total_out+= copy_this;
- zi->ci.pos_in_buffered_data += copy_this;
- }
- }
- }// while(...)
- }
-
- return err;
-}
-
-extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
-{
- return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
-}
-
-extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
-{
- zip64_internal* zi;
- ZPOS64_T compressed_size;
- uLong invalidValue = 0xffffffff;
- short datasize = 0;
- int err=ZIP_OK;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 0)
- return ZIP_PARAMERROR;
- zi->ci.stream.avail_in = 0;
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- while (err==ZIP_OK)
- {
- uLong uTotalOutBefore;
- if (zi->ci.stream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.stream.next_out = zi->ci.buffered_data;
- }
- uTotalOutBefore = zi->ci.stream.total_out;
- err=deflate(&zi->ci.stream, Z_FINISH);
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
- }
- }
- else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
-#ifdef HAVE_BZIP2
- err = BZ_FINISH_OK;
- while (err==BZ_FINISH_OK)
- {
- uLong uTotalOutBefore;
- if (zi->ci.bstream.avail_out == 0)
- {
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
- err = ZIP_ERRNO;
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
- zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
- }
- uTotalOutBefore = zi->ci.bstream.total_out_lo32;
- err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
- if(err == BZ_STREAM_END)
- err = Z_STREAM_END;
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
- }
-
- if(err == BZ_FINISH_OK)
- err = ZIP_OK;
-#endif
- }
-
- if (err==Z_STREAM_END)
- err=ZIP_OK; /* this is normal */
-
- if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
- {
- if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
- err = ZIP_ERRNO;
- }
-
- if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
- {
- int tmp_err = deflateEnd(&zi->ci.stream);
- if (err == ZIP_OK)
- err = tmp_err;
- zi->ci.stream_initialised = 0;
- }
-#ifdef HAVE_BZIP2
- else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
- {
- int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
- if (err==ZIP_OK)
- err = tmperr;
- zi->ci.stream_initialised = 0;
- }
-#endif
-
- if (!zi->ci.raw)
- {
- crc32 = (uLong)zi->ci.crc32;
- uncompressed_size = zi->ci.totalUncompressedData;
- }
- compressed_size = zi->ci.totalCompressedData;
-
-# ifndef NOCRYPT
- compressed_size += zi->ci.crypt_header_size;
-# endif
-
- // update Current Item crc and sizes,
- if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
- {
- /*version Made by*/
- zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
- /*version needed*/
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
-
- }
-
- zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
-
-
- if(compressed_size >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
- else
- zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
-
- /// set internal file attributes field
- if (zi->ci.stream.data_type == Z_ASCII)
- zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
-
- if(uncompressed_size >= 0xffffffff)
- zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
- else
- zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
-
- // Add ZIP64 extra info field for uncompressed size
- if(uncompressed_size >= 0xffffffff)
- datasize += 8;
-
- // Add ZIP64 extra info field for compressed size
- if(compressed_size >= 0xffffffff)
- datasize += 8;
-
- // Add ZIP64 extra info field for relative offset to local file header of current file
- if(zi->ci.pos_local_header >= 0xffffffff)
- datasize += 8;
-
- if(datasize > 0)
- {
- char* p = NULL;
-
- if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
- {
- // we can not write more data to the buffer that we have room for.
- return ZIP_BADZIPFILE;
- }
-
- p = zi->ci.central_header + zi->ci.size_centralheader;
-
- // Add Extra Information Header for 'ZIP64 information'
- zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
- p += 2;
- zip64local_putValue_inmemory(p, datasize, 2); // DataSize
- p += 2;
-
- if(uncompressed_size >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, uncompressed_size, 8);
- p += 8;
- }
-
- if(compressed_size >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, compressed_size, 8);
- p += 8;
- }
-
- if(zi->ci.pos_local_header >= 0xffffffff)
- {
- zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
- p += 8;
- }
-
- // Update how much extra free space we got in the memory buffer
- // and increase the centralheader size so the new ZIP64 fields are included
- // ( 4 below is the size of HeaderID and DataSize field )
- zi->ci.size_centralExtraFree -= datasize + 4;
- zi->ci.size_centralheader += datasize + 4;
-
- // Update the extra info size field
- zi->ci.size_centralExtra += datasize + 4;
- zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
- }
-
- if (err==ZIP_OK)
- err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
-
- free(zi->ci.central_header);
-
- if (err==ZIP_OK)
- {
- // Update the LocalFileHeader with the new values.
-
- ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
-
- if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
-
- if (err==ZIP_OK)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
-
- if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff )
- {
- if(zi->ci.pos_zip64extrainfo > 0)
- {
- // Update the size in the ZIP64 extended field.
- if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
-
- if (err==ZIP_OK) /* compressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
-
- if (err==ZIP_OK) /* uncompressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
- }
- else
- err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
- }
- else
- {
- if (err==ZIP_OK) /* compressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
-
- if (err==ZIP_OK) /* uncompressed size, unknown */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
- }
-
- if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
- err = ZIP_ERRNO;
- }
-
- zi->number_entry ++;
- zi->in_opened_file_inzip = 0;
-
- return err;
-}
-
-extern int ZEXPORT zipCloseFileInZip (zipFile file)
-{
- return zipCloseFileInZipRaw (file,0,0);
-}
-
-int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
-{
- int err = ZIP_OK;
- ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
-
- /*num disks*/
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- /*relative offset*/
- if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
-
- /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
-
- return err;
-}
-
-int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
-{
- int err = ZIP_OK;
-
- uLong Zip64DataSize = 44;
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
-
- if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
-
- if (err==ZIP_OK) /* version made by */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
-
- if (err==ZIP_OK) /* version needed */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
-
- if (err==ZIP_OK) /* number of this disk */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
-
- if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
-
- if (err==ZIP_OK) /* total number of entries in the central dir */
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
-
- if (err==ZIP_OK) /* size of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
-
- if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
- {
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
- }
- return err;
-}
-int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
-{
- int err = ZIP_OK;
-
- /*signature*/
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
-
- if (err==ZIP_OK) /* number of this disk */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
- if (err==ZIP_OK) /* number of the disk with the start of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
-
- if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
- {
- {
- if(zi->number_entry >= 0xFFFF)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
- }
- }
-
- if (err==ZIP_OK) /* total number of entries in the central dir */
- {
- if(zi->number_entry >= 0xFFFF)
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
- }
-
- if (err==ZIP_OK) /* size of the central directory */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
-
- if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
- {
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
- if(pos >= 0xffffffff)
- {
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
- }
- else
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writing_offset),4);
- }
-
- return err;
-}
-
-int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
-{
- int err = ZIP_OK;
- uInt size_global_comment = 0;
-
- if(global_comment != NULL)
- size_global_comment = (uInt)strlen(global_comment);
-
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
-
- if (err == ZIP_OK && size_global_comment > 0)
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
- err = ZIP_ERRNO;
- }
- return err;
-}
-
-extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
-{
- zip64_internal* zi;
- int err = 0;
- uLong size_centraldir = 0;
- ZPOS64_T centraldir_pos_inzip;
- ZPOS64_T pos;
-
- if (file == NULL)
- return ZIP_PARAMERROR;
-
- zi = (zip64_internal*)file;
-
- if (zi->in_opened_file_inzip == 1)
- {
- err = zipCloseFileInZip (file);
- }
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- if (global_comment==NULL)
- global_comment = zi->globalcomment;
-#endif
-
- centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
-
- if (err==ZIP_OK)
- {
- linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
- while (ldi!=NULL)
- {
- if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
- {
- if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
- err = ZIP_ERRNO;
- }
-
- size_centraldir += ldi->filled_in_this_block;
- ldi = ldi->next_datablock;
- }
- }
- free_linkedlist(&(zi->central_dir));
-
- pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
- if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
- {
- ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
- Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
-
- Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
- }
-
- if (err==ZIP_OK)
- err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
-
- if(err == ZIP_OK)
- err = Write_GlobalComment(zi, global_comment);
-
- if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
- if (err == ZIP_OK)
- err = ZIP_ERRNO;
-
-#ifndef NO_ADDFILEINEXISTINGZIP
- TRYFREE(zi->globalcomment);
-#endif
- TRYFREE(zi);
-
- return err;
-}
-
-extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
-{
- char* p = pData;
- int size = 0;
- char* pNewHeader;
- char* pTmp;
- short header;
- short dataSize;
-
- int retVal = ZIP_OK;
-
- if(pData == NULL || *dataLen < 4)
- return ZIP_PARAMERROR;
-
- pNewHeader = (char*)ALLOC(*dataLen);
- pTmp = pNewHeader;
-
- while(p < (pData + *dataLen))
- {
- header = *(short*)p;
- dataSize = *(((short*)p)+1);
-
- if( header == sHeader ) // Header found.
- {
- p += dataSize + 4; // skip it. do not copy to temp buffer
- }
- else
- {
- // Extra Info block should not be removed, So copy it to the temp buffer.
- memcpy(pTmp, p, dataSize + 4);
- p += dataSize + 4;
- size += dataSize + 4;
- }
-
- }
-
- if(size < *dataLen)
- {
- // clean old extra info block.
- memset(pData,0, *dataLen);
-
- // copy the new extra info block over the old
- if(size > 0)
- memcpy(pData, pNewHeader, size);
-
- // set the new extra info size
- *dataLen = size;
-
- retVal = ZIP_OK;
- }
- else
- retVal = ZIP_ERRNO;
-
- TRYFREE(pNewHeader);
-
- return retVal;
-}
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h
deleted file mode 100644
index 8c06c0a..0000000
--- a/contrib/minizip/zip.h
+++ /dev/null
@@ -1,362 +0,0 @@
-/* zip.h -- IO on .zip files using zlib
- Version 1.1, February 14h, 2010
- part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
-
- Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
-
- Modifications for Zip64 support
- Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
-
- For more info read MiniZip_info.txt
-
- ---------------------------------------------------------------------------
-
- Condition of use and distribution are the same than zlib :
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-
- ---------------------------------------------------------------------------
-
- Changes
-
- See header of zip.h
-
-*/
-
-#ifndef _zip12_H
-#define _zip12_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//#define HAVE_BZIP2
-
-#ifndef _ZLIB_H
-#include "third_party/zlib/zlib.h"
-#endif
-
-#ifndef _ZLIBIOAPI_H
-#include "ioapi.h"
-#endif
-
-#ifdef HAVE_BZIP2
-#include "bzlib.h"
-#endif
-
-#define Z_BZIP2ED 12
-
-#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
-/* like the STRICT of WIN32, we define a pointer that cannot be converted
- from (void*) without cast */
-typedef struct TagzipFile__ { int unused; } zipFile__;
-typedef zipFile__ *zipFile;
-#else
-typedef voidp zipFile;
-#endif
-
-#define ZIP_OK (0)
-#define ZIP_EOF (0)
-#define ZIP_ERRNO (Z_ERRNO)
-#define ZIP_PARAMERROR (-102)
-#define ZIP_BADZIPFILE (-103)
-#define ZIP_INTERNALERROR (-104)
-
-#ifndef DEF_MEM_LEVEL
-# if MAX_MEM_LEVEL >= 8
-# define DEF_MEM_LEVEL 8
-# else
-# define DEF_MEM_LEVEL MAX_MEM_LEVEL
-# endif
-#endif
-/* default memLevel */
-
-/* tm_zip contain date/time info */
-typedef struct tm_zip_s
-{
- uInt tm_sec; /* seconds after the minute - [0,59] */
- uInt tm_min; /* minutes after the hour - [0,59] */
- uInt tm_hour; /* hours since midnight - [0,23] */
- uInt tm_mday; /* day of the month - [1,31] */
- uInt tm_mon; /* months since January - [0,11] */
- uInt tm_year; /* years - [1980..2044] */
-} tm_zip;
-
-typedef struct
-{
- tm_zip tmz_date; /* date in understandable format */
- uLong dosDate; /* if dos_date == 0, tmu_date is used */
-/* uLong flag; */ /* general purpose bit flag 2 bytes */
-
- uLong internal_fa; /* internal file attributes 2 bytes */
- uLong external_fa; /* external file attributes 4 bytes */
-} zip_fileinfo;
-
-typedef const char* zipcharpc;
-
-
-#define APPEND_STATUS_CREATE (0)
-#define APPEND_STATUS_CREATEAFTER (1)
-#define APPEND_STATUS_ADDINZIP (2)
-
-extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
-extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
-/*
- Create a zipfile.
- pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
- an Unix computer "zlib/zlib113.zip".
- if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
- will be created at the end of the file.
- (useful if the file contain a self extractor code)
- if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
- add files in existing zip (be sure you don't add file that doesn't exist)
- If the zipfile cannot be opened, the return value is NULL.
- Else, the return value is a zipFile Handle, usable with other function
- of this zip package.
-*/
-
-/* Note : there is no delete function into a zipfile.
- If you want delete file into a zipfile, you must open a zipfile, and create another
- Of couse, you can use RAW reading and writing to copy the file you did not want delte
-*/
-
-extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
- int append,
- zipcharpc* globalcomment,
- zlib_filefunc_def* pzlib_filefunc_def));
-
-extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
- int append,
- zipcharpc* globalcomment,
- zlib_filefunc64_def* pzlib_filefunc_def));
-
-extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level));
-
-extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int zip64));
-
-/*
- Open a file in the ZIP for writing.
- filename : the filename in zip (if NULL, '-' without quote will be used
- *zipfi contain supplemental information
- if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
- contains the extrafield data the the local header
- if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
- contains the extrafield data the the local header
- if comment != NULL, comment contain the comment string
- method contain the compression method (0 for store, Z_DEFLATED for deflate)
- level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
- zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
- this MUST be '1' if the uncompressed size is >= 0xffffffff.
-
-*/
-
-
-extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw));
-
-
-extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int zip64));
-/*
- Same than zipOpenNewFileInZip, except if raw=1, we write raw file
- */
-
-extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting));
-
-extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- int zip64
- ));
-
-/*
- Same than zipOpenNewFileInZip2, except
- windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
- password : crypting password (NULL for no crypting)
- crcForCrypting : crc of file to compress (needed for crypting)
- */
-
-extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- uLong versionMadeBy,
- uLong flagBase
- ));
-
-
-extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
- const char* filename,
- const zip_fileinfo* zipfi,
- const void* extrafield_local,
- uInt size_extrafield_local,
- const void* extrafield_global,
- uInt size_extrafield_global,
- const char* comment,
- int method,
- int level,
- int raw,
- int windowBits,
- int memLevel,
- int strategy,
- const char* password,
- uLong crcForCrypting,
- uLong versionMadeBy,
- uLong flagBase,
- int zip64
- ));
-/*
- Same than zipOpenNewFileInZip4, except
- versionMadeBy : value for Version made by field
- flag : value for flag field (compression level info will be added)
- */
-
-
-extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
- const void* buf,
- unsigned len));
-/*
- Write data in the zipfile
-*/
-
-extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
-/*
- Close the current file in the zipfile
-*/
-
-extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
- uLong uncompressed_size,
- uLong crc32));
-
-extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
- ZPOS64_T uncompressed_size,
- uLong crc32));
-
-/*
- Close the current file in the zipfile, for file opened with
- parameter raw=1 in zipOpenNewFileInZip2
- uncompressed_size and crc32 are value for the uncompressed size
-*/
-
-extern int ZEXPORT zipClose OF((zipFile file,
- const char* global_comment));
-/*
- Close the zipfile
-*/
-
-
-extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
-/*
- zipRemoveExtraInfoBlock - Added by Mathias Svensson
-
- Remove extra information block from a extra information data for the local file header or central directory header
-
- It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
-
- 0x0001 is the signature header for the ZIP64 extra information blocks
-
- usage.
- Remove ZIP64 Extra information from a central director extra field data
- zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
-
- Remove ZIP64 Extra information from a Local File Header extra field data
- zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
-*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _zip64_H */
diff --git a/contrib/optimizations/chunkcopy.h b/contrib/optimizations/chunkcopy.h
deleted file mode 100644
index 9c0b7cb..0000000
--- a/contrib/optimizations/chunkcopy.h
+++ /dev/null
@@ -1,477 +0,0 @@
-/* chunkcopy.h -- fast chunk copy and set operations
- * Copyright (C) 2017 ARM, Inc.
- * Copyright 2017 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#ifndef CHUNKCOPY_H
-#define CHUNKCOPY_H
-
-#include <stdint.h>
-#include "zutil.h"
-
-#define Z_STATIC_ASSERT(name, assert) typedef char name[(assert) ? 1 : -1]
-
-#if __STDC_VERSION__ >= 199901L
-#define Z_RESTRICT restrict
-#else
-#define Z_RESTRICT
-#endif
-
-#if defined(__clang__) || defined(__GNUC__) || defined(__llvm__)
-#define Z_BUILTIN_MEMCPY __builtin_memcpy
-#else
-#define Z_BUILTIN_MEMCPY zmemcpy
-#endif
-
-#if defined(INFLATE_CHUNK_SIMD_NEON)
-#include <arm_neon.h>
-typedef uint8x16_t z_vec128i_t;
-#elif defined(INFLATE_CHUNK_SIMD_SSE2)
-#include <emmintrin.h>
-typedef __m128i z_vec128i_t;
-#else
-#error chunkcopy.h inflate chunk SIMD is not defined for your build target
-#endif
-
-/*
- * chunk copy type: the z_vec128i_t type size should be exactly 128-bits
- * and equal to CHUNKCOPY_CHUNK_SIZE.
- */
-#define CHUNKCOPY_CHUNK_SIZE sizeof(z_vec128i_t)
-
-Z_STATIC_ASSERT(vector_128_bits_wide,
- CHUNKCOPY_CHUNK_SIZE == sizeof(int8_t) * 16);
-
-/*
- * Ask the compiler to perform a wide, unaligned load with a machine
- * instruction appropriate for the z_vec128i_t type.
- */
-static inline z_vec128i_t loadchunk(
- const unsigned char FAR* s) {
- z_vec128i_t v;
- Z_BUILTIN_MEMCPY(&v, s, sizeof(v));
- return v;
-}
-
-/*
- * Ask the compiler to perform a wide, unaligned store with a machine
- * instruction appropriate for the z_vec128i_t type.
- */
-static inline void storechunk(
- unsigned char FAR* d,
- const z_vec128i_t v) {
- Z_BUILTIN_MEMCPY(d, &v, sizeof(v));
-}
-
-/*
- * Perform a memcpy-like operation, assuming that length is non-zero and that
- * it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if
- * the length is shorter than this.
- *
- * It also guarantees that it will properly unroll the data if the distance
- * between `out` and `from` is at least CHUNKCOPY_CHUNK_SIZE, which we rely on
- * in chunkcopy_relaxed().
- *
- * Aside from better memory bus utilisation, this means that short copies
- * (CHUNKCOPY_CHUNK_SIZE bytes or fewer) will fall straight through the loop
- * without iteration, which will hopefully make the branch prediction more
- * reliable.
- */
-static inline unsigned char FAR* chunkcopy_core(
- unsigned char FAR* out,
- const unsigned char FAR* from,
- unsigned len) {
- const int bump = (--len % CHUNKCOPY_CHUNK_SIZE) + 1;
- storechunk(out, loadchunk(from));
- out += bump;
- from += bump;
- len /= CHUNKCOPY_CHUNK_SIZE;
- while (len-- > 0) {
- storechunk(out, loadchunk(from));
- out += CHUNKCOPY_CHUNK_SIZE;
- from += CHUNKCOPY_CHUNK_SIZE;
- }
- return out;
-}
-
-/*
- * Like chunkcopy_core(), but avoid writing beyond of legal output.
- *
- * Accepts an additional pointer to the end of safe output. A generic safe
- * copy would use (out + len), but it's normally the case that the end of the
- * output buffer is beyond the end of the current copy, and this can still be
- * exploited.
- */
-static inline unsigned char FAR* chunkcopy_core_safe(
- unsigned char FAR* out,
- const unsigned char FAR* from,
- unsigned len,
- unsigned char FAR* limit) {
- Assert(out + len <= limit, "chunk copy exceeds safety limit");
- if ((limit - out) < (ptrdiff_t)CHUNKCOPY_CHUNK_SIZE) {
- const unsigned char FAR* Z_RESTRICT rfrom = from;
- Assert((uintptr_t)out - (uintptr_t)from >= len,
- "invalid restrict in chunkcopy_core_safe");
- Assert((uintptr_t)from - (uintptr_t)out >= len,
- "invalid restrict in chunkcopy_core_safe");
- if (len & 8) {
- Z_BUILTIN_MEMCPY(out, rfrom, 8);
- out += 8;
- rfrom += 8;
- }
- if (len & 4) {
- Z_BUILTIN_MEMCPY(out, rfrom, 4);
- out += 4;
- rfrom += 4;
- }
- if (len & 2) {
- Z_BUILTIN_MEMCPY(out, rfrom, 2);
- out += 2;
- rfrom += 2;
- }
- if (len & 1) {
- *out++ = *rfrom++;
- }
- return out;
- }
- return chunkcopy_core(out, from, len);
-}
-
-/*
- * Perform short copies until distance can be rewritten as being at least
- * CHUNKCOPY_CHUNK_SIZE.
- *
- * Assumes it's OK to overwrite at least the first 2*CHUNKCOPY_CHUNK_SIZE
- * bytes of output even if the copy is shorter than this. This assumption
- * holds within zlib inflate_fast(), which starts every iteration with at
- * least 258 bytes of output space available (258 being the maximum length
- * output from a single token; see inffast.c).
- */
-static inline unsigned char FAR* chunkunroll_relaxed(
- unsigned char FAR* out,
- unsigned FAR* dist,
- unsigned FAR* len) {
- const unsigned char FAR* from = out - *dist;
- while (*dist < *len && *dist < CHUNKCOPY_CHUNK_SIZE) {
- storechunk(out, loadchunk(from));
- out += *dist;
- *len -= *dist;
- *dist += *dist;
- }
- return out;
-}
-
-#if defined(INFLATE_CHUNK_SIMD_NEON)
-/*
- * v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
- * every 64-bit component of the 128-bit result (64-bit int splat).
- */
-static inline z_vec128i_t v_load64_dup(const void* src) {
- return vcombine_u8(vld1_u8(src), vld1_u8(src));
-}
-
-/*
- * v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
- * every 32-bit component of the 128-bit result (32-bit int splat).
- */
-static inline z_vec128i_t v_load32_dup(const void* src) {
- int32_t i32;
- Z_BUILTIN_MEMCPY(&i32, src, sizeof(i32));
- return vreinterpretq_u8_s32(vdupq_n_s32(i32));
-}
-
-/*
- * v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
- * every 16-bit component of the 128-bit result (16-bit int splat).
- */
-static inline z_vec128i_t v_load16_dup(const void* src) {
- int16_t i16;
- Z_BUILTIN_MEMCPY(&i16, src, sizeof(i16));
- return vreinterpretq_u8_s16(vdupq_n_s16(i16));
-}
-
-/*
- * v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
- * component of the 128-bit result (8-bit int splat).
- */
-static inline z_vec128i_t v_load8_dup(const void* src) {
- return vld1q_dup_u8((const uint8_t*)src);
-}
-
-/*
- * v_store_128(): store the 128-bit vec in a memory destination (that might
- * not be 16-byte aligned) void* out.
- */
-static inline void v_store_128(void* out, const z_vec128i_t vec) {
- vst1q_u8(out, vec);
-}
-
-#elif defined(INFLATE_CHUNK_SIMD_SSE2)
-/*
- * v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
- * every 64-bit component of the 128-bit result (64-bit int splat).
- */
-static inline z_vec128i_t v_load64_dup(const void* src) {
- int64_t i64;
- Z_BUILTIN_MEMCPY(&i64, src, sizeof(i64));
- return _mm_set1_epi64x(i64);
-}
-
-/*
- * v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
- * every 32-bit component of the 128-bit result (32-bit int splat).
- */
-static inline z_vec128i_t v_load32_dup(const void* src) {
- int32_t i32;
- Z_BUILTIN_MEMCPY(&i32, src, sizeof(i32));
- return _mm_set1_epi32(i32);
-}
-
-/*
- * v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
- * every 16-bit component of the 128-bit result (16-bit int splat).
- */
-static inline z_vec128i_t v_load16_dup(const void* src) {
- int16_t i16;
- Z_BUILTIN_MEMCPY(&i16, src, sizeof(i16));
- return _mm_set1_epi16(i16);
-}
-
-/*
- * v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
- * component of the 128-bit result (8-bit int splat).
- */
-static inline z_vec128i_t v_load8_dup(const void* src) {
- return _mm_set1_epi8(*(const char*)src);
-}
-
-/*
- * v_store_128(): store the 128-bit vec in a memory destination (that might
- * not be 16-byte aligned) void* out.
- */
-static inline void v_store_128(void* out, const z_vec128i_t vec) {
- _mm_storeu_si128((__m128i*)out, vec);
-}
-#endif
-
-/*
- * Perform an overlapping copy which behaves as a memset() operation, but
- * supporting periods other than one, and assume that length is non-zero and
- * that it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE*3 bytes of output
- * even if the length is shorter than this.
- */
-static inline unsigned char FAR* chunkset_core(
- unsigned char FAR* out,
- unsigned period,
- unsigned len) {
- z_vec128i_t v;
- const int bump = ((len - 1) % sizeof(v)) + 1;
-
- switch (period) {
- case 1:
- v = v_load8_dup(out - 1);
- v_store_128(out, v);
- out += bump;
- len -= bump;
- while (len > 0) {
- v_store_128(out, v);
- out += sizeof(v);
- len -= sizeof(v);
- }
- return out;
- case 2:
- v = v_load16_dup(out - 2);
- v_store_128(out, v);
- out += bump;
- len -= bump;
- if (len > 0) {
- v = v_load16_dup(out - 2);
- do {
- v_store_128(out, v);
- out += sizeof(v);
- len -= sizeof(v);
- } while (len > 0);
- }
- return out;
- case 4:
- v = v_load32_dup(out - 4);
- v_store_128(out, v);
- out += bump;
- len -= bump;
- if (len > 0) {
- v = v_load32_dup(out - 4);
- do {
- v_store_128(out, v);
- out += sizeof(v);
- len -= sizeof(v);
- } while (len > 0);
- }
- return out;
- case 8:
- v = v_load64_dup(out - 8);
- v_store_128(out, v);
- out += bump;
- len -= bump;
- if (len > 0) {
- v = v_load64_dup(out - 8);
- do {
- v_store_128(out, v);
- out += sizeof(v);
- len -= sizeof(v);
- } while (len > 0);
- }
- return out;
- }
- out = chunkunroll_relaxed(out, &period, &len);
- return chunkcopy_core(out, out - period, len);
-}
-
-/*
- * Perform a memcpy-like operation, but assume that length is non-zero and that
- * it's OK to overwrite at least CHUNKCOPY_CHUNK_SIZE bytes of output even if
- * the length is shorter than this.
- *
- * Unlike chunkcopy_core() above, no guarantee is made regarding the behaviour
- * of overlapping buffers, regardless of the distance between the pointers.
- * This is reflected in the `restrict`-qualified pointers, allowing the
- * compiler to re-order loads and stores.
- */
-static inline unsigned char FAR* chunkcopy_relaxed(
- unsigned char FAR* Z_RESTRICT out,
- const unsigned char FAR* Z_RESTRICT from,
- unsigned len) {
- Assert((uintptr_t)out - (uintptr_t)from >= len,
- "invalid restrict in chunkcopy_relaxed");
- Assert((uintptr_t)from - (uintptr_t)out >= len,
- "invalid restrict in chunkcopy_relaxed");
- return chunkcopy_core(out, from, len);
-}
-
-/*
- * Like chunkcopy_relaxed(), but avoid writing beyond of legal output.
- *
- * Unlike chunkcopy_core_safe() above, no guarantee is made regarding the
- * behaviour of overlapping buffers, regardless of the distance between the
- * pointers. This is reflected in the `restrict`-qualified pointers, allowing
- * the compiler to re-order loads and stores.
- *
- * Accepts an additional pointer to the end of safe output. A generic safe
- * copy would use (out + len), but it's normally the case that the end of the
- * output buffer is beyond the end of the current copy, and this can still be
- * exploited.
- */
-static inline unsigned char FAR* chunkcopy_safe(
- unsigned char FAR* out,
- const unsigned char FAR* Z_RESTRICT from,
- unsigned len,
- unsigned char FAR* limit) {
- Assert(out + len <= limit, "chunk copy exceeds safety limit");
- Assert((uintptr_t)out - (uintptr_t)from >= len,
- "invalid restrict in chunkcopy_safe");
- Assert((uintptr_t)from - (uintptr_t)out >= len,
- "invalid restrict in chunkcopy_safe");
-
- return chunkcopy_core_safe(out, from, len, limit);
-}
-
-/*
- * Perform chunky copy within the same buffer, where the source and destination
- * may potentially overlap.
- *
- * Assumes that len > 0 on entry, and that it's safe to write at least
- * CHUNKCOPY_CHUNK_SIZE*3 bytes to the output.
- */
-static inline unsigned char FAR* chunkcopy_lapped_relaxed(
- unsigned char FAR* out,
- unsigned dist,
- unsigned len) {
- if (dist < len && dist < CHUNKCOPY_CHUNK_SIZE) {
- return chunkset_core(out, dist, len);
- }
- return chunkcopy_core(out, out - dist, len);
-}
-
-/*
- * Behave like chunkcopy_lapped_relaxed(), but avoid writing beyond of legal
- * output.
- *
- * Accepts an additional pointer to the end of safe output. A generic safe
- * copy would use (out + len), but it's normally the case that the end of the
- * output buffer is beyond the end of the current copy, and this can still be
- * exploited.
- */
-static inline unsigned char FAR* chunkcopy_lapped_safe(
- unsigned char FAR* out,
- unsigned dist,
- unsigned len,
- unsigned char FAR* limit) {
- Assert(out + len <= limit, "chunk copy exceeds safety limit");
- if ((limit - out) < (ptrdiff_t)(3 * CHUNKCOPY_CHUNK_SIZE)) {
- /* TODO(cavalcantii): try harder to optimise this */
- while (len-- > 0) {
- *out = *(out - dist);
- out++;
- }
- return out;
- }
- return chunkcopy_lapped_relaxed(out, dist, len);
-}
-
-/* TODO(cavalcanti): see crbug.com/1110083. */
-static inline unsigned char FAR* chunkcopy_safe_ugly(unsigned char FAR* out,
- unsigned dist,
- unsigned len,
- unsigned char FAR* limit) {
-#if defined(__GNUC__) && !defined(__clang__)
- /* Speed is the same as using chunkcopy_safe
- w/ GCC on ARM (tested gcc 6.3 and 7.5) and avoids
- undefined behavior.
- */
- return chunkcopy_core_safe(out, out - dist, len, limit);
-#elif defined(__clang__) && defined(ARMV8_OS_ANDROID) && !defined(__aarch64__)
- /* Seems to perform better on 32bit (i.e. Android). */
- return chunkcopy_core_safe(out, out - dist, len, limit);
-#else
- /* Seems to perform better on 64bit. */
- return chunkcopy_lapped_safe(out, dist, len, limit);
-#endif
-}
-
-/*
- * The chunk-copy code above deals with writing the decoded DEFLATE data to
- * the output with SIMD methods to increase decode speed. Reading the input
- * to the DEFLATE decoder with a wide, SIMD method can also increase decode
- * speed. This option is supported on little endian machines, and reads the
- * input data in 64-bit (8 byte) chunks.
- */
-
-#ifdef INFLATE_CHUNK_READ_64LE
-/*
- * Buffer the input in a uint64_t (8 bytes) in the wide input reading case.
- */
-typedef uint64_t inflate_holder_t;
-
-/*
- * Ask the compiler to perform a wide, unaligned load of a uint64_t using a
- * machine instruction appropriate for the uint64_t type.
- */
-static inline inflate_holder_t read64le(const unsigned char FAR *in) {
- inflate_holder_t input;
- Z_BUILTIN_MEMCPY(&input, in, sizeof(input));
- return input;
-}
-#else
-/*
- * Otherwise, buffer the input bits using zlib's default input buffer type.
- */
-typedef unsigned long inflate_holder_t;
-
-#endif /* INFLATE_CHUNK_READ_64LE */
-
-#undef Z_STATIC_ASSERT
-#undef Z_RESTRICT
-#undef Z_BUILTIN_MEMCPY
-
-#endif /* CHUNKCOPY_H */
diff --git a/contrib/optimizations/inffast_chunk.c b/contrib/optimizations/inffast_chunk.c
deleted file mode 100644
index 4bacbc4..0000000
--- a/contrib/optimizations/inffast_chunk.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/* inffast_chunk.c -- fast decoding
- * Copyright (C) 1995-2017 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "contrib/optimizations/inffast_chunk.h"
-#include "contrib/optimizations/chunkcopy.h"
-
-#ifdef ASMINF
-# pragma message("Assembler code may have bugs -- use at your own risk")
-#else
-
-/*
- Decode literal, length, and distance codes and write out the resulting
- literal and match bytes until either not enough input or output is
- available, an end-of-block is encountered, or a data error is encountered.
- When large enough input and output buffers are supplied to inflate(), for
- example, a 16K input buffer and a 64K output buffer, more than 95% of the
- inflate() execution time is spent in this routine.
-
- Entry assumptions:
-
- state->mode == LEN
- strm->avail_in >= INFLATE_FAST_MIN_INPUT (6 or 8 bytes)
- strm->avail_out >= INFLATE_FAST_MIN_OUTPUT (258 bytes)
- start >= strm->avail_out
- state->bits < 8
- (state->hold >> state->bits) == 0
- strm->next_out[0..strm->avail_out] does not overlap with
- strm->next_in[0..strm->avail_in]
- strm->state->window is allocated with an additional
- CHUNKCOPY_CHUNK_SIZE-1 bytes of padding beyond strm->state->wsize
-
- On return, state->mode is one of:
-
- LEN -- ran out of enough output space or enough available input
- TYPE -- reached end of block code, inflate() to interpret next block
- BAD -- error in block data
-
- Notes:
-
- INFLATE_FAST_MIN_INPUT: 6 or 8 bytes
-
- - The maximum input bits used by a length/distance pair is 15 bits for the
- length code, 5 bits for the length extra, 15 bits for the distance code,
- and 13 bits for the distance extra. This totals 48 bits, or six bytes.
- Therefore if strm->avail_in >= 6, then there is enough input to avoid
- checking for available input while decoding.
-
- - The wide input data reading option reads 64 input bits at a time. Thus,
- if strm->avail_in >= 8, then there is enough input to avoid checking for
- available input while decoding. Reading consumes the input with:
-
- hold |= read64le(in) << bits;
- in += 6;
- bits += 48;
-
- reporting 6 bytes of new input because |bits| is 0..15 (2 bytes rounded
- up, worst case) and 6 bytes is enough to decode as noted above. At exit,
- hold &= (1U << bits) - 1 drops excess input to keep the invariant:
-
- (state->hold >> state->bits) == 0
-
- INFLATE_FAST_MIN_OUTPUT: 258 bytes
-
- - The maximum bytes that a single length/distance pair can output is 258
- bytes, which is the maximum length that can be coded. inflate_fast()
- requires strm->avail_out >= 258 for each loop to avoid checking for
- available output space while decoding.
- */
-void ZLIB_INTERNAL inflate_fast_chunk_(strm, start)
-z_streamp strm;
-unsigned start; /* inflate()'s starting value for strm->avail_out */
-{
- struct inflate_state FAR *state;
- z_const unsigned char FAR *in; /* local strm->next_in */
- z_const unsigned char FAR *last; /* have enough input while in < last */
- unsigned char FAR *out; /* local strm->next_out */
- unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
- unsigned char FAR *end; /* while out < end, enough space available */
- unsigned char FAR *limit; /* safety limit for chunky copies */
-#ifdef INFLATE_STRICT
- unsigned dmax; /* maximum distance from zlib header */
-#endif
- unsigned wsize; /* window size or zero if not using window */
- unsigned whave; /* valid bytes in the window */
- unsigned wnext; /* window write index */
- unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
- inflate_holder_t hold; /* local strm->hold */
- unsigned bits; /* local strm->bits */
- code const FAR *lcode; /* local strm->lencode */
- code const FAR *dcode; /* local strm->distcode */
- unsigned lmask; /* mask for first level of length codes */
- unsigned dmask; /* mask for first level of distance codes */
- code here; /* retrieved table entry */
- unsigned op; /* code bits, operation, extra bits, or */
- /* window position, window bytes to copy */
- unsigned len; /* match length, unused bytes */
- unsigned dist; /* match distance */
- unsigned char FAR *from; /* where to copy match from */
-
- /* copy state to local variables */
- state = (struct inflate_state FAR *)strm->state;
- in = strm->next_in;
- last = in + (strm->avail_in - (INFLATE_FAST_MIN_INPUT - 1));
- out = strm->next_out;
- beg = out - (start - strm->avail_out);
- end = out + (strm->avail_out - (INFLATE_FAST_MIN_OUTPUT - 1));
- limit = out + strm->avail_out;
-#ifdef INFLATE_STRICT
- dmax = state->dmax;
-#endif
- wsize = state->wsize;
- whave = state->whave;
- wnext = (state->wnext == 0 && whave >= wsize) ? wsize : state->wnext;
- window = state->window;
- hold = state->hold;
- bits = state->bits;
- lcode = state->lencode;
- dcode = state->distcode;
- lmask = (1U << state->lenbits) - 1;
- dmask = (1U << state->distbits) - 1;
-
- /* decode literals and length/distances until end-of-block or not enough
- input data or output space */
- do {
- if (bits < 15) {
-#ifdef INFLATE_CHUNK_READ_64LE
- hold |= read64le(in) << bits;
- in += 6;
- bits += 48;
-#else
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
-#endif
- }
- here = lcode[hold & lmask];
- dolen:
- op = (unsigned)(here.bits);
- hold >>= op;
- bits -= op;
- op = (unsigned)(here.op);
- if (op == 0) { /* literal */
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
- *out++ = (unsigned char)(here.val);
- }
- else if (op & 16) { /* length base */
- len = (unsigned)(here.val);
- op &= 15; /* number of extra bits */
- if (op) {
- if (bits < op) {
-#ifdef INFLATE_CHUNK_READ_64LE
- hold |= read64le(in) << bits;
- in += 6;
- bits += 48;
-#else
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
-#endif
- }
- len += (unsigned)hold & ((1U << op) - 1);
- hold >>= op;
- bits -= op;
- }
- Tracevv((stderr, "inflate: length %u\n", len));
- if (bits < 15) {
-#ifdef INFLATE_CHUNK_READ_64LE
- hold |= read64le(in) << bits;
- in += 6;
- bits += 48;
-#else
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
-#endif
- }
- here = dcode[hold & dmask];
- dodist:
- op = (unsigned)(here.bits);
- hold >>= op;
- bits -= op;
- op = (unsigned)(here.op);
- if (op & 16) { /* distance base */
- dist = (unsigned)(here.val);
- op &= 15; /* number of extra bits */
- if (bits < op) {
-#ifdef INFLATE_CHUNK_READ_64LE
- hold |= read64le(in) << bits;
- in += 6;
- bits += 48;
-#else
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
- if (bits < op) {
- hold += (unsigned long)(*in++) << bits;
- bits += 8;
- }
-#endif
- }
- dist += (unsigned)hold & ((1U << op) - 1);
-#ifdef INFLATE_STRICT
- if (dist > dmax) {
- strm->msg = (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#endif
- hold >>= op;
- bits -= op;
- Tracevv((stderr, "inflate: distance %u\n", dist));
- op = (unsigned)(out - beg); /* max distance in output */
- if (dist > op) { /* see if copy from window */
- op = dist - op; /* distance back in window */
- if (op > whave) {
- if (state->sane) {
- strm->msg =
- (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- if (len <= op - whave) {
- do {
- *out++ = 0;
- } while (--len);
- continue;
- }
- len -= op - whave;
- do {
- *out++ = 0;
- } while (--op > whave);
- if (op == 0) {
- from = out - dist;
- do {
- *out++ = *from++;
- } while (--len);
- continue;
- }
-#endif
- }
- from = window;
- if (wnext >= op) { /* contiguous in window */
- from += wnext - op;
- }
- else { /* wrap around window */
- op -= wnext;
- from += wsize - op;
- if (op < len) { /* some from end of window */
- len -= op;
- out = chunkcopy_safe(out, from, op, limit);
- from = window; /* more from start of window */
- op = wnext;
- /* This (rare) case can create a situation where
- the first chunkcopy below must be checked.
- */
- }
- }
- if (op < len) { /* still need some from output */
- out = chunkcopy_safe(out, from, op, limit);
- len -= op;
- /* When dist is small the amount of data that can be
- copied from the window is also small, and progress
- towards the dangerous end of the output buffer is
- also small. This means that for trivial memsets and
- for chunkunroll_relaxed() a safety check is
- unnecessary. However, these conditions may not be
- entered at all, and in that case it's possible that
- the main copy is near the end.
- */
- out = chunkunroll_relaxed(out, &dist, &len);
- out = chunkcopy_safe_ugly(out, dist, len, limit);
- } else {
- /* from points to window, so there is no risk of
- overlapping pointers requiring memset-like behaviour
- */
- out = chunkcopy_safe(out, from, len, limit);
- }
- }
- else {
- /* Whole reference is in range of current output. No
- range checks are necessary because we start with room
- for at least 258 bytes of output, so unroll and roundoff
- operations can write beyond `out+len` so long as they
- stay within 258 bytes of `out`.
- */
- out = chunkcopy_lapped_relaxed(out, dist, len);
- }
- }
- else if ((op & 64) == 0) { /* 2nd level distance code */
- here = dcode[here.val + (hold & ((1U << op) - 1))];
- goto dodist;
- }
- else {
- strm->msg = (char *)"invalid distance code";
- state->mode = BAD;
- break;
- }
- }
- else if ((op & 64) == 0) { /* 2nd level length code */
- here = lcode[here.val + (hold & ((1U << op) - 1))];
- goto dolen;
- }
- else if (op & 32) { /* end-of-block */
- Tracevv((stderr, "inflate: end of block\n"));
- state->mode = TYPE;
- break;
- }
- else {
- strm->msg = (char *)"invalid literal/length code";
- state->mode = BAD;
- break;
- }
- } while (in < last && out < end);
-
- /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
- len = bits >> 3;
- in -= len;
- bits -= len << 3;
- hold &= (1U << bits) - 1;
-
- /* update state and return */
- strm->next_in = in;
- strm->next_out = out;
- strm->avail_in = (unsigned)(in < last ?
- (INFLATE_FAST_MIN_INPUT - 1) + (last - in) :
- (INFLATE_FAST_MIN_INPUT - 1) - (in - last));
- strm->avail_out = (unsigned)(out < end ?
- (INFLATE_FAST_MIN_OUTPUT - 1) + (end - out) :
- (INFLATE_FAST_MIN_OUTPUT - 1) - (out - end));
- state->hold = hold;
- state->bits = bits;
-
- Assert((state->hold >> state->bits) == 0, "invalid input data state");
- return;
-}
-
-/*
- inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
- - Using bit fields for code structure
- - Different op definition to avoid & for extra bits (do & for table bits)
- - Three separate decoding do-loops for direct, window, and wnext == 0
- - Special case for distance > 1 copies to do overlapped load and store copy
- - Explicit branch predictions (based on measured branch probabilities)
- - Deferring match copy and interspersed it with decoding subsequent codes
- - Swapping literal/length else
- - Swapping window/direct else
- - Larger unrolled copy loops (three is about right)
- - Moving len -= 3 statement into middle of loop
- */
-
-#endif /* !ASMINF */
diff --git a/contrib/optimizations/inffast_chunk.h b/contrib/optimizations/inffast_chunk.h
deleted file mode 100644
index 39c771b..0000000
--- a/contrib/optimizations/inffast_chunk.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* inffast_chunk.h -- header to use inffast_chunk.c
- * Copyright (C) 1995-2003, 2010 Mark Adler
- * Copyright (C) 2017 ARM, Inc.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* WARNING: this file should *not* be used by applications. It is
- part of the implementation of the compression library and is
- subject to change. Applications should only use zlib.h.
- */
-
-#include "inffast.h"
-
-/* INFLATE_FAST_MIN_INPUT: the minimum number of input bytes needed so that
- we can safely call inflate_fast() with only one up-front bounds check. One
- length/distance code pair (15 bits for the length code, 5 bits for length
- extra, 15 bits for the distance code, 13 bits for distance extra) requires
- reading up to 48 input bits (6 bytes). The wide input data reading option
- requires a little endian machine, and reads 64 input bits (8 bytes).
-*/
-#ifdef INFLATE_CHUNK_READ_64LE
-#undef INFLATE_FAST_MIN_INPUT
-#define INFLATE_FAST_MIN_INPUT 8
-#endif
-
-void ZLIB_INTERNAL inflate_fast_chunk_ OF((z_streamp strm, unsigned start));
diff --git a/contrib/optimizations/inflate.c b/contrib/optimizations/inflate.c
deleted file mode 100644
index 81d558b..0000000
--- a/contrib/optimizations/inflate.c
+++ /dev/null
@@ -1,1583 +0,0 @@
-/* inflate.c -- zlib decompression
- * Copyright (C) 1995-2016 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/*
- * Change history:
- *
- * 1.2.beta0 24 Nov 2002
- * - First version -- complete rewrite of inflate to simplify code, avoid
- * creation of window when not needed, minimize use of window when it is
- * needed, make inffast.c even faster, implement gzip decoding, and to
- * improve code readability and style over the previous zlib inflate code
- *
- * 1.2.beta1 25 Nov 2002
- * - Use pointers for available input and output checking in inffast.c
- * - Remove input and output counters in inffast.c
- * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
- * - Remove unnecessary second byte pull from length extra in inffast.c
- * - Unroll direct copy to three copies per loop in inffast.c
- *
- * 1.2.beta2 4 Dec 2002
- * - Change external routine names to reduce potential conflicts
- * - Correct filename to inffixed.h for fixed tables in inflate.c
- * - Make hbuf[] unsigned char to match parameter type in inflate.c
- * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
- * to avoid negation problem on Alphas (64 bit) in inflate.c
- *
- * 1.2.beta3 22 Dec 2002
- * - Add comments on state->bits assertion in inffast.c
- * - Add comments on op field in inftrees.h
- * - Fix bug in reuse of allocated window after inflateReset()
- * - Remove bit fields--back to byte structure for speed
- * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
- * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
- * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
- * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
- * - Use local copies of stream next and avail values, as well as local bit
- * buffer and bit count in inflate()--for speed when inflate_fast() not used
- *
- * 1.2.beta4 1 Jan 2003
- * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
- * - Move a comment on output buffer sizes from inffast.c to inflate.c
- * - Add comments in inffast.c to introduce the inflate_fast() routine
- * - Rearrange window copies in inflate_fast() for speed and simplification
- * - Unroll last copy for window match in inflate_fast()
- * - Use local copies of window variables in inflate_fast() for speed
- * - Pull out common wnext == 0 case for speed in inflate_fast()
- * - Make op and len in inflate_fast() unsigned for consistency
- * - Add FAR to lcode and dcode declarations in inflate_fast()
- * - Simplified bad distance check in inflate_fast()
- * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
- * source file infback.c to provide a call-back interface to inflate for
- * programs like gzip and unzip -- uses window as output buffer to avoid
- * window copying
- *
- * 1.2.beta5 1 Jan 2003
- * - Improved inflateBack() interface to allow the caller to provide initial
- * input in strm.
- * - Fixed stored blocks bug in inflateBack()
- *
- * 1.2.beta6 4 Jan 2003
- * - Added comments in inffast.c on effectiveness of POSTINC
- * - Typecasting all around to reduce compiler warnings
- * - Changed loops from while (1) or do {} while (1) to for (;;), again to
- * make compilers happy
- * - Changed type of window in inflateBackInit() to unsigned char *
- *
- * 1.2.beta7 27 Jan 2003
- * - Changed many types to unsigned or unsigned short to avoid warnings
- * - Added inflateCopy() function
- *
- * 1.2.0 9 Mar 2003
- * - Changed inflateBack() interface to provide separate opaque descriptors
- * for the in() and out() functions
- * - Changed inflateBack() argument and in_func typedef to swap the length
- * and buffer address return values for the input function
- * - Check next_in and next_out for Z_NULL on entry to inflate()
- *
- * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
- */
-
-#include "zutil.h"
-#include "inftrees.h"
-#include "inflate.h"
-#include "contrib/optimizations/inffast_chunk.h"
-#include "contrib/optimizations/chunkcopy.h"
-
-#ifdef MAKEFIXED
-# ifndef BUILDFIXED
-# define BUILDFIXED
-# endif
-#endif
-
-/* function prototypes */
-local int inflateStateCheck OF((z_streamp strm));
-local void fixedtables OF((struct inflate_state FAR *state));
-local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
- unsigned copy));
-#ifdef BUILDFIXED
- void makefixed OF((void));
-#endif
-local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
- unsigned len));
-
-local int inflateStateCheck(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
- if (strm == Z_NULL ||
- strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
- return 1;
- state = (struct inflate_state FAR *)strm->state;
- if (state == Z_NULL || state->strm != strm ||
- state->mode < HEAD || state->mode > SYNC)
- return 1;
- return 0;
-}
-
-int ZEXPORT inflateResetKeep(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- strm->total_in = strm->total_out = state->total = 0;
- strm->msg = Z_NULL;
- if (state->wrap) /* to support ill-conceived Java test suite */
- strm->adler = state->wrap & 1;
- state->mode = HEAD;
- state->last = 0;
- state->havedict = 0;
- state->dmax = 32768U;
- state->head = Z_NULL;
- state->hold = 0;
- state->bits = 0;
- state->lencode = state->distcode = state->next = state->codes;
- state->sane = 1;
- state->back = -1;
- Tracev((stderr, "inflate: reset\n"));
- return Z_OK;
-}
-
-int ZEXPORT inflateReset(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- state->wsize = 0;
- state->whave = 0;
- state->wnext = 0;
- return inflateResetKeep(strm);
-}
-
-int ZEXPORT inflateReset2(strm, windowBits)
-z_streamp strm;
-int windowBits;
-{
- int wrap;
- struct inflate_state FAR *state;
-
- /* get the state */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
-
- /* extract wrap request from windowBits parameter */
- if (windowBits < 0) {
- wrap = 0;
- windowBits = -windowBits;
- }
- else {
- wrap = (windowBits >> 4) + 5;
-#ifdef GUNZIP
- if (windowBits < 48)
- windowBits &= 15;
-#endif
- }
-
- /* set number of window bits, free window if different */
- if (windowBits && (windowBits < 8 || windowBits > 15))
- return Z_STREAM_ERROR;
- if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
- ZFREE(strm, state->window);
- state->window = Z_NULL;
- }
-
- /* update state and reset the rest of it */
- state->wrap = wrap;
- state->wbits = (unsigned)windowBits;
- return inflateReset(strm);
-}
-
-int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
-z_streamp strm;
-int windowBits;
-const char *version;
-int stream_size;
-{
- int ret;
- struct inflate_state FAR *state;
-
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
- stream_size != (int)(sizeof(z_stream)))
- return Z_VERSION_ERROR;
- if (strm == Z_NULL) return Z_STREAM_ERROR;
- strm->msg = Z_NULL; /* in case we return an error */
- if (strm->zalloc == (alloc_func)0) {
-#ifdef Z_SOLO
- return Z_STREAM_ERROR;
-#else
- strm->zalloc = zcalloc;
- strm->opaque = (voidpf)0;
-#endif
- }
- if (strm->zfree == (free_func)0)
-#ifdef Z_SOLO
- return Z_STREAM_ERROR;
-#else
- strm->zfree = zcfree;
-#endif
- state = (struct inflate_state FAR *)
- ZALLOC(strm, 1, sizeof(struct inflate_state));
- if (state == Z_NULL) return Z_MEM_ERROR;
- Tracev((stderr, "inflate: allocated\n"));
- strm->state = (struct internal_state FAR *)state;
- state->strm = strm;
- state->window = Z_NULL;
- state->mode = HEAD; /* to pass state test in inflateReset2() */
- state->check = 1L; /* 1L is the result of adler32() zero length data */
- ret = inflateReset2(strm, windowBits);
- if (ret != Z_OK) {
- ZFREE(strm, state);
- strm->state = Z_NULL;
- }
- return ret;
-}
-
-int ZEXPORT inflateInit_(strm, version, stream_size)
-z_streamp strm;
-const char *version;
-int stream_size;
-{
- return inflateInit2_(strm, DEF_WBITS, version, stream_size);
-}
-
-int ZEXPORT inflatePrime(strm, bits, value)
-z_streamp strm;
-int bits;
-int value;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (bits < 0) {
- state->hold = 0;
- state->bits = 0;
- return Z_OK;
- }
- if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
- value &= (1L << bits) - 1;
- state->hold += (unsigned)value << state->bits;
- state->bits += (uInt)bits;
- return Z_OK;
-}
-
-/*
- Return state with length and distance decoding tables and index sizes set to
- fixed code decoding. Normally this returns fixed tables from inffixed.h.
- If BUILDFIXED is defined, then instead this routine builds the tables the
- first time it's called, and returns those tables the first time and
- thereafter. This reduces the size of the code by about 2K bytes, in
- exchange for a little execution time. However, BUILDFIXED should not be
- used for threaded applications, since the rewriting of the tables and virgin
- may not be thread-safe.
- */
-local void fixedtables(state)
-struct inflate_state FAR *state;
-{
-#ifdef BUILDFIXED
- static int virgin = 1;
- static code *lenfix, *distfix;
- static code fixed[544];
-
- /* build fixed huffman tables if first call (may not be thread safe) */
- if (virgin) {
- unsigned sym, bits;
- static code *next;
-
- /* literal/length table */
- sym = 0;
- while (sym < 144) state->lens[sym++] = 8;
- while (sym < 256) state->lens[sym++] = 9;
- while (sym < 280) state->lens[sym++] = 7;
- while (sym < 288) state->lens[sym++] = 8;
- next = fixed;
- lenfix = next;
- bits = 9;
- inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
- /* distance table */
- sym = 0;
- while (sym < 32) state->lens[sym++] = 5;
- distfix = next;
- bits = 5;
- inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
- /* do this just once */
- virgin = 0;
- }
-#else /* !BUILDFIXED */
-# include "inffixed.h"
-#endif /* BUILDFIXED */
- state->lencode = lenfix;
- state->lenbits = 9;
- state->distcode = distfix;
- state->distbits = 5;
-}
-
-#ifdef MAKEFIXED
-#include <stdio.h>
-
-/*
- Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
- defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
- those tables to stdout, which would be piped to inffixed.h. A small program
- can simply call makefixed to do this:
-
- void makefixed(void);
-
- int main(void)
- {
- makefixed();
- return 0;
- }
-
- Then that can be linked with zlib built with MAKEFIXED defined and run:
-
- a.out > inffixed.h
- */
-void makefixed()
-{
- unsigned low, size;
- struct inflate_state state;
-
- fixedtables(&state);
- puts(" /* inffixed.h -- table for decoding fixed codes");
- puts(" * Generated automatically by makefixed().");
- puts(" */");
- puts("");
- puts(" /* WARNING: this file should *not* be used by applications.");
- puts(" It is part of the implementation of this library and is");
- puts(" subject to change. Applications should only use zlib.h.");
- puts(" */");
- puts("");
- size = 1U << 9;
- printf(" static const code lenfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 7) == 0) printf("\n ");
- printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
- state.lencode[low].bits, state.lencode[low].val);
- if (++low == size) break;
- putchar(',');
- }
- puts("\n };");
- size = 1U << 5;
- printf("\n static const code distfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 6) == 0) printf("\n ");
- printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
- state.distcode[low].val);
- if (++low == size) break;
- putchar(',');
- }
- puts("\n };");
-}
-#endif /* MAKEFIXED */
-
-/*
- Update the window with the last wsize (normally 32K) bytes written before
- returning. If window does not exist yet, create it. This is only called
- when a window is already in use, or when output has been written during this
- inflate call, but the end of the deflate stream has not been reached yet.
- It is also called to create a window for dictionary data when a dictionary
- is loaded.
-
- Providing output buffers larger than 32K to inflate() should provide a speed
- advantage, since only the last 32K of output is copied to the sliding window
- upon return from inflate(), and since all distances after the first 32K of
- output will fall in the output data, making match copies simpler and faster.
- The advantage may be dependent on the size of the processor's data caches.
- */
-local int updatewindow(strm, end, copy)
-z_streamp strm;
-const Bytef *end;
-unsigned copy;
-{
- struct inflate_state FAR *state;
- unsigned dist;
-
- state = (struct inflate_state FAR *)strm->state;
-
- /* if it hasn't been done already, allocate space for the window */
- if (state->window == Z_NULL) {
- unsigned wsize = 1U << state->wbits;
- state->window = (unsigned char FAR *)
- ZALLOC(strm, wsize + CHUNKCOPY_CHUNK_SIZE,
- sizeof(unsigned char));
- if (state->window == Z_NULL) return 1;
-#ifdef INFLATE_CLEAR_UNUSED_UNDEFINED
- /* Copies from the overflow portion of this buffer are undefined and
- may cause analysis tools to raise a warning if we don't initialize
- it. However, this undefined data overwrites other undefined data
- and is subsequently either overwritten or left deliberately
- undefined at the end of decode; so there's really no point.
- */
- zmemzero(state->window + wsize, CHUNKCOPY_CHUNK_SIZE);
-#endif
- }
-
- /* if window not in use yet, initialize */
- if (state->wsize == 0) {
- state->wsize = 1U << state->wbits;
- state->wnext = 0;
- state->whave = 0;
- }
-
- /* copy state->wsize or less output bytes into the circular window */
- if (copy >= state->wsize) {
- zmemcpy(state->window, end - state->wsize, state->wsize);
- state->wnext = 0;
- state->whave = state->wsize;
- }
- else {
- dist = state->wsize - state->wnext;
- if (dist > copy) dist = copy;
- zmemcpy(state->window + state->wnext, end - copy, dist);
- copy -= dist;
- if (copy) {
- zmemcpy(state->window, end - copy, copy);
- state->wnext = copy;
- state->whave = state->wsize;
- }
- else {
- state->wnext += dist;
- if (state->wnext == state->wsize) state->wnext = 0;
- if (state->whave < state->wsize) state->whave += dist;
- }
- }
- return 0;
-}
-
-/* Macros for inflate(): */
-
-/* check function to use adler32() for zlib or crc32() for gzip */
-#ifdef GUNZIP
-# define UPDATE(check, buf, len) \
- (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
-#else
-# define UPDATE(check, buf, len) adler32(check, buf, len)
-#endif
-
-/* check macros for header crc */
-#ifdef GUNZIP
-# define CRC2(check, word) \
- do { \
- hbuf[0] = (unsigned char)(word); \
- hbuf[1] = (unsigned char)((word) >> 8); \
- check = crc32(check, hbuf, 2); \
- } while (0)
-
-# define CRC4(check, word) \
- do { \
- hbuf[0] = (unsigned char)(word); \
- hbuf[1] = (unsigned char)((word) >> 8); \
- hbuf[2] = (unsigned char)((word) >> 16); \
- hbuf[3] = (unsigned char)((word) >> 24); \
- check = crc32(check, hbuf, 4); \
- } while (0)
-#endif
-
-/* Load registers with state in inflate() for speed */
-#define LOAD() \
- do { \
- put = strm->next_out; \
- left = strm->avail_out; \
- next = strm->next_in; \
- have = strm->avail_in; \
- hold = state->hold; \
- bits = state->bits; \
- } while (0)
-
-/* Restore state from registers in inflate() */
-#define RESTORE() \
- do { \
- strm->next_out = put; \
- strm->avail_out = left; \
- strm->next_in = next; \
- strm->avail_in = have; \
- state->hold = hold; \
- state->bits = bits; \
- } while (0)
-
-/* Clear the input bit accumulator */
-#define INITBITS() \
- do { \
- hold = 0; \
- bits = 0; \
- } while (0)
-
-/* Get a byte of input into the bit accumulator, or return from inflate()
- if there is no input available. */
-#define PULLBYTE() \
- do { \
- if (have == 0) goto inf_leave; \
- have--; \
- hold += (unsigned long)(*next++) << bits; \
- bits += 8; \
- } while (0)
-
-/* Assure that there are at least n bits in the bit accumulator. If there is
- not enough available input to do that, then return from inflate(). */
-#define NEEDBITS(n) \
- do { \
- while (bits < (unsigned)(n)) \
- PULLBYTE(); \
- } while (0)
-
-/* Return the low n bits of the bit accumulator (n < 16) */
-#define BITS(n) \
- ((unsigned)hold & ((1U << (n)) - 1))
-
-/* Remove n bits from the bit accumulator */
-#define DROPBITS(n) \
- do { \
- hold >>= (n); \
- bits -= (unsigned)(n); \
- } while (0)
-
-/* Remove zero to seven bits as needed to go to a byte boundary */
-#define BYTEBITS() \
- do { \
- hold >>= bits & 7; \
- bits -= bits & 7; \
- } while (0)
-
-/*
- inflate() uses a state machine to process as much input data and generate as
- much output data as possible before returning. The state machine is
- structured roughly as follows:
-
- for (;;) switch (state) {
- ...
- case STATEn:
- if (not enough input data or output space to make progress)
- return;
- ... make progress ...
- state = STATEm;
- break;
- ...
- }
-
- so when inflate() is called again, the same case is attempted again, and
- if the appropriate resources are provided, the machine proceeds to the
- next state. The NEEDBITS() macro is usually the way the state evaluates
- whether it can proceed or should return. NEEDBITS() does the return if
- the requested bits are not available. The typical use of the BITS macros
- is:
-
- NEEDBITS(n);
- ... do something with BITS(n) ...
- DROPBITS(n);
-
- where NEEDBITS(n) either returns from inflate() if there isn't enough
- input left to load n bits into the accumulator, or it continues. BITS(n)
- gives the low n bits in the accumulator. When done, DROPBITS(n) drops
- the low n bits off the accumulator. INITBITS() clears the accumulator
- and sets the number of available bits to zero. BYTEBITS() discards just
- enough bits to put the accumulator on a byte boundary. After BYTEBITS()
- and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
-
- NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
- if there is no input available. The decoding of variable length codes uses
- PULLBYTE() directly in order to pull just enough bytes to decode the next
- code, and no more.
-
- Some states loop until they get enough input, making sure that enough
- state information is maintained to continue the loop where it left off
- if NEEDBITS() returns in the loop. For example, want, need, and keep
- would all have to actually be part of the saved state in case NEEDBITS()
- returns:
-
- case STATEw:
- while (want < need) {
- NEEDBITS(n);
- keep[want++] = BITS(n);
- DROPBITS(n);
- }
- state = STATEx;
- case STATEx:
-
- As shown above, if the next state is also the next case, then the break
- is omitted.
-
- A state may also return if there is not enough output space available to
- complete that state. Those states are copying stored data, writing a
- literal byte, and copying a matching string.
-
- When returning, a "goto inf_leave" is used to update the total counters,
- update the check value, and determine whether any progress has been made
- during that inflate() call in order to return the proper return code.
- Progress is defined as a change in either strm->avail_in or strm->avail_out.
- When there is a window, goto inf_leave will update the window with the last
- output written. If a goto inf_leave occurs in the middle of decompression
- and there is no window currently, goto inf_leave will create one and copy
- output to the window for the next call of inflate().
-
- In this implementation, the flush parameter of inflate() only affects the
- return code (per zlib.h). inflate() always writes as much as possible to
- strm->next_out, given the space available and the provided input--the effect
- documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
- the allocation of and copying into a sliding window until necessary, which
- provides the effect documented in zlib.h for Z_FINISH when the entire input
- stream available. So the only thing the flush parameter actually does is:
- when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
- will return Z_BUF_ERROR if it has not reached the end of the stream.
- */
-
-int ZEXPORT inflate(strm, flush)
-z_streamp strm;
-int flush;
-{
- struct inflate_state FAR *state;
- z_const unsigned char FAR *next; /* next input */
- unsigned char FAR *put; /* next output */
- unsigned have, left; /* available input and output */
- unsigned long hold; /* bit buffer */
- unsigned bits; /* bits in bit buffer */
- unsigned in, out; /* save starting available input and output */
- unsigned copy; /* number of stored or match bytes to copy */
- unsigned char FAR *from; /* where to copy match bytes from */
- code here; /* current decoding table entry */
- code last; /* parent table entry */
- unsigned len; /* length to copy for repeats, bits to drop */
- int ret; /* return code */
-#ifdef GUNZIP
- unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
-#endif
- static const unsigned short order[19] = /* permutation of code lengths */
- {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
- if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
- (strm->next_in == Z_NULL && strm->avail_in != 0))
- return Z_STREAM_ERROR;
-
- state = (struct inflate_state FAR *)strm->state;
- if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
- LOAD();
- in = have;
- out = left;
- ret = Z_OK;
- for (;;)
- switch (state->mode) {
- case HEAD:
- if (state->wrap == 0) {
- state->mode = TYPEDO;
- break;
- }
- NEEDBITS(16);
-#ifdef GUNZIP
- if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
- if (state->wbits == 0)
- state->wbits = 15;
- state->check = crc32(0L, Z_NULL, 0);
- CRC2(state->check, hold);
- INITBITS();
- state->mode = FLAGS;
- break;
- }
- state->flags = 0; /* expect zlib header */
- if (state->head != Z_NULL)
- state->head->done = -1;
- if (!(state->wrap & 1) || /* check if zlib header allowed */
-#else
- if (
-#endif
- ((BITS(8) << 8) + (hold >> 8)) % 31) {
- strm->msg = (char *)"incorrect header check";
- state->mode = BAD;
- break;
- }
- if (BITS(4) != Z_DEFLATED) {
- strm->msg = (char *)"unknown compression method";
- state->mode = BAD;
- break;
- }
- DROPBITS(4);
- len = BITS(4) + 8;
- if (state->wbits == 0)
- state->wbits = len;
- if (len > 15 || len > state->wbits) {
- strm->msg = (char *)"invalid window size";
- state->mode = BAD;
- break;
- }
- state->dmax = 1U << len;
- Tracev((stderr, "inflate: zlib header ok\n"));
- strm->adler = state->check = adler32(0L, Z_NULL, 0);
- state->mode = hold & 0x200 ? DICTID : TYPE;
- INITBITS();
- break;
-#ifdef GUNZIP
- case FLAGS:
- NEEDBITS(16);
- state->flags = (int)(hold);
- if ((state->flags & 0xff) != Z_DEFLATED) {
- strm->msg = (char *)"unknown compression method";
- state->mode = BAD;
- break;
- }
- if (state->flags & 0xe000) {
- strm->msg = (char *)"unknown header flags set";
- state->mode = BAD;
- break;
- }
- if (state->head != Z_NULL)
- state->head->text = (int)((hold >> 8) & 1);
- if ((state->flags & 0x0200) && (state->wrap & 4))
- CRC2(state->check, hold);
- INITBITS();
- state->mode = TIME;
- case TIME:
- NEEDBITS(32);
- if (state->head != Z_NULL)
- state->head->time = hold;
- if ((state->flags & 0x0200) && (state->wrap & 4))
- CRC4(state->check, hold);
- INITBITS();
- state->mode = OS;
- case OS:
- NEEDBITS(16);
- if (state->head != Z_NULL) {
- state->head->xflags = (int)(hold & 0xff);
- state->head->os = (int)(hold >> 8);
- }
- if ((state->flags & 0x0200) && (state->wrap & 4))
- CRC2(state->check, hold);
- INITBITS();
- state->mode = EXLEN;
- case EXLEN:
- if (state->flags & 0x0400) {
- NEEDBITS(16);
- state->length = (unsigned)(hold);
- if (state->head != Z_NULL)
- state->head->extra_len = (unsigned)hold;
- if ((state->flags & 0x0200) && (state->wrap & 4))
- CRC2(state->check, hold);
- INITBITS();
- }
- else if (state->head != Z_NULL)
- state->head->extra = Z_NULL;
- state->mode = EXTRA;
- case EXTRA:
- if (state->flags & 0x0400) {
- copy = state->length;
- if (copy > have) copy = have;
- if (copy) {
- if (state->head != Z_NULL &&
- state->head->extra != Z_NULL) {
- len = state->head->extra_len - state->length;
- zmemcpy(state->head->extra + len, next,
- len + copy > state->head->extra_max ?
- state->head->extra_max - len : copy);
- }
- if ((state->flags & 0x0200) && (state->wrap & 4))
- state->check = crc32(state->check, next, copy);
- have -= copy;
- next += copy;
- state->length -= copy;
- }
- if (state->length) goto inf_leave;
- }
- state->length = 0;
- state->mode = NAME;
- case NAME:
- if (state->flags & 0x0800) {
- if (have == 0) goto inf_leave;
- copy = 0;
- do {
- len = (unsigned)(next[copy++]);
- if (state->head != Z_NULL &&
- state->head->name != Z_NULL &&
- state->length < state->head->name_max)
- state->head->name[state->length++] = (Bytef)len;
- } while (len && copy < have);
- if ((state->flags & 0x0200) && (state->wrap & 4))
- state->check = crc32(state->check, next, copy);
- have -= copy;
- next += copy;
- if (len) goto inf_leave;
- }
- else if (state->head != Z_NULL)
- state->head->name = Z_NULL;
- state->length = 0;
- state->mode = COMMENT;
- case COMMENT:
- if (state->flags & 0x1000) {
- if (have == 0) goto inf_leave;
- copy = 0;
- do {
- len = (unsigned)(next[copy++]);
- if (state->head != Z_NULL &&
- state->head->comment != Z_NULL &&
- state->length < state->head->comm_max)
- state->head->comment[state->length++] = (Bytef)len;
- } while (len && copy < have);
- if ((state->flags & 0x0200) && (state->wrap & 4))
- state->check = crc32(state->check, next, copy);
- have -= copy;
- next += copy;
- if (len) goto inf_leave;
- }
- else if (state->head != Z_NULL)
- state->head->comment = Z_NULL;
- state->mode = HCRC;
- case HCRC:
- if (state->flags & 0x0200) {
- NEEDBITS(16);
- if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
- strm->msg = (char *)"header crc mismatch";
- state->mode = BAD;
- break;
- }
- INITBITS();
- }
- if (state->head != Z_NULL) {
- state->head->hcrc = (int)((state->flags >> 9) & 1);
- state->head->done = 1;
- }
- strm->adler = state->check = crc32(0L, Z_NULL, 0);
- state->mode = TYPE;
- break;
-#endif
- case DICTID:
- NEEDBITS(32);
- strm->adler = state->check = ZSWAP32(hold);
- INITBITS();
- state->mode = DICT;
- case DICT:
- if (state->havedict == 0) {
- RESTORE();
- return Z_NEED_DICT;
- }
- strm->adler = state->check = adler32(0L, Z_NULL, 0);
- state->mode = TYPE;
- case TYPE:
- if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
- case TYPEDO:
- if (state->last) {
- BYTEBITS();
- state->mode = CHECK;
- break;
- }
- NEEDBITS(3);
- state->last = BITS(1);
- DROPBITS(1);
- switch (BITS(2)) {
- case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- state->last ? " (last)" : ""));
- state->mode = STORED;
- break;
- case 1: /* fixed block */
- fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
- state->last ? " (last)" : ""));
- state->mode = LEN_; /* decode codes */
- if (flush == Z_TREES) {
- DROPBITS(2);
- goto inf_leave;
- }
- break;
- case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- state->last ? " (last)" : ""));
- state->mode = TABLE;
- break;
- case 3:
- strm->msg = (char *)"invalid block type";
- state->mode = BAD;
- }
- DROPBITS(2);
- break;
- case STORED:
- BYTEBITS(); /* go to byte boundary */
- NEEDBITS(32);
- if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
- strm->msg = (char *)"invalid stored block lengths";
- state->mode = BAD;
- break;
- }
- state->length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
- state->length));
- INITBITS();
- state->mode = COPY_;
- if (flush == Z_TREES) goto inf_leave;
- case COPY_:
- state->mode = COPY;
- case COPY:
- copy = state->length;
- if (copy) {
- if (copy > have) copy = have;
- if (copy > left) copy = left;
- if (copy == 0) goto inf_leave;
- zmemcpy(put, next, copy);
- have -= copy;
- next += copy;
- left -= copy;
- put += copy;
- state->length -= copy;
- break;
- }
- Tracev((stderr, "inflate: stored end\n"));
- state->mode = TYPE;
- break;
- case TABLE:
- NEEDBITS(14);
- state->nlen = BITS(5) + 257;
- DROPBITS(5);
- state->ndist = BITS(5) + 1;
- DROPBITS(5);
- state->ncode = BITS(4) + 4;
- DROPBITS(4);
-#ifndef PKZIP_BUG_WORKAROUND
- if (state->nlen > 286 || state->ndist > 30) {
- strm->msg = (char *)"too many length or distance symbols";
- state->mode = BAD;
- break;
- }
-#endif
- Tracev((stderr, "inflate: table sizes ok\n"));
- state->have = 0;
- state->mode = LENLENS;
- case LENLENS:
- while (state->have < state->ncode) {
- NEEDBITS(3);
- state->lens[order[state->have++]] = (unsigned short)BITS(3);
- DROPBITS(3);
- }
- while (state->have < 19)
- state->lens[order[state->have++]] = 0;
- state->next = state->codes;
- state->lencode = (const code FAR *)(state->next);
- state->lenbits = 7;
- ret = inflate_table(CODES, state->lens, 19, &(state->next),
- &(state->lenbits), state->work);
- if (ret) {
- strm->msg = (char *)"invalid code lengths set";
- state->mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: code lengths ok\n"));
- state->have = 0;
- state->mode = CODELENS;
- case CODELENS:
- while (state->have < state->nlen + state->ndist) {
- for (;;) {
- here = state->lencode[BITS(state->lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.val < 16) {
- DROPBITS(here.bits);
- state->lens[state->have++] = here.val;
- }
- else {
- if (here.val == 16) {
- NEEDBITS(here.bits + 2);
- DROPBITS(here.bits);
- if (state->have == 0) {
- strm->msg = (char *)"invalid bit length repeat";
- state->mode = BAD;
- break;
- }
- len = state->lens[state->have - 1];
- copy = 3 + BITS(2);
- DROPBITS(2);
- }
- else if (here.val == 17) {
- NEEDBITS(here.bits + 3);
- DROPBITS(here.bits);
- len = 0;
- copy = 3 + BITS(3);
- DROPBITS(3);
- }
- else {
- NEEDBITS(here.bits + 7);
- DROPBITS(here.bits);
- len = 0;
- copy = 11 + BITS(7);
- DROPBITS(7);
- }
- if (state->have + copy > state->nlen + state->ndist) {
- strm->msg = (char *)"invalid bit length repeat";
- state->mode = BAD;
- break;
- }
- while (copy--)
- state->lens[state->have++] = (unsigned short)len;
- }
- }
-
- /* handle error breaks in while */
- if (state->mode == BAD) break;
-
- /* check for end-of-block code (better have one) */
- if (state->lens[256] == 0) {
- strm->msg = (char *)"invalid code -- missing end-of-block";
- state->mode = BAD;
- break;
- }
-
- /* build code tables -- note: do not change the lenbits or distbits
- values here (9 and 6) without reading the comments in inftrees.h
- concerning the ENOUGH constants, which depend on those values */
- state->next = state->codes;
- state->lencode = (const code FAR *)(state->next);
- state->lenbits = 9;
- ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
- &(state->lenbits), state->work);
- if (ret) {
- strm->msg = (char *)"invalid literal/lengths set";
- state->mode = BAD;
- break;
- }
- state->distcode = (const code FAR *)(state->next);
- state->distbits = 6;
- ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
- &(state->next), &(state->distbits), state->work);
- if (ret) {
- strm->msg = (char *)"invalid distances set";
- state->mode = BAD;
- break;
- }
- Tracev((stderr, "inflate: codes ok\n"));
- state->mode = LEN_;
- if (flush == Z_TREES) goto inf_leave;
- case LEN_:
- state->mode = LEN;
- case LEN:
- if (have >= INFLATE_FAST_MIN_INPUT &&
- left >= INFLATE_FAST_MIN_OUTPUT) {
- RESTORE();
- inflate_fast_chunk_(strm, out);
- LOAD();
- if (state->mode == TYPE)
- state->back = -1;
- break;
- }
- state->back = 0;
- for (;;) {
- here = state->lencode[BITS(state->lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if (here.op && (here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = state->lencode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- state->back += last.bits;
- }
- DROPBITS(here.bits);
- state->back += here.bits;
- state->length = (unsigned)here.val;
- if ((int)(here.op) == 0) {
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
- "inflate: literal '%c'\n" :
- "inflate: literal 0x%02x\n", here.val));
- state->mode = LIT;
- break;
- }
- if (here.op & 32) {
- Tracevv((stderr, "inflate: end of block\n"));
- state->back = -1;
- state->mode = TYPE;
- break;
- }
- if (here.op & 64) {
- strm->msg = (char *)"invalid literal/length code";
- state->mode = BAD;
- break;
- }
- state->extra = (unsigned)(here.op) & 15;
- state->mode = LENEXT;
- case LENEXT:
- if (state->extra) {
- NEEDBITS(state->extra);
- state->length += BITS(state->extra);
- DROPBITS(state->extra);
- state->back += state->extra;
- }
- Tracevv((stderr, "inflate: length %u\n", state->length));
- state->was = state->length;
- state->mode = DIST;
- case DIST:
- for (;;) {
- here = state->distcode[BITS(state->distbits)];
- if ((unsigned)(here.bits) <= bits) break;
- PULLBYTE();
- }
- if ((here.op & 0xf0) == 0) {
- last = here;
- for (;;) {
- here = state->distcode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
- PULLBYTE();
- }
- DROPBITS(last.bits);
- state->back += last.bits;
- }
- DROPBITS(here.bits);
- state->back += here.bits;
- if (here.op & 64) {
- strm->msg = (char *)"invalid distance code";
- state->mode = BAD;
- break;
- }
- state->offset = (unsigned)here.val;
- state->extra = (unsigned)(here.op) & 15;
- state->mode = DISTEXT;
- case DISTEXT:
- if (state->extra) {
- NEEDBITS(state->extra);
- state->offset += BITS(state->extra);
- DROPBITS(state->extra);
- state->back += state->extra;
- }
-#ifdef INFLATE_STRICT
- if (state->offset > state->dmax) {
- strm->msg = (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#endif
- Tracevv((stderr, "inflate: distance %u\n", state->offset));
- state->mode = MATCH;
- case MATCH:
- if (left == 0) goto inf_leave;
- copy = out - left;
- if (state->offset > copy) { /* copy from window */
- copy = state->offset - copy;
- if (copy > state->whave) {
- if (state->sane) {
- strm->msg = (char *)"invalid distance too far back";
- state->mode = BAD;
- break;
- }
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- Trace((stderr, "inflate.c too far\n"));
- copy -= state->whave;
- if (copy > state->length) copy = state->length;
- if (copy > left) copy = left;
- left -= copy;
- state->length -= copy;
- do {
- *put++ = 0;
- } while (--copy);
- if (state->length == 0) state->mode = LEN;
- break;
-#endif
- }
- if (copy > state->wnext) {
- copy -= state->wnext;
- from = state->window + (state->wsize - copy);
- }
- else
- from = state->window + (state->wnext - copy);
- if (copy > state->length) copy = state->length;
- if (copy > left) copy = left;
- put = chunkcopy_safe(put, from, copy, put + left);
- }
- else { /* copy from output */
- copy = state->length;
- if (copy > left) copy = left;
- put = chunkcopy_lapped_safe(put, state->offset, copy, put + left);
- }
- left -= copy;
- state->length -= copy;
- if (state->length == 0) state->mode = LEN;
- break;
- case LIT:
- if (left == 0) goto inf_leave;
- *put++ = (unsigned char)(state->length);
- left--;
- state->mode = LEN;
- break;
- case CHECK:
- if (state->wrap) {
- NEEDBITS(32);
- out -= left;
- strm->total_out += out;
- state->total += out;
- if ((state->wrap & 4) && out)
- strm->adler = state->check =
- UPDATE(state->check, put - out, out);
- out = left;
- if ((state->wrap & 4) && (
-#ifdef GUNZIP
- state->flags ? hold :
-#endif
- ZSWAP32(hold)) != state->check) {
- strm->msg = (char *)"incorrect data check";
- state->mode = BAD;
- break;
- }
- INITBITS();
- Tracev((stderr, "inflate: check matches trailer\n"));
- }
-#ifdef GUNZIP
- state->mode = LENGTH;
- case LENGTH:
- if (state->wrap && state->flags) {
- NEEDBITS(32);
- if (hold != (state->total & 0xffffffffUL)) {
- strm->msg = (char *)"incorrect length check";
- state->mode = BAD;
- break;
- }
- INITBITS();
- Tracev((stderr, "inflate: length matches trailer\n"));
- }
-#endif
- state->mode = DONE;
- case DONE:
- ret = Z_STREAM_END;
- goto inf_leave;
- case BAD:
- ret = Z_DATA_ERROR;
- goto inf_leave;
- case MEM:
- return Z_MEM_ERROR;
- case SYNC:
- default:
- return Z_STREAM_ERROR;
- }
-
- /*
- Return from inflate(), updating the total counts and the check value.
- If there was no progress during the inflate() call, return a buffer
- error. Call updatewindow() to create and/or update the window state.
- Note: a memory error from inflate() is non-recoverable.
- */
- inf_leave:
- /* We write a defined value in the unused space to help mark
- * where the stream has ended. We don't use zeros as that can
- * mislead clients relying on undefined behavior (i.e. assuming
- * that the data is over when the buffer has a zero/null value).
- */
- if (left >= CHUNKCOPY_CHUNK_SIZE)
- memset(put, 0x55, CHUNKCOPY_CHUNK_SIZE);
- else
- memset(put, 0x55, left);
-
- RESTORE();
- if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
- (state->mode < CHECK || flush != Z_FINISH)))
- if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
- state->mode = MEM;
- return Z_MEM_ERROR;
- }
- in -= strm->avail_in;
- out -= strm->avail_out;
- strm->total_in += in;
- strm->total_out += out;
- state->total += out;
- if ((state->wrap & 4) && out)
- strm->adler = state->check =
- UPDATE(state->check, strm->next_out - out, out);
- strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
- (state->mode == TYPE ? 128 : 0) +
- (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
- if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
- ret = Z_BUF_ERROR;
- return ret;
-}
-
-int ZEXPORT inflateEnd(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
- if (inflateStateCheck(strm))
- return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (state->window != Z_NULL) ZFREE(strm, state->window);
- ZFREE(strm, strm->state);
- strm->state = Z_NULL;
- Tracev((stderr, "inflate: end\n"));
- return Z_OK;
-}
-
-int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength)
-z_streamp strm;
-Bytef *dictionary;
-uInt *dictLength;
-{
- struct inflate_state FAR *state;
-
- /* check state */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
-
- /* copy dictionary */
- if (state->whave && dictionary != Z_NULL) {
- zmemcpy(dictionary, state->window + state->wnext,
- state->whave - state->wnext);
- zmemcpy(dictionary + state->whave - state->wnext,
- state->window, state->wnext);
- }
- if (dictLength != Z_NULL)
- *dictLength = state->whave;
- return Z_OK;
-}
-
-int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
-z_streamp strm;
-const Bytef *dictionary;
-uInt dictLength;
-{
- struct inflate_state FAR *state;
- unsigned long dictid;
- int ret;
-
- /* check state */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (state->wrap != 0 && state->mode != DICT)
- return Z_STREAM_ERROR;
-
- /* check for correct dictionary identifier */
- if (state->mode == DICT) {
- dictid = adler32(0L, Z_NULL, 0);
- dictid = adler32(dictid, dictionary, dictLength);
- if (dictid != state->check)
- return Z_DATA_ERROR;
- }
-
- /* copy dictionary to window using updatewindow(), which will amend the
- existing dictionary if appropriate */
- ret = updatewindow(strm, dictionary + dictLength, dictLength);
- if (ret) {
- state->mode = MEM;
- return Z_MEM_ERROR;
- }
- state->havedict = 1;
- Tracev((stderr, "inflate: dictionary set\n"));
- return Z_OK;
-}
-
-int ZEXPORT inflateGetHeader(strm, head)
-z_streamp strm;
-gz_headerp head;
-{
- struct inflate_state FAR *state;
-
- /* check state */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
-
- /* save header structure */
- state->head = head;
- head->done = 0;
- return Z_OK;
-}
-
-/*
- Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
- or when out of input. When called, *have is the number of pattern bytes
- found in order so far, in 0..3. On return *have is updated to the new
- state. If on return *have equals four, then the pattern was found and the
- return value is how many bytes were read including the last byte of the
- pattern. If *have is less than four, then the pattern has not been found
- yet and the return value is len. In the latter case, syncsearch() can be
- called again with more data and the *have state. *have is initialized to
- zero for the first call.
- */
-local unsigned syncsearch(have, buf, len)
-unsigned FAR *have;
-const unsigned char FAR *buf;
-unsigned len;
-{
- unsigned got;
- unsigned next;
-
- got = *have;
- next = 0;
- while (next < len && got < 4) {
- if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
- got++;
- else if (buf[next])
- got = 0;
- else
- got = 4 - got;
- next++;
- }
- *have = got;
- return next;
-}
-
-int ZEXPORT inflateSync(strm)
-z_streamp strm;
-{
- unsigned len; /* number of bytes to look at or looked at */
- unsigned long in, out; /* temporary to save total_in and total_out */
- unsigned char buf[4]; /* to restore bit buffer to byte string */
- struct inflate_state FAR *state;
-
- /* check parameters */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
-
- /* if first time, start search in bit buffer */
- if (state->mode != SYNC) {
- state->mode = SYNC;
- state->hold <<= state->bits & 7;
- state->bits -= state->bits & 7;
- len = 0;
- while (state->bits >= 8) {
- buf[len++] = (unsigned char)(state->hold);
- state->hold >>= 8;
- state->bits -= 8;
- }
- state->have = 0;
- syncsearch(&(state->have), buf, len);
- }
-
- /* search available input */
- len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
- strm->avail_in -= len;
- strm->next_in += len;
- strm->total_in += len;
-
- /* return no joy or set up to restart inflate() on a new block */
- if (state->have != 4) return Z_DATA_ERROR;
- in = strm->total_in; out = strm->total_out;
- inflateReset(strm);
- strm->total_in = in; strm->total_out = out;
- state->mode = TYPE;
- return Z_OK;
-}
-
-/*
- Returns true if inflate is currently at the end of a block generated by
- Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
- implementation to provide an additional safety check. PPP uses
- Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
- block. When decompressing, PPP checks that at the end of input packet,
- inflate is waiting for these length bytes.
- */
-int ZEXPORT inflateSyncPoint(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- return state->mode == STORED && state->bits == 0;
-}
-
-int ZEXPORT inflateCopy(dest, source)
-z_streamp dest;
-z_streamp source;
-{
- struct inflate_state FAR *state;
- struct inflate_state FAR *copy;
- unsigned char FAR *window;
- unsigned wsize;
-
- /* check input */
- if (inflateStateCheck(source) || dest == Z_NULL)
- return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)source->state;
-
- /* allocate space */
- copy = (struct inflate_state FAR *)
- ZALLOC(source, 1, sizeof(struct inflate_state));
- if (copy == Z_NULL) return Z_MEM_ERROR;
- window = Z_NULL;
- if (state->window != Z_NULL) {
- window = (unsigned char FAR *)
- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
- if (window == Z_NULL) {
- ZFREE(source, copy);
- return Z_MEM_ERROR;
- }
- }
-
- /* copy state */
- zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
- zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
- copy->strm = dest;
- if (state->lencode >= state->codes &&
- state->lencode <= state->codes + ENOUGH - 1) {
- copy->lencode = copy->codes + (state->lencode - state->codes);
- copy->distcode = copy->codes + (state->distcode - state->codes);
- }
- copy->next = copy->codes + (state->next - state->codes);
- if (window != Z_NULL) {
- wsize = 1U << state->wbits;
- zmemcpy(window, state->window, wsize);
- }
- copy->window = window;
- dest->state = (struct internal_state FAR *)copy;
- return Z_OK;
-}
-
-int ZEXPORT inflateUndermine(strm, subvert)
-z_streamp strm;
-int subvert;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
-#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
- state->sane = !subvert;
- return Z_OK;
-#else
- (void)subvert;
- state->sane = 1;
- return Z_DATA_ERROR;
-#endif
-}
-
-int ZEXPORT inflateValidate(strm, check)
-z_streamp strm;
-int check;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
- state = (struct inflate_state FAR *)strm->state;
- if (check)
- state->wrap |= 4;
- else
- state->wrap &= ~4;
- return Z_OK;
-}
-
-long ZEXPORT inflateMark(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
-
- if (inflateStateCheck(strm))
- return -(1L << 16);
- state = (struct inflate_state FAR *)strm->state;
- return (long)(((unsigned long)((long)state->back)) << 16) +
- (state->mode == COPY ? state->length :
- (state->mode == MATCH ? state->was - state->length : 0));
-}
-
-unsigned long ZEXPORT inflateCodesUsed(strm)
-z_streamp strm;
-{
- struct inflate_state FAR *state;
- if (inflateStateCheck(strm)) return (unsigned long)-1;
- state = (struct inflate_state FAR *)strm->state;
- return (unsigned long)(state->next - state->codes);
-}
diff --git a/contrib/optimizations/insert_string.h b/contrib/optimizations/insert_string.h
deleted file mode 100644
index 9f634ae..0000000
--- a/contrib/optimizations/insert_string.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/* insert_string.h
- *
- * Copyright 2019 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#if defined(_MSC_VER)
-#define INLINE __inline
-#else
-#define INLINE inline
-#endif
-
-#include "cpu_features.h"
-
-// clang-format off
-#if defined(CRC32_SIMD_SSE42_PCLMUL)
- #include <smmintrin.h> /* Required to make MSVC bot build pass. */
-
- #if defined(__clang__) || defined(__GNUC__)
- #define TARGET_CPU_WITH_CRC __attribute__((target("sse4.2")))
- #else
- #define TARGET_CPU_WITH_CRC
- #endif
-
- #define _cpu_crc32_u32 _mm_crc32_u32
-
-#elif defined(CRC32_ARMV8_CRC32)
- #if defined(__clang__)
- #define __crc32cw __builtin_arm_crc32cw
- #elif defined(__GNUC__)
- #define __crc32cw __builtin_aarch64_crc32cw
- #endif
-
- #if defined(__aarch64__) && defined(__clang__)
- #define TARGET_CPU_WITH_CRC __attribute__((target("crc")))
- #elif defined(__aarch64__) && defined(__GNUC__)
- #define TARGET_CPU_WITH_CRC __attribute__((target("+crc")))
- #elif defined(__clang__) // !defined(__aarch64__)
- #define TARGET_CPU_WITH_CRC __attribute__((target("armv8-a,crc")))
- #endif // defined(__aarch64__)
-
- #define _cpu_crc32_u32 __crc32cw
-
-#endif
-// clang-format on
-
-#if defined(TARGET_CPU_WITH_CRC)
-
-TARGET_CPU_WITH_CRC
-local INLINE Pos insert_string_simd(deflate_state* const s, const Pos str) {
- Pos ret;
- unsigned *ip, val, h = 0;
-
- ip = (unsigned*)&s->window[str];
- val = *ip;
-
- if (s->level >= 6)
- val &= 0xFFFFFF;
-
- /* Unlike the case of data integrity checks for GZIP format where the
- * polynomial used is defined (https://tools.ietf.org/html/rfc1952#page-11),
- * here it is just a hash function for the hash table used while
- * performing compression.
- */
- h = _cpu_crc32_u32(h, val);
-
- ret = s->head[h & s->hash_mask];
- s->head[h & s->hash_mask] = str;
- s->prev[str & s->w_mask] = ret;
- return ret;
-}
-
-#endif // TARGET_CPU_WITH_CRC
-
-/* ===========================================================================
- * Update a hash value with the given input byte
- * IN assertion: all calls to UPDATE_HASH are made with consecutive input
- * characters, so that a running hash key can be computed from the previous
- * key instead of complete recalculation each time.
- */
-#define UPDATE_HASH(s, h, c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask)
-
-/* ===========================================================================
- * Insert string str in the dictionary and set match_head to the previous head
- * of the hash chain (the most recent string with same hash key). Return
- * the previous length of the hash chain.
- * If this file is compiled with -DFASTEST, the compression level is forced
- * to 1, and no hash chains are maintained.
- * IN assertion: all calls to INSERT_STRING are made with consecutive input
- * characters and the first MIN_MATCH bytes of str are valid (except for
- * the last MIN_MATCH-1 bytes of the input file).
- */
-local INLINE Pos insert_string_c(deflate_state* const s, const Pos str) {
- Pos ret;
-
- UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH - 1)]);
-#ifdef FASTEST
- ret = s->head[s->ins_h];
-#else
- ret = s->prev[str & s->w_mask] = s->head[s->ins_h];
-#endif
- s->head[s->ins_h] = str;
-
- return ret;
-}
-
-local INLINE Pos insert_string(deflate_state* const s, const Pos str) {
-/* insert_string_simd string dictionary insertion: this SIMD symbol hashing
- * significantly improves data compression speed.
- *
- * Note: the generated compressed output is a valid DEFLATE stream but will
- * differ from vanilla zlib output ...
- */
-#if defined(CHROMIUM_ZLIB_NO_CASTAGNOLI)
-/* ... so this build-time option can used to disable the SIMD symbol hasher
- * if matching vanilla zlib DEFLATE output is required.
- */ (;) /* FALLTHOUGH */
-#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_SIMD_SSE42_PCLMUL)
- if (x86_cpu_enable_simd)
- return insert_string_simd(s, str);
-#elif defined(TARGET_CPU_WITH_CRC) && defined(CRC32_ARMV8_CRC32)
- if (arm_cpu_enable_crc32)
- return insert_string_simd(s, str);
-#endif
- return insert_string_c(s, str);
-}
diff --git a/contrib/optimizations/slide_hash_neon.h b/contrib/optimizations/slide_hash_neon.h
deleted file mode 100644
index 26995d7..0000000
--- a/contrib/optimizations/slide_hash_neon.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Copyright 2018 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-#ifndef __SLIDE_HASH__NEON__
-#define __SLIDE_HASH__NEON__
-
-#include "deflate.h"
-#include <arm_neon.h>
-
-inline static void ZLIB_INTERNAL neon_slide_hash_update(Posf *hash,
- const uInt hash_size,
- const ush w_size)
-{
- /* NEON 'Q' registers allow to store 128 bits, so we can load 8x16-bits
- * values. For further details, check:
- * ARM DHT 0002A, section 1.3.2 NEON Registers.
- */
- const size_t chunk = sizeof(uint16x8_t) / sizeof(uint16_t);
- /* Unrolling the operation yielded a compression performance boost in both
- * ARMv7 (from 11.7% to 13.4%) and ARMv8 (from 3.7% to 7.5%) for HTML4
- * content. For full benchmarking data, check: http://crbug.com/863257.
- */
- const size_t stride = 2*chunk;
- const uint16x8_t v = vdupq_n_u16(w_size);
-
- for (Posf *end = hash + hash_size; hash != end; hash += stride) {
- uint16x8_t m_low = vld1q_u16(hash);
- uint16x8_t m_high = vld1q_u16(hash + chunk);
-
- /* The first 'q' in vqsubq_u16 makes these subtracts saturate to zero,
- * replacing the ternary operator expression in the original code:
- * (m >= wsize ? m - wsize : NIL).
- */
- m_low = vqsubq_u16(m_low, v);
- m_high = vqsubq_u16(m_high, v);
-
- vst1q_u16(hash, m_low);
- vst1q_u16(hash + chunk, m_high);
- }
-}
-
-
-inline static void ZLIB_INTERNAL neon_slide_hash(Posf *head, Posf *prev,
- const unsigned short w_size,
- const uInt hash_size)
-{
- /*
- * SIMD implementation for hash table rebase assumes:
- * 1. hash chain offset (Pos) is 2 bytes.
- * 2. hash table size is multiple of 32 bytes.
- * #1 should be true as Pos is defined as "ush"
- * #2 should be true as hash_bits are greater than 7
- */
- const size_t size = hash_size * sizeof(head[0]);
- Assert(sizeof(Pos) == 2, "Wrong Pos size.");
- Assert((size % sizeof(uint16x8_t) * 2) == 0, "Hash table size error.");
-
- neon_slide_hash_update(head, hash_size, w_size);
-#ifndef FASTEST
- neon_slide_hash_update(prev, w_size, w_size);
-#endif
-}
-
-#endif
diff --git a/contrib/tests/fuzzers/BUILD.gn b/contrib/tests/fuzzers/BUILD.gn
deleted file mode 100644
index 34c3b43..0000000
--- a/contrib/tests/fuzzers/BUILD.gn
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//testing/libfuzzer/fuzzer_test.gni")
-
-# root BUILD depends on this target. Needed for package discovery
-group("fuzzers") {
-}
-
-fuzzer_test("zlib_uncompress_fuzzer") {
- sources = [ "uncompress_fuzzer.cc" ]
- deps = [ "../../../:zlib" ]
-}
-
-fuzzer_test("zlib_inflate_fuzzer") {
- sources = [ "inflate_fuzzer.cc" ]
- deps = [ "../../../:zlib" ]
-}
-
-fuzzer_test("zlib_deflate_set_dictionary_fuzzer") {
- sources = [ "deflate_set_dictionary_fuzzer.cc" ]
- deps = [ "../../../:zlib" ]
-}
-
-fuzzer_test("zlib_deflate_fuzzer") {
- sources = [ "deflate_fuzzer.cc" ]
- deps = [ "../../../:zlib" ]
-}
diff --git a/contrib/tests/fuzzers/deflate_fuzzer.cc b/contrib/tests/fuzzers/deflate_fuzzer.cc
deleted file mode 100644
index c00e715..0000000
--- a/contrib/tests/fuzzers/deflate_fuzzer.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <fuzzer/FuzzedDataProvider.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <vector>
-
-#include "third_party/zlib/zlib.h"
-
-// Fuzzer builds often have NDEBUG set, so roll our own assert macro.
-#define ASSERT(cond) \
- do { \
- if (!(cond)) { \
- fprintf(stderr, "%s:%d Assert failed: %s\n", __FILE__, __LINE__, #cond); \
- exit(1); \
- } \
- } while (0)
-
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- FuzzedDataProvider fdp(data, size);
- int level = fdp.PickValueInArray({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
- int windowBits = fdp.PickValueInArray({9, 10, 11, 12, 13, 14, 15});
- int memLevel = fdp.PickValueInArray({1, 2, 3, 4, 5, 6, 7, 8, 9});
- int strategy = fdp.PickValueInArray(
- {Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED});
- std::vector<uint8_t> src = fdp.ConsumeRemainingBytes<uint8_t>();
-
- z_stream stream;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
-
- // Compress the data one byte at a time to exercise the streaming code.
- int ret =
- deflateInit2(&stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
- ASSERT(ret == Z_OK);
- std::vector<uint8_t> compressed(src.size() * 2 + 1000);
- stream.next_out = compressed.data();
- stream.avail_out = compressed.size();
- for (uint8_t b : src) {
- stream.next_in = &b;
- stream.avail_in = 1;
- ret = deflate(&stream, Z_NO_FLUSH);
- ASSERT(ret == Z_OK);
- }
- stream.next_in = Z_NULL;
- stream.avail_in = 0;
- ret = deflate(&stream, Z_FINISH);
- ASSERT(ret == Z_STREAM_END);
- compressed.resize(compressed.size() - stream.avail_out);
- deflateEnd(&stream);
-
- // Verify that the data decompresses correctly.
- ret = inflateInit2(&stream, windowBits);
- ASSERT(ret == Z_OK);
- // Make room for at least one byte so it's never empty.
- std::vector<uint8_t> decompressed(src.size() + 1);
- stream.next_in = compressed.data();
- stream.avail_in = compressed.size();
- stream.next_out = decompressed.data();
- stream.avail_out = decompressed.size();
- ret = inflate(&stream, Z_FINISH);
- ASSERT(ret == Z_STREAM_END);
- decompressed.resize(decompressed.size() - stream.avail_out);
- inflateEnd(&stream);
-
- ASSERT(decompressed == src);
-
- return 0;
-}
diff --git a/contrib/tests/fuzzers/deflate_set_dictionary_fuzzer.cc b/contrib/tests/fuzzers/deflate_set_dictionary_fuzzer.cc
deleted file mode 100644
index febbfcb..0000000
--- a/contrib/tests/fuzzers/deflate_set_dictionary_fuzzer.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <cassert>
-#include <vector>
-
-#include "third_party/zlib/zlib.h"
-
-static Bytef buffer[256 * 1024] = {0};
-
-// Entry point for LibFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- // We need to strip the 'const' for zlib.
- std::vector<unsigned char> input_buffer{data, data + size};
-
- uLongf buffer_length = static_cast<uLongf>(sizeof(buffer));
-
- z_stream stream;
- stream.next_in = input_buffer.data();
- stream.avail_in = size;
- stream.total_in = size;
- stream.next_out = buffer;
- stream.avail_out = buffer_length;
- stream.total_out = buffer_length;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
-
- if (Z_OK != deflateInit(&stream, Z_DEFAULT_COMPRESSION)) {
- deflateEnd(&stream);
- assert(false);
- }
-
- auto deflate_set_dictionary_result =
- deflateSetDictionary(&stream, data, size);
- deflateEnd(&stream);
- if (Z_OK != deflate_set_dictionary_result)
- assert(false);
-
- return 0;
-}
diff --git a/contrib/tests/fuzzers/inflate_fuzzer.cc b/contrib/tests/fuzzers/inflate_fuzzer.cc
deleted file mode 100644
index 44f9c72..0000000
--- a/contrib/tests/fuzzers/inflate_fuzzer.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-#include <cassert>
-#include <vector>
-
-#include "third_party/zlib/zlib.h"
-
-static Bytef buffer[256 * 1024] = {0};
-
-// Entry point for LibFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- // We need to strip the 'const' for zlib
- std::vector<unsigned char> input_buffer{data, data+size};
-
- uLongf buffer_length = static_cast<uLongf>(sizeof(buffer));
-
- z_stream stream;
- stream.next_in = input_buffer.data();
- stream.avail_in = size;
- stream.total_in = size;
- stream.next_out = buffer;
- stream.avail_out = buffer_length;
- stream.total_out = buffer_length;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
-
- if (Z_OK != inflateInit(&stream)) {
- inflateEnd(&stream);
- assert(false);
- }
-
- inflate(&stream, Z_NO_FLUSH);
- inflateEnd(&stream);
-
- return 0;
-}
diff --git a/contrib/tests/fuzzers/streaming_inflate_fuzzer.cc b/contrib/tests/fuzzers/streaming_inflate_fuzzer.cc
deleted file mode 100644
index de4d216..0000000
--- a/contrib/tests/fuzzers/streaming_inflate_fuzzer.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "third_party/zlib/zlib.h"
-
-// Fuzzer builds often have NDEBUG set, so roll our own assert macro.
-#define ASSERT(cond) \
- do { \
- if (!(cond)) { \
- fprintf(stderr, "%s:%d Assert failed: %s\n", __FILE__, __LINE__, #cond); \
- exit(1); \
- } \
- } while (0)
-
-// Entry point for LibFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- // Deflate data.
- z_stream comp_strm;
- comp_strm.zalloc = Z_NULL;
- comp_strm.zfree = Z_NULL;
- comp_strm.opaque = Z_NULL;
- int ret = deflateInit(&comp_strm, Z_DEFAULT_COMPRESSION);
- ASSERT(ret == Z_OK);
-
- size_t comp_buf_cap = deflateBound(&comp_strm, size);
- uint8_t* comp_buf = (uint8_t*)malloc(comp_buf_cap);
- ASSERT(comp_buf != nullptr);
- comp_strm.next_out = comp_buf;
- comp_strm.avail_out = comp_buf_cap;
- comp_strm.next_in = (unsigned char*)data;
- comp_strm.avail_in = size;
- ret = deflate(&comp_strm, Z_FINISH);
- ASSERT(ret == Z_STREAM_END);
- size_t comp_sz = comp_buf_cap - comp_strm.avail_out;
-
- // Inflate comp_buf one chunk at a time.
- z_stream decomp_strm;
- decomp_strm.zalloc = Z_NULL;
- decomp_strm.zfree = Z_NULL;
- decomp_strm.opaque = Z_NULL;
- ret = inflateInit(&decomp_strm);
- ASSERT(ret == Z_OK);
- decomp_strm.next_in = comp_buf;
- decomp_strm.avail_in = comp_sz;
-
- while (decomp_strm.avail_in > 0) {
- uint8_t decomp_buf[1024];
- decomp_strm.next_out = decomp_buf;
- decomp_strm.avail_out = sizeof(decomp_buf);
- ret = inflate(&decomp_strm, Z_FINISH);
- ASSERT(ret == Z_OK || ret == Z_STREAM_END || ret == Z_BUF_ERROR);
-
- // Verify the output bytes.
- size_t num_out = sizeof(decomp_buf) - decomp_strm.avail_out;
- for (size_t i = 0; i < num_out; i++) {
- ASSERT(decomp_buf[i] == data[decomp_strm.total_out - num_out + i]);
- }
- }
-
- ret = deflateEnd(&comp_strm);
- ASSERT(ret == Z_OK);
- free(comp_buf);
-
- inflateEnd(&decomp_strm);
- ASSERT(ret == Z_OK);
-
- return 0;
-}
diff --git a/contrib/tests/fuzzers/uncompress_fuzzer.cc b/contrib/tests/fuzzers/uncompress_fuzzer.cc
deleted file mode 100644
index bca5244..0000000
--- a/contrib/tests/fuzzers/uncompress_fuzzer.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-
-#include "third_party/zlib/zlib.h"
-
-static Bytef buffer[256 * 1024] = {0};
-
-// Entry point for LibFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- uLongf buffer_length = static_cast<uLongf>(sizeof(buffer));
- if (Z_OK !=
- uncompress(buffer, &buffer_length, data, static_cast<uLong>(size))) {
- return 0;
- }
- return 0;
-}
diff --git a/contrib/tests/infcover.cc b/contrib/tests/infcover.cc
deleted file mode 100644
index c5300a5..0000000
--- a/contrib/tests/infcover.cc
+++ /dev/null
@@ -1,684 +0,0 @@
-/* infcover.c -- test zlib's inflate routines with full code coverage
- * Copyright (C) 2011, 2016 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* to use, do: ./configure --cover && make cover */
-// clang-format off
-#include "infcover.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "zlib.h"
-
-/* get definition of internal structure so we can mess with it (see pull()),
- and so we can call inflate_trees() (see cover5()) */
-#define ZLIB_INTERNAL
-#include "inftrees.h"
-#include "inflate.h"
-
-/* XXX: use C++ streams instead of printf/fputs/etc due to portability
- * as type sizes can vary between platforms.
- */
-#include <iostream>
-#define local static
-
-/* XXX: hacking C assert and plugging into GTest. */
-#include "gtest.h"
-#if defined(assert)
-#undef assert
-#define assert EXPECT_TRUE
-#endif
-
-/* XXX: handle what is a reserved word in C++. */
-#define try try_f
-
-/* -- memory tracking routines -- */
-
-/*
- These memory tracking routines are provided to zlib and track all of zlib's
- allocations and deallocations, check for LIFO operations, keep a current
- and high water mark of total bytes requested, optionally set a limit on the
- total memory that can be allocated, and when done check for memory leaks.
-
- They are used as follows:
-
- z_stream strm;
- mem_setup(&strm) initializes the memory tracking and sets the
- zalloc, zfree, and opaque members of strm to use
- memory tracking for all zlib operations on strm
- mem_limit(&strm, limit) sets a limit on the total bytes requested -- a
- request that exceeds this limit will result in an
- allocation failure (returns NULL) -- setting the
- limit to zero means no limit, which is the default
- after mem_setup()
- mem_used(&strm, "msg") prints to stderr "msg" and the total bytes used
- mem_high(&strm, "msg") prints to stderr "msg" and the high water mark
- mem_done(&strm, "msg") ends memory tracking, releases all allocations
- for the tracking as well as leaked zlib blocks, if
- any. If there was anything unusual, such as leaked
- blocks, non-FIFO frees, or frees of addresses not
- allocated, then "msg" and information about the
- problem is printed to stderr. If everything is
- normal, nothing is printed. mem_done resets the
- strm members to Z_NULL to use the default memory
- allocation routines on the next zlib initialization
- using strm.
- */
-
-/* these items are strung together in a linked list, one for each allocation */
-struct mem_item {
- void *ptr; /* pointer to allocated memory */
- size_t size; /* requested size of allocation */
- struct mem_item *next; /* pointer to next item in list, or NULL */
-};
-
-/* this structure is at the root of the linked list, and tracks statistics */
-struct mem_zone {
- struct mem_item *first; /* pointer to first item in list, or NULL */
- size_t total, highwater; /* total allocations, and largest total */
- size_t limit; /* memory allocation limit, or 0 if no limit */
- int notlifo, rogue; /* counts of non-LIFO frees and rogue frees */
-};
-
-/* memory allocation routine to pass to zlib */
-local void *mem_alloc(void *mem, unsigned count, unsigned size)
-{
- void *ptr;
- struct mem_item *item;
- struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
- size_t len = count * (size_t)size;
-
- /* induced allocation failure */
- if (zone == NULL || (zone->limit && zone->total + len > zone->limit))
- return NULL;
-
- /* perform allocation using the standard library, fill memory with a
- non-zero value to make sure that the code isn't depending on zeros */
- ptr = malloc(len);
- if (ptr == NULL)
- return NULL;
- memset(ptr, 0xa5, len);
-
- /* create a new item for the list */
- item = static_cast<struct mem_item *>(malloc(sizeof(struct mem_item)));
- if (item == NULL) {
- free(ptr);
- return NULL;
- }
- item->ptr = ptr;
- item->size = len;
-
- /* insert item at the beginning of the list */
- item->next = zone->first;
- zone->first = item;
-
- /* update the statistics */
- zone->total += item->size;
- if (zone->total > zone->highwater)
- zone->highwater = zone->total;
-
- /* return the allocated memory */
- return ptr;
-}
-
-/* memory free routine to pass to zlib */
-local void mem_free(void *mem, void *ptr)
-{
- struct mem_item *item, *next;
- struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
-
- /* if no zone, just do a free */
- if (zone == NULL) {
- free(ptr);
- return;
- }
-
- /* point next to the item that matches ptr, or NULL if not found -- remove
- the item from the linked list if found */
- next = zone->first;
- if (next) {
- if (next->ptr == ptr)
- zone->first = next->next; /* first one is it, remove from list */
- else {
- do { /* search the linked list */
- item = next;
- next = item->next;
- } while (next != NULL && next->ptr != ptr);
- if (next) { /* if found, remove from linked list */
- item->next = next->next;
- zone->notlifo++; /* not a LIFO free */
- }
-
- }
- }
-
- /* if found, update the statistics and free the item */
- if (next) {
- zone->total -= next->size;
- free(next);
- }
-
- /* if not found, update the rogue count */
- else
- zone->rogue++;
-
- /* in any case, do the requested free with the standard library function */
- free(ptr);
-}
-
-/* set up a controlled memory allocation space for monitoring, set the stream
- parameters to the controlled routines, with opaque pointing to the space */
-local void mem_setup(z_stream *strm)
-{
- struct mem_zone *zone;
-
- zone = static_cast<struct mem_zone *>(malloc(sizeof(struct mem_zone)));
- assert(zone != NULL);
- zone->first = NULL;
- zone->total = 0;
- zone->highwater = 0;
- zone->limit = 0;
- zone->notlifo = 0;
- zone->rogue = 0;
- strm->opaque = zone;
- strm->zalloc = mem_alloc;
- strm->zfree = mem_free;
-}
-
-/* set a limit on the total memory allocation, or 0 to remove the limit */
-local void mem_limit(z_stream *strm, size_t limit)
-{
- struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
-
- zone->limit = limit;
-}
-
-/* show the current total requested allocations in bytes */
-local void mem_used(z_stream *strm, const char *prefix)
-{
- struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
-
- std::cout << prefix << ": " << zone->total << " allocated" << std::endl;
-}
-
-/* show the high water allocation in bytes */
-local void mem_high(z_stream *strm, const char *prefix)
-{
- struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
-
- std::cout << prefix << ": " << zone->highwater << " high water mark" << std::endl;
-}
-
-/* release the memory allocation zone -- if there are any surprises, notify */
-local void mem_done(z_stream *strm, const char *prefix)
-{
- int count = 0;
- struct mem_item *item, *next;
- struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
-
- /* show high water mark */
- mem_high(strm, prefix);
-
- /* free leftover allocations and item structures, if any */
- item = zone->first;
- while (item != NULL) {
- free(item->ptr);
- next = item->next;
- free(item);
- item = next;
- count++;
- }
-
- /* issue alerts about anything unexpected */
- if (count || zone->total)
- std::cout << "** " << prefix << ": "
- << zone->total << " bytes in "
- << count << " blocks not freed"
- << std::endl;
-
- if (zone->notlifo)
- std::cout << "** " << prefix << ": "
- << zone->notlifo << " frees not LIFO"
- << std::endl;
-
- if (zone->rogue)
- std::cout << "** " << prefix << ": "
- << zone->rogue << " frees not recognized"
- << std::endl;
-
- /* free the zone and delete from the stream */
- free(zone);
- strm->opaque = Z_NULL;
- strm->zalloc = Z_NULL;
- strm->zfree = Z_NULL;
-}
-
-/* -- inflate test routines -- */
-
-/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This
- decodes liberally, in that hex digits can be adjacent, in which case two in
- a row writes a byte. Or they can be delimited by any non-hex character,
- where the delimiters are ignored except when a single hex digit is followed
- by a delimiter, where that single digit writes a byte. The returned data is
- allocated and must eventually be freed. NULL is returned if out of memory.
- If the length is not needed, then len can be NULL. */
-local unsigned char *h2b(const char *hex, unsigned *len)
-{
- unsigned char *in, *re;
- unsigned next, val;
-
- in = static_cast<unsigned char *>(malloc((strlen(hex) + 1) >> 1));
- if (in == NULL)
- return NULL;
- next = 0;
- val = 1;
- do {
- if (*hex >= '0' && *hex <= '9')
- val = (val << 4) + *hex - '0';
- else if (*hex >= 'A' && *hex <= 'F')
- val = (val << 4) + *hex - 'A' + 10;
- else if (*hex >= 'a' && *hex <= 'f')
- val = (val << 4) + *hex - 'a' + 10;
- else if (val != 1 && val < 32) /* one digit followed by delimiter */
- val += 240; /* make it look like two digits */
- if (val > 255) { /* have two digits */
- in[next++] = val & 0xff; /* save the decoded byte */
- val = 1; /* start over */
- }
- } while (*hex++); /* go through the loop with the terminating null */
- if (len != NULL)
- *len = next;
- re = static_cast<unsigned char *>(realloc(in, next));
- return re == NULL ? in : re;
-}
-
-/* generic inflate() run, where hex is the hexadecimal input data, what is the
- text to include in an error message, step is how much input data to feed
- inflate() on each call, or zero to feed it all, win is the window bits
- parameter to inflateInit2(), len is the size of the output buffer, and err
- is the error code expected from the first inflate() call (the second
- inflate() call is expected to return Z_STREAM_END). If win is 47, then
- header information is collected with inflateGetHeader(). If a zlib stream
- is looking for a dictionary, then an empty dictionary is provided.
- inflate() is run until all of the input data is consumed. */
-local void inf(const char *hex, const char *what, unsigned step, int win, unsigned len,
- int err)
-{
- int ret;
- unsigned have;
- unsigned char *in, *out;
- z_stream strm, copy;
- gz_header head;
-
- mem_setup(&strm);
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit2(&strm, win);
- if (ret != Z_OK) {
- mem_done(&strm, what);
- return;
- }
- out = static_cast<unsigned char *>(malloc(len)); assert(out != NULL);
- if (win == 47) {
- head.extra = out;
- head.extra_max = len;
- head.name = out;
- head.name_max = len;
- head.comment = out;
- head.comm_max = len;
- ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK);
- }
- in = h2b(hex, &have); assert(in != NULL);
- if (step == 0 || step > have)
- step = have;
- strm.avail_in = step;
- have -= step;
- strm.next_in = in;
- do {
- strm.avail_out = len;
- strm.next_out = out;
- ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err);
- if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT)
- break;
- if (ret == Z_NEED_DICT) {
- ret = inflateSetDictionary(&strm, in, 1);
- assert(ret == Z_DATA_ERROR);
- mem_limit(&strm, 1);
- ret = inflateSetDictionary(&strm, out, 0);
- assert(ret == Z_MEM_ERROR);
- mem_limit(&strm, 0);
- ((struct inflate_state *)strm.state)->mode = DICT;
- ret = inflateSetDictionary(&strm, out, 0);
- assert(ret == Z_OK);
- ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR);
- }
- ret = inflateCopy(©, &strm); assert(ret == Z_OK);
- ret = inflateEnd(©); assert(ret == Z_OK);
- err = 9; /* don't care next time around */
- have += strm.avail_in;
- strm.avail_in = step > have ? have : step;
- have -= strm.avail_in;
- } while (strm.avail_in);
- free(in);
- free(out);
- ret = inflateReset2(&strm, -8); assert(ret == Z_OK);
- ret = inflateEnd(&strm); assert(ret == Z_OK);
- mem_done(&strm, what);
-}
-
-/* cover all of the lines in inflate.c up to inflate() */
-void cover_support(void)
-{
- int ret;
- z_stream strm;
-
- mem_setup(&strm);
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm); assert(ret == Z_OK);
- mem_used(&strm, "inflate init");
- ret = inflatePrime(&strm, 5, 31); assert(ret == Z_OK);
- ret = inflatePrime(&strm, -1, 0); assert(ret == Z_OK);
- ret = inflateSetDictionary(&strm, Z_NULL, 0);
- assert(ret == Z_STREAM_ERROR);
- ret = inflateEnd(&strm); assert(ret == Z_OK);
- mem_done(&strm, "prime");
-
- inf("63 0", "force window allocation", 0, -15, 1, Z_OK);
- inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK);
- inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK);
- inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END);
- inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);
-
- mem_setup(&strm);
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
- assert(ret == Z_VERSION_ERROR);
- mem_done(&strm, "wrong version");
-
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm); assert(ret == Z_OK);
- ret = inflateEnd(&strm); assert(ret == Z_OK);
- std::cout << "inflate built-in memory routines" << std::endl;;
-}
-
-/* cover all inflate() header and trailer cases and code after inflate() */
-void cover_wrap(void)
-{
- int ret;
- z_stream strm, copy;
- unsigned char dict[257];
-
- ret = inflate(Z_NULL, 0); assert(ret == Z_STREAM_ERROR);
- ret = inflateEnd(Z_NULL); assert(ret == Z_STREAM_ERROR);
- ret = inflateCopy(Z_NULL, Z_NULL); assert(ret == Z_STREAM_ERROR);
- std::cout << "inflate bad parameters" << std::endl;
-
- inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR);
- inf("1f 8b 8 80", "bad gzip flags", 0, 31, 0, Z_DATA_ERROR);
- inf("77 85", "bad zlib method", 0, 15, 0, Z_DATA_ERROR);
- inf("8 99", "set window size from header", 0, 0, 0, Z_OK);
- inf("78 9c", "bad zlib window size", 0, 8, 0, Z_DATA_ERROR);
- inf("78 9c 63 0 0 0 1 0 1", "check adler32", 0, 15, 1, Z_STREAM_END);
- inf("1f 8b 8 1e 0 0 0 0 0 0 1 0 0 0 0 0 0", "bad header crc", 0, 47, 1,
- Z_DATA_ERROR);
- inf("1f 8b 8 2 0 0 0 0 0 0 1d 26 3 0 0 0 0 0 0 0 0 0", "check gzip length",
- 0, 47, 0, Z_STREAM_END);
- inf("78 90", "bad zlib header check", 0, 47, 0, Z_DATA_ERROR);
- inf("8 b8 0 0 0 1", "need dictionary", 0, 8, 0, Z_NEED_DICT);
- inf("78 9c 63 0", "compute adler32", 0, 15, 1, Z_OK);
-
- mem_setup(&strm);
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit2(&strm, -8);
- strm.avail_in = 2;
- strm.next_in = (Bytef *)"\x63";
- strm.avail_out = 1;
- strm.next_out = (Bytef *)&ret;
- mem_limit(&strm, 1);
- ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR);
- ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR);
- mem_limit(&strm, 0);
- memset(dict, 0, 257);
- ret = inflateSetDictionary(&strm, dict, 257);
- assert(ret == Z_OK);
- mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256);
- ret = inflatePrime(&strm, 16, 0); assert(ret == Z_OK);
- strm.avail_in = 2;
- strm.next_in = (Bytef *)"\x80";
- ret = inflateSync(&strm); assert(ret == Z_DATA_ERROR);
- ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR);
- strm.avail_in = 4;
- strm.next_in = (Bytef *)"\0\0\xff\xff";
- ret = inflateSync(&strm); assert(ret == Z_OK);
- (void)inflateSyncPoint(&strm);
- ret = inflateCopy(©, &strm); assert(ret == Z_MEM_ERROR);
- mem_limit(&strm, 0);
- ret = inflateUndermine(&strm, 1); assert(ret == Z_DATA_ERROR);
- (void)inflateMark(&strm);
- ret = inflateEnd(&strm); assert(ret == Z_OK);
- mem_done(&strm, "miscellaneous, force memory errors");
-}
-
-/* input and output functions for inflateBack() */
-local unsigned pull(void *desc, unsigned char **buf)
-{
- static unsigned int next = 0;
- static unsigned char dat[] = {0x63, 0, 2, 0};
- struct inflate_state *state;
-
- if (desc == Z_NULL) {
- next = 0;
- return 0; /* no input (already provided at next_in) */
- }
- state = reinterpret_cast<struct inflate_state *>(((z_stream *)desc)->state);
- if (state != Z_NULL)
- state->mode = SYNC; /* force an otherwise impossible situation */
- return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
-}
-
-local int push(void *desc, unsigned char *buf, unsigned len)
-{
- buf += len;
- return desc != Z_NULL; /* force error if desc not null */
-}
-
-/* cover inflateBack() up to common deflate data cases and after those */
-void cover_back(void)
-{
- int ret;
- z_stream strm;
- unsigned char win[32768];
-
- ret = inflateBackInit_(Z_NULL, 0, win, 0, 0);
- assert(ret == Z_VERSION_ERROR);
- ret = inflateBackInit(Z_NULL, 0, win); assert(ret == Z_STREAM_ERROR);
- ret = inflateBack(Z_NULL, Z_NULL, Z_NULL, Z_NULL, Z_NULL);
- assert(ret == Z_STREAM_ERROR);
- ret = inflateBackEnd(Z_NULL); assert(ret == Z_STREAM_ERROR);
- std::cout << "inflateBack bad parameters" << std::endl;;
-
- mem_setup(&strm);
- ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK);
- strm.avail_in = 2;
- strm.next_in = (Bytef *)"\x03";
- ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL);
- assert(ret == Z_STREAM_END);
- /* force output error */
- strm.avail_in = 3;
- strm.next_in = (Bytef *)"\x63\x00";
- ret = inflateBack(&strm, pull, Z_NULL, push, &strm);
- assert(ret == Z_BUF_ERROR);
- /* force mode error by mucking with state */
- ret = inflateBack(&strm, pull, &strm, push, Z_NULL);
- assert(ret == Z_STREAM_ERROR);
- ret = inflateBackEnd(&strm); assert(ret == Z_OK);
- mem_done(&strm, "inflateBack bad state");
-
- ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK);
- ret = inflateBackEnd(&strm); assert(ret == Z_OK);
- std::cout << "inflateBack built-in memory routines" << std::endl;;
-}
-
-/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
-local int try(const char *hex, const char *id, int err)
-{
- int ret;
- unsigned len, size;
- unsigned char *in, *out, *win;
- char *prefix;
- z_stream strm;
-
- /* convert to hex */
- in = h2b(hex, &len);
- assert(in != NULL);
-
- /* allocate work areas */
- size = len << 3;
- out = static_cast<unsigned char *>(malloc(size));
- assert(out != NULL);
- win = static_cast<unsigned char *>(malloc(32768));
- assert(win != NULL);
- prefix = static_cast<char *>(malloc(strlen(id) + 6));
- assert(prefix != NULL);
-
- /* first with inflate */
- strcpy(prefix, id);
- strcat(prefix, "-late");
- mem_setup(&strm);
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit2(&strm, err < 0 ? 47 : -15);
- assert(ret == Z_OK);
- strm.avail_in = len;
- strm.next_in = in;
- do {
- strm.avail_out = size;
- strm.next_out = out;
- ret = inflate(&strm, Z_TREES);
- assert(ret != Z_STREAM_ERROR && ret != Z_MEM_ERROR);
- if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT)
- break;
- } while (strm.avail_in || strm.avail_out == 0);
- if (err) {
- assert(ret == Z_DATA_ERROR);
- assert(strcmp(id, strm.msg) == 0);
- }
- inflateEnd(&strm);
- mem_done(&strm, prefix);
-
- /* then with inflateBack */
- if (err >= 0) {
- strcpy(prefix, id);
- strcat(prefix, "-back");
- mem_setup(&strm);
- ret = inflateBackInit(&strm, 15, win);
- assert(ret == Z_OK);
- strm.avail_in = len;
- strm.next_in = in;
- ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL);
- assert(ret != Z_STREAM_ERROR);
- if (err) {
- assert(ret == Z_DATA_ERROR);
- assert(strcmp(id, strm.msg) == 0);
- }
- inflateBackEnd(&strm);
- mem_done(&strm, prefix);
- }
-
- /* clean up */
- free(prefix);
- free(win);
- free(out);
- free(in);
- return ret;
-}
-
-/* cover deflate data cases in both inflate() and inflateBack() */
-void cover_inflate(void)
-{
- try("0 0 0 0 0", "invalid stored block lengths", 1);
- try("3 0", "fixed", 0);
- try("6", "invalid block type", 1);
- try("1 1 0 fe ff 0", "stored", 0);
- try("fc 0 0", "too many length or distance symbols", 1);
- try("4 0 fe ff", "invalid code lengths set", 1);
- try("4 0 24 49 0", "invalid bit length repeat", 1);
- try("4 0 24 e9 ff ff", "invalid bit length repeat", 1);
- try("4 0 24 e9 ff 6d", "invalid code -- missing end-of-block", 1);
- try("4 80 49 92 24 49 92 24 71 ff ff 93 11 0",
- "invalid literal/lengths set", 1);
- try("4 80 49 92 24 49 92 24 f b4 ff ff c3 84", "invalid distances set", 1);
- try("4 c0 81 8 0 0 0 0 20 7f eb b 0 0", "invalid literal/length code", 1);
- try("2 7e ff ff", "invalid distance code", 1);
- try("c c0 81 0 0 0 0 0 90 ff 6b 4 0", "invalid distance too far back", 1);
-
- /* also trailer mismatch just in inflate() */
- try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 1", "incorrect data check", -1);
- try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 1",
- "incorrect length check", -1);
- try("5 c0 21 d 0 0 0 80 b0 fe 6d 2f 91 6c", "pull 17", 0);
- try("5 e0 81 91 24 cb b2 2c 49 e2 f 2e 8b 9a 47 56 9f fb fe ec d2 ff 1f",
- "long code", 0);
- try("ed c0 1 1 0 0 0 40 20 ff 57 1b 42 2c 4f", "length extra", 0);
- try("ed cf c1 b1 2c 47 10 c4 30 fa 6f 35 1d 1 82 59 3d fb be 2e 2a fc f c",
- "long distance and extra", 0);
- try("ed c0 81 0 0 0 0 80 a0 fd a9 17 a9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "
- "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6", "window end", 0);
- inf("2 8 20 80 0 3 0", "inflate_fast TYPE return", 0, -15, 258,
- Z_STREAM_END);
- inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK);
-}
-
-/* XXX(cavalcantii): fix linking error due inflate_table. */
-/* cover remaining lines in inftrees.c */
-/* void cover_trees(void) */
-/* { */
-/* int ret; */
-/* unsigned bits; */
-/* unsigned short lens[16], work[16]; */
-/* code *next, table[ENOUGH_DISTS]; */
-
-/* /\* we need to call inflate_table() directly in order to manifest not- */
-/* enough errors, since zlib insures that enough is always enough *\/ */
-/* for (bits = 0; bits < 15; bits++) */
-/* lens[bits] = (unsigned short)(bits + 1); */
-/* lens[15] = 15; */
-/* next = table; */
-/* bits = 15; */
-/* ret = inflate_table(DISTS, lens, 16, &next, &bits, work); */
-/* assert(ret == 1); */
-/* next = table; */
-/* bits = 1; */
-/* ret = inflate_table(DISTS, lens, 16, &next, &bits, work); */
-/* assert(ret == 1); */
-/* fputs("inflate_table not enough errors\n", stderr); */
-/* } */
-
-/* cover remaining inffast.c decoding and window copying */
-void cover_fast(void)
-{
- inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
- " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);
- inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49"
- " 50 fe ff ff 3f 0 0", "fast distance extra bits", 0, -8, 258,
- Z_DATA_ERROR);
- inf("3 7e 0 0 0 0 0", "fast invalid distance code", 0, -8, 258,
- Z_DATA_ERROR);
- inf("1b 7 0 0 0 0 0", "fast invalid literal/length code", 0, -8, 258,
- Z_DATA_ERROR);
- inf("d c7 1 ae eb 38 c 4 41 a0 87 72 de df fb 1f b8 36 b1 38 5d ff ff 0",
- "fast 2nd level codes and too far back", 0, -8, 258, Z_DATA_ERROR);
- inf("63 18 5 8c 10 8 0 0 0 0", "very common case", 0, -8, 259, Z_OK);
- inf("63 60 60 18 c9 0 8 18 18 18 26 c0 28 0 29 0 0 0",
- "contiguous and wrap around window", 6, -8, 259, Z_OK);
- inf("63 0 3 0 0 0 0 0", "copy direct from output", 0, -8, 259,
- Z_STREAM_END);
-}
-
-// clang-format on
diff --git a/contrib/tests/infcover.h b/contrib/tests/infcover.h
deleted file mode 100644
index b3e112f..0000000
--- a/contrib/tests/infcover.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __INF_COVER_H__
-#define __INF_COVER_H__
-
-void cover_support(void);
-void cover_wrap(void);
-void cover_back(void);
-void cover_inflate(void);
-void cover_trees(void);
-void cover_fast(void);
-
-#endif
diff --git a/contrib/tests/run_all_unittests.cc b/contrib/tests/run_all_unittests.cc
deleted file mode 100644
index 65ed57e..0000000
--- a/contrib/tests/run_all_unittests.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/bind.h"
-#include "base/test/launcher/unit_test_launcher.h"
-#include "base/test/test_suite.h"
-
-int main(int argc, char** argv) {
- base::TestSuite test_suite(argc, argv);
- return base::LaunchUnitTests(
- argc, argv,
- base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
-}
diff --git a/contrib/tests/utils_unittest.cc b/contrib/tests/utils_unittest.cc
deleted file mode 100644
index 468421e..0000000
--- a/contrib/tests/utils_unittest.cc
+++ /dev/null
@@ -1,521 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the Chromium source repository LICENSE file.
-
-#include "infcover.h"
-
-#include <cstddef>
-#include <vector>
-
-#include "compression_utils_portable.h"
-#include "gtest.h"
-#include "zlib.h"
-
-void TestPayloads(size_t input_size, zlib_internal::WrapperType type) {
- std::vector<unsigned char> input;
- input.reserve(input_size);
- for (size_t i = 1; i <= input_size; ++i)
- input.push_back(i & 0xff);
-
- // If it is big enough for GZIP, will work for other wrappers.
- std::vector<unsigned char> compressed(
- zlib_internal::GzipExpectedCompressedSize(input.size()));
- std::vector<unsigned char> decompressed(input.size());
-
- // Libcores's java/util/zip/Deflater default settings: ZLIB,
- // DEFAULT_COMPRESSION and DEFAULT_STRATEGY.
- unsigned long compressed_size = static_cast<unsigned long>(compressed.size());
- int result = zlib_internal::CompressHelper(
- type, compressed.data(), &compressed_size, input.data(), input.size(),
- Z_DEFAULT_COMPRESSION, nullptr, nullptr);
- ASSERT_EQ(result, Z_OK);
-
- unsigned long decompressed_size =
- static_cast<unsigned long>(decompressed.size());
- result = zlib_internal::UncompressHelper(type, decompressed.data(),
- &decompressed_size,
- compressed.data(), compressed_size);
- ASSERT_EQ(result, Z_OK);
- EXPECT_EQ(input, decompressed);
-}
-
-TEST(ZlibTest, ZlibWrapper) {
- // Minimal ZLIB wrapped short stream size is about 8 bytes.
- for (size_t i = 1; i < 1024; ++i)
- TestPayloads(i, zlib_internal::WrapperType::ZLIB);
-}
-
-TEST(ZlibTest, GzipWrapper) {
- // GZIP should be 12 bytes bigger than ZLIB wrapper.
- for (size_t i = 1; i < 1024; ++i)
- TestPayloads(i, zlib_internal::WrapperType::GZIP);
-}
-
-TEST(ZlibTest, RawWrapper) {
- // RAW has no wrapper (V8 Blobs is a known user), size
- // should be payload_size + 2 for short payloads.
- for (size_t i = 1; i < 1024; ++i)
- TestPayloads(i, zlib_internal::WrapperType::ZRAW);
-}
-
-TEST(ZlibTest, InflateCover) {
- cover_support();
- cover_wrap();
- cover_back();
- cover_inflate();
- // TODO(cavalcantii): enable this last test.
- // cover_trees();
- cover_fast();
-}
-
-TEST(ZlibTest, DeflateStored) {
- const int no_compression = 0;
- const zlib_internal::WrapperType type = zlib_internal::WrapperType::GZIP;
- std::vector<unsigned char> input(1 << 10, 42);
- std::vector<unsigned char> compressed(
- zlib_internal::GzipExpectedCompressedSize(input.size()));
- std::vector<unsigned char> decompressed(input.size());
- unsigned long compressed_size = static_cast<unsigned long>(compressed.size());
- int result = zlib_internal::CompressHelper(
- type, compressed.data(), &compressed_size, input.data(), input.size(),
- no_compression, nullptr, nullptr);
- ASSERT_EQ(result, Z_OK);
-
- unsigned long decompressed_size =
- static_cast<unsigned long>(decompressed.size());
- result = zlib_internal::UncompressHelper(type, decompressed.data(),
- &decompressed_size,
- compressed.data(), compressed_size);
- ASSERT_EQ(result, Z_OK);
- EXPECT_EQ(input, decompressed);
-}
-
-TEST(ZlibTest, StreamingInflate) {
- uint8_t comp_buf[4096], decomp_buf[4096];
- z_stream comp_strm, decomp_strm;
- int ret;
-
- std::vector<uint8_t> src;
- for (size_t i = 0; i < 1000; i++) {
- for (size_t j = 0; j < 40; j++) {
- src.push_back(j);
- }
- }
-
- // Deflate src into comp_buf.
- comp_strm.zalloc = Z_NULL;
- comp_strm.zfree = Z_NULL;
- comp_strm.opaque = Z_NULL;
- ret = deflateInit(&comp_strm, Z_BEST_COMPRESSION);
- ASSERT_EQ(ret, Z_OK);
- comp_strm.next_out = comp_buf;
- comp_strm.avail_out = sizeof(comp_buf);
- comp_strm.next_in = src.data();
- comp_strm.avail_in = src.size();
- ret = deflate(&comp_strm, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- size_t comp_sz = sizeof(comp_buf) - comp_strm.avail_out;
-
- // Inflate comp_buf one 4096-byte buffer at a time.
- decomp_strm.zalloc = Z_NULL;
- decomp_strm.zfree = Z_NULL;
- decomp_strm.opaque = Z_NULL;
- ret = inflateInit(&decomp_strm);
- ASSERT_EQ(ret, Z_OK);
- decomp_strm.next_in = comp_buf;
- decomp_strm.avail_in = comp_sz;
-
- while (decomp_strm.avail_in > 0) {
- decomp_strm.next_out = decomp_buf;
- decomp_strm.avail_out = sizeof(decomp_buf);
- ret = inflate(&decomp_strm, Z_FINISH);
- ASSERT_TRUE(ret == Z_OK || ret == Z_STREAM_END || ret == Z_BUF_ERROR);
-
- // Verify the output bytes.
- size_t num_out = sizeof(decomp_buf) - decomp_strm.avail_out;
- for (size_t i = 0; i < num_out; i++) {
- EXPECT_EQ(decomp_buf[i], src[decomp_strm.total_out - num_out + i]);
- }
- }
-
- // Cleanup memory (i.e. makes ASAN bot happy).
- ret = deflateEnd(&comp_strm);
- EXPECT_EQ(ret, Z_OK);
- ret = inflateEnd(&decomp_strm);
- EXPECT_EQ(ret, Z_OK);
-}
-
-TEST(ZlibTest, CRCHashBitsCollision) {
- // The CRC32c of the hex sequences 2a,14,14,14 and 2a,14,db,14 have the same
- // lower 9 bits. Since longest_match doesn't check match[2], a bad match could
- // be chosen when the number of hash bits is <= 9. For this reason, the number
- // of hash bits must be set higher, regardless of the memlevel parameter, when
- // using CRC32c hashing for string matching. See https://crbug.com/1113596
-
- std::vector<uint8_t> src = {
- // Random byte; zlib doesn't match at offset 0.
- 123,
-
- // This will look like 5-byte match.
- 0x2a,
- 0x14,
- 0xdb,
- 0x14,
- 0x15,
-
- // Offer a 4-byte match to bump the next expected match length to 5.
- 0x2a,
- 0x14,
- 0x14,
- 0x14,
-
- 0x2a,
- 0x14,
- 0x14,
- 0x14,
- 0x15,
- };
-
- z_stream stream;
- stream.zalloc = nullptr;
- stream.zfree = nullptr;
-
- // Using a low memlevel to try to reduce the number of hash bits. Negative
- // windowbits means raw deflate, i.e. without the zlib header.
- int ret = deflateInit2(&stream, /*comp level*/ 2, /*method*/ Z_DEFLATED,
- /*windowbits*/ -15, /*memlevel*/ 2,
- /*strategy*/ Z_DEFAULT_STRATEGY);
- ASSERT_EQ(ret, Z_OK);
- std::vector<uint8_t> compressed(100, '\0');
- stream.next_out = compressed.data();
- stream.avail_out = compressed.size();
- stream.next_in = src.data();
- stream.avail_in = src.size();
- ret = deflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- compressed.resize(compressed.size() - stream.avail_out);
- deflateEnd(&stream);
-
- ret = inflateInit2(&stream, /*windowbits*/ -15);
- ASSERT_EQ(ret, Z_OK);
- std::vector<uint8_t> decompressed(src.size(), '\0');
- stream.next_in = compressed.data();
- stream.avail_in = compressed.size();
- stream.next_out = decompressed.data();
- stream.avail_out = decompressed.size();
- ret = inflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- EXPECT_EQ(0U, stream.avail_out);
- inflateEnd(&stream);
-
- EXPECT_EQ(src, decompressed);
-}
-
-TEST(ZlibTest, CRCHashAssert) {
- // The CRC32c of the hex sequences ff,ff,5e,6f and ff,ff,13,ff have the same
- // lower 15 bits. This means longest_match's assert that match[2] == scan[2]
- // won't hold. However, such hash collisions are only possible when one of the
- // other four bytes also mismatch. This tests that zlib's assert handles this
- // case.
-
- std::vector<uint8_t> src = {
- // Random byte; zlib doesn't match at offset 0.
- 123,
-
- // This has the same hash as the last byte sequence, and the first two and
- // last two bytes match; though the third and the fourth don't.
- 0xff,
- 0xff,
- 0x5e,
- 0x6f,
- 0x12,
- 0x34,
-
- // Offer a 5-byte match to bump the next expected match length to 6
- // (because the two first and two last bytes need to match).
- 0xff,
- 0xff,
- 0x13,
- 0xff,
- 0x12,
-
- 0xff,
- 0xff,
- 0x13,
- 0xff,
- 0x12,
- 0x34,
- };
-
- z_stream stream;
- stream.zalloc = nullptr;
- stream.zfree = nullptr;
-
- int ret = deflateInit2(&stream, /*comp level*/ 5, /*method*/ Z_DEFLATED,
- /*windowbits*/ -15, /*memlevel*/ 8,
- /*strategy*/ Z_DEFAULT_STRATEGY);
- ASSERT_EQ(ret, Z_OK);
- std::vector<uint8_t> compressed(100, '\0');
- stream.next_out = compressed.data();
- stream.avail_out = compressed.size();
- stream.next_in = src.data();
- stream.avail_in = src.size();
- ret = deflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- compressed.resize(compressed.size() - stream.avail_out);
- deflateEnd(&stream);
-
- ret = inflateInit2(&stream, /*windowbits*/ -15);
- ASSERT_EQ(ret, Z_OK);
- std::vector<uint8_t> decompressed(src.size(), '\0');
- stream.next_in = compressed.data();
- stream.avail_in = compressed.size();
- stream.next_out = decompressed.data();
- stream.avail_out = decompressed.size();
- ret = inflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- EXPECT_EQ(0U, stream.avail_out);
- inflateEnd(&stream);
-
- EXPECT_EQ(src, decompressed);
-}
-
-// Fuzzer generated.
-static const uint8_t checkMatchCrashData[] = {
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
- 0x6e, 0x6e, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x01, 0x39, 0x6e, 0x6e,
- 0x00, 0x00, 0x00, 0x00, 0xf7, 0xff, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x6e,
- 0x00, 0x00, 0x0a, 0x9a, 0x00, 0x00, 0x6e, 0x6e, 0x6e, 0x2a, 0x00, 0x00,
- 0x00, 0xd5, 0xf0, 0x00, 0x81, 0x02, 0xf3, 0xfd, 0xff, 0xab, 0xf3, 0x6e,
- 0x7e, 0x04, 0x5b, 0xf6, 0x2a, 0x2c, 0xf8, 0x00, 0x54, 0xf3, 0xa5, 0x0e,
- 0xfd, 0x6e, 0xff, 0x00, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xa4, 0x0b, 0xa5, 0x2a, 0x0d, 0x10, 0x01, 0x26, 0xf6, 0x04, 0x0e,
- 0xff, 0x6e, 0x6e, 0x6e, 0x76, 0x00, 0x00, 0x87, 0x01, 0xfe, 0x0d, 0xb6,
- 0x6e, 0x6e, 0xf7, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfd, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x9b,
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
- 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x6e, 0xff, 0xff, 0x00,
- 0x00, 0xd5, 0xf0, 0x00, 0xff, 0x40, 0x7e, 0x0b, 0xa5, 0x10, 0x67, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x40, 0x7e, 0x0b, 0xa5, 0x10, 0x67,
- 0x7e, 0x32, 0x6e, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x40, 0x0b, 0xa5,
- 0x10, 0x67, 0x01, 0xfe, 0x0d, 0xb6, 0x2a, 0x00, 0x00, 0x58, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x6e, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x3d, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xd6, 0x2d, 0x2d, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
- 0x8a, 0x8a, 0x8a, 0x8a, 0x66, 0x8a, 0x8a, 0x8a, 0xee, 0x1d, 0x00, 0x00,
- 0x00, 0x02, 0x00, 0x00, 0x00, 0xee, 0x0a, 0x00, 0x00, 0x00, 0x54, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xf3, 0x00, 0x00, 0xff, 0xff, 0x23, 0x7e, 0x00, 0x1e,
- 0x00, 0x00, 0xd5, 0xf0, 0x00, 0xff, 0x40, 0x0b, 0xa5, 0x10, 0x67, 0x01,
- 0xfe, 0x0d, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
- 0x8a, 0x8a, 0x8a, 0x2d, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e,
- 0xfb, 0x00, 0x10, 0x24, 0x00, 0x00, 0xfb, 0xff, 0x00, 0x00, 0xff, 0x1f,
- 0xb3, 0x00, 0x04, 0x3d, 0x00, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
- 0x01, 0x45, 0x3d, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x11, 0x21, 0x00, 0x1e,
- 0x00, 0x0c, 0xb3, 0xfe, 0x0e, 0xee, 0x02, 0x00, 0x1d, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x6e, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x6e, 0x00,
- 0x00, 0x87, 0x00, 0x33, 0x38, 0x6e, 0x6e, 0x6e, 0x6e, 0x6e, 0x00, 0x00,
- 0x00, 0x38, 0x00, 0x00, 0xff, 0xff, 0xff, 0x04, 0x3f, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xff, 0x00, 0x31, 0x13, 0x13, 0x13,
- 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xab, 0x30, 0x83, 0x33,
- 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0xff, 0xff, 0x7d, 0xff, 0x00, 0x01,
- 0x10, 0x0d, 0x2a, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x11,
- 0x21, 0x00, 0xa5, 0x00, 0x68, 0x68, 0x68, 0x67, 0x00, 0x00, 0xff, 0xff,
- 0x02, 0x00, 0x00, 0x68, 0x68, 0x68, 0x68, 0x00, 0x00, 0xfa, 0xff, 0xff,
- 0x03, 0x01, 0xff, 0x02, 0x00, 0x00, 0x68, 0x68, 0x68, 0x68, 0x0a, 0x10,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
- 0x06, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfa, 0xff, 0xff, 0x08, 0xff, 0xff, 0xff, 0x00, 0x06, 0x04,
- 0x00, 0xf8, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x78, 0x00, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff, 0x00, 0x06, 0x04, 0x6e,
- 0x7e, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00,
- 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x6e, 0x6e, 0x6e,
- 0x00, 0x01, 0x38, 0xd5, 0xf0, 0x00, 0x00, 0x2a, 0xfe, 0x04, 0x5b, 0x0d,
- 0xfd, 0x6e, 0x92, 0x28, 0xf9, 0xfb, 0xff, 0x07, 0xd2, 0xd6, 0x2d, 0x2d,
- 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
- 0x8a, 0x8a, 0xc2, 0x91, 0x00, 0x5b, 0xef, 0xde, 0xf2, 0x6e, 0x6e, 0xfd,
- 0x0c, 0x02, 0x91, 0x62, 0x91, 0xfd, 0x6e, 0x6e, 0xd3, 0x06, 0x00, 0x00,
- 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00,
- 0xd5, 0xf0, 0x00, 0xff, 0x00, 0x00, 0x31, 0x13, 0x13, 0x13, 0x04, 0x00,
- 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x04, 0x00, 0x13, 0x0a, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x6e, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x09, 0x00, 0x6a, 0x24, 0x26, 0x30, 0x01, 0x2e, 0x2a, 0xfe,
- 0x04, 0x5b, 0x0d, 0xfd, 0x6e, 0x6e, 0xd7, 0x06, 0x6e, 0x6e, 0x6e, 0x00,
- 0x00, 0xb1, 0xb1, 0xb1, 0xb1, 0x00, 0x00, 0x00, 0x6e, 0x5b, 0x00, 0x00,
- 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x1e, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x0b,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x24, 0x2a, 0x6e, 0x5c, 0x24,
- 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x05, 0x00, 0x00, 0x00, 0x5d, 0x10, 0x6e, 0x6e, 0xa5, 0x2f, 0x00, 0x00,
- 0x95, 0x87, 0x00, 0x6e};
-
-TEST(ZlibTest, CheckMatchCrash) {
- // See https://crbug.com/1113142.
- z_stream stream;
- stream.zalloc = nullptr;
- stream.zfree = nullptr;
-
- // Low windowbits to hit window sliding also with a relatively small input.
- int ret = deflateInit2(&stream, /*comp level*/ 5, /*method*/ Z_DEFLATED,
- /*windowbits*/ -9, /*memlevel*/ 8,
- /*strategy*/ Z_DEFAULT_STRATEGY);
- ASSERT_EQ(ret, Z_OK);
-
- uint8_t compressed[sizeof(checkMatchCrashData) * 2];
- stream.next_out = compressed;
- stream.avail_out = sizeof(compressed);
-
- for (size_t i = 0; i < sizeof(checkMatchCrashData); i++) {
- ASSERT_GT(stream.avail_out, 0U);
- stream.next_in = (uint8_t*)&checkMatchCrashData[i];
- stream.avail_in = 1;
- ret = deflate(&stream, Z_NO_FLUSH);
- ASSERT_EQ(ret, Z_OK);
- }
-
- stream.next_in = nullptr;
- stream.avail_in = 0;
- ASSERT_GT(stream.avail_out, 0U);
- ret = deflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- size_t compressed_sz = sizeof(compressed) - stream.avail_out;
- deflateEnd(&stream);
-
- uint8_t decompressed[sizeof(checkMatchCrashData)];
- ret = inflateInit2(&stream, -15);
- ASSERT_EQ(ret, Z_OK);
- stream.next_in = compressed;
- stream.avail_in = compressed_sz;
- stream.next_out = decompressed;
- stream.avail_out = sizeof(decompressed);
- ret = inflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- inflateEnd(&stream);
- ASSERT_EQ(
- memcmp(checkMatchCrashData, decompressed, sizeof(checkMatchCrashData)),
- 0);
-}
-
-TEST(ZlibTest, DeflateRLEUninitUse) {
- // MSan would complain about use of uninitialized values in deflate_rle if the
- // window isn't zero-initialized. See crbug.com/1137613. Similar problems
- // exist in other places in zlib, e.g. longest_match (crbug.com/1144420) but
- // we don't have as nice test cases.
-
- int level = 9;
- int windowBits = 9;
- int memLevel = 8;
- int strategy = Z_RLE;
- const std::vector<uint8_t> src{
- 0x31, 0x64, 0x38, 0x32, 0x30, 0x32, 0x30, 0x36, 0x65, 0x35, 0x38, 0x35,
- 0x32, 0x61, 0x30, 0x36, 0x65, 0x35, 0x32, 0x66, 0x30, 0x34, 0x38, 0x37,
- 0x61, 0x31, 0x38, 0x36, 0x37, 0x37, 0x31, 0x39, 0x0a, 0x65, 0x62, 0x00,
- 0x9f, 0xff, 0xc6, 0xc6, 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff,
- 0xc6, 0xc6, 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff, 0xc6, 0xc6,
- 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff, 0xc6, 0xc6, 0xc6, 0x95,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0e, 0x0a, 0x54, 0x52,
- 0x58, 0x56, 0xab, 0x26, 0x13, 0x53, 0x5a, 0xb5, 0x30, 0xbb, 0x96, 0x44,
- 0x80, 0xe6, 0xc5, 0x0a, 0xd0, 0x47, 0x7a, 0xa0, 0x4e, 0xbe, 0x30, 0xdc,
- 0xa1, 0x08, 0x54, 0xe1, 0x51, 0xd1, 0xea, 0xef, 0xdb, 0xa1, 0x2d, 0xb4,
- 0xb9, 0x58, 0xb1, 0x2f, 0xf0, 0xae, 0xbc, 0x07, 0xd1, 0xba, 0x7f, 0x14,
- 0xa4, 0xde, 0x99, 0x7f, 0x4d, 0x3e, 0x25, 0xd9, 0xef, 0xee, 0x4f, 0x38,
- 0x7b, 0xaf, 0x3f, 0x6b, 0x53, 0x5a, 0xcb, 0x1f, 0x97, 0xb5, 0x43, 0xa3,
- 0xe8, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff, 0xc6, 0xc6, 0xc6, 0xff,
- 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff, 0xc6, 0xc6, 0xc6, 0xff, 0x09, 0x00,
- 0x62, 0x00, 0x9f, 0xff, 0xc6, 0xc6, 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00,
- 0x9f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x3c,
- 0x73, 0x70, 0x23, 0x87, 0xec, 0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xc1, 0x00, 0x00, 0x9f, 0xc6, 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f,
- 0xff, 0xc6, 0xc6, 0xc6, 0xff, 0x09, 0x00, 0x62, 0x00, 0x9f, 0xff, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
- };
-
- z_stream stream;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
-
- // Compress the data one byte at a time to exercise the streaming code.
- int ret =
- deflateInit2(&stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
- ASSERT_EQ(ret, Z_OK);
- std::vector<uint8_t> compressed(src.size() * 2 + 1000);
- stream.next_out = compressed.data();
- stream.avail_out = compressed.size();
- for (uint8_t b : src) {
- stream.next_in = &b;
- stream.avail_in = 1;
- ret = deflate(&stream, Z_NO_FLUSH);
- ASSERT_EQ(ret, Z_OK);
- }
- stream.next_in = Z_NULL;
- stream.avail_in = 0;
- ret = deflate(&stream, Z_FINISH);
- ASSERT_EQ(ret, Z_STREAM_END);
- deflateEnd(&stream);
-}
diff --git a/cpu_features.c b/cpu_features.c
deleted file mode 100644
index 70f01be..0000000
--- a/cpu_features.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* cpu_features.c -- Processor features detection.
- *
- * Copyright 2018 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#include "cpu_features.h"
-#include "zutil.h"
-
-#include <stdint.h>
-#if defined(_MSC_VER)
-#include <intrin.h>
-#elif defined(ADLER32_SIMD_SSSE3)
-#include <cpuid.h>
-#endif
-
-/* TODO(cavalcantii): remove checks for x86_flags on deflate.
- */
-#if defined(ARMV8_OS_MACOS)
-/* crc32 is a baseline feature in ARMv8.1-A, and macOS running on arm64 is new
- * enough that this can be assumed without runtime detection. */
-int ZLIB_INTERNAL arm_cpu_enable_crc32 = 1;
-#else
-int ZLIB_INTERNAL arm_cpu_enable_crc32 = 0;
-#endif
-int ZLIB_INTERNAL arm_cpu_enable_pmull = 0;
-int ZLIB_INTERNAL x86_cpu_enable_sse2 = 0;
-int ZLIB_INTERNAL x86_cpu_enable_ssse3 = 0;
-int ZLIB_INTERNAL x86_cpu_enable_simd = 0;
-
-#ifndef CPU_NO_SIMD
-
-#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA)
-#include <pthread.h>
-#endif
-
-#if defined(ARMV8_OS_ANDROID)
-#include <cpu-features.h>
-#elif defined(ARMV8_OS_LINUX)
-#include <asm/hwcap.h>
-#include <sys/auxv.h>
-#elif defined(ARMV8_OS_FUCHSIA)
-#include <zircon/features.h>
-#include <zircon/syscalls.h>
-#include <zircon/types.h>
-#elif defined(ARMV8_OS_WINDOWS) || defined(X86_WINDOWS)
-#include <windows.h>
-#elif !defined(_MSC_VER)
-#include <pthread.h>
-#else
-#error cpu_features.c CPU feature detection in not defined for your platform
-#endif
-
-#if !defined(CPU_NO_SIMD) && !defined(ARMV8_OS_MACOS) && !defined(ARM_OS_IOS)
-static void _cpu_check_features(void);
-#endif
-
-#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS)
-#if !defined(ARMV8_OS_MACOS)
-// _cpu_check_features() doesn't need to do anything on mac/arm since all
-// features are known at build time, so don't call it.
-// Do provide cpu_check_features() (with a no-op implementation) so that we
-// don't have to make all callers of it check for mac/arm.
-static pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
-#endif
-void ZLIB_INTERNAL cpu_check_features(void)
-{
-#if !defined(ARMV8_OS_MACOS)
- pthread_once(&cpu_check_inited_once, _cpu_check_features);
-#endif
-}
-#elif defined(ARMV8_OS_WINDOWS) || defined(X86_WINDOWS)
-static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT;
-static BOOL CALLBACK _cpu_check_features_forwarder(PINIT_ONCE once, PVOID param, PVOID* context)
-{
- _cpu_check_features();
- return TRUE;
-}
-void ZLIB_INTERNAL cpu_check_features(void)
-{
- InitOnceExecuteOnce(&cpu_check_inited_once, _cpu_check_features_forwarder,
- NULL, NULL);
-}
-#endif
-
-#if (defined(__ARM_NEON__) || defined(__ARM_NEON))
-/*
- * iOS@ARM is a special case where we always have NEON but don't check
- * for crypto extensions.
- */
-#if !defined(ARMV8_OS_MACOS) && !defined(ARM_OS_IOS)
-/*
- * See http://bit.ly/2CcoEsr for run-time detection of ARM features and also
- * crbug.com/931275 for android_getCpuFeatures() use in the Android sandbox.
- */
-static void _cpu_check_features(void)
-{
-#if defined(ARMV8_OS_ANDROID) && defined(__aarch64__)
- uint64_t features = android_getCpuFeatures();
- arm_cpu_enable_crc32 = !!(features & ANDROID_CPU_ARM64_FEATURE_CRC32);
- arm_cpu_enable_pmull = !!(features & ANDROID_CPU_ARM64_FEATURE_PMULL);
-#elif defined(ARMV8_OS_ANDROID) /* aarch32 */
- uint64_t features = android_getCpuFeatures();
- arm_cpu_enable_crc32 = !!(features & ANDROID_CPU_ARM_FEATURE_CRC32);
- arm_cpu_enable_pmull = !!(features & ANDROID_CPU_ARM_FEATURE_PMULL);
-#elif defined(ARMV8_OS_LINUX) && defined(__aarch64__)
- unsigned long features = getauxval(AT_HWCAP);
- arm_cpu_enable_crc32 = !!(features & HWCAP_CRC32);
- arm_cpu_enable_pmull = !!(features & HWCAP_PMULL);
-#elif defined(ARMV8_OS_LINUX) && (defined(__ARM_NEON) || defined(__ARM_NEON__))
- /* Query HWCAP2 for ARMV8-A SoCs running in aarch32 mode */
- unsigned long features = getauxval(AT_HWCAP2);
- arm_cpu_enable_crc32 = !!(features & HWCAP2_CRC32);
- arm_cpu_enable_pmull = !!(features & HWCAP2_PMULL);
-#elif defined(ARMV8_OS_FUCHSIA)
- uint32_t features;
- zx_status_t rc = zx_system_get_features(ZX_FEATURE_KIND_CPU, &features);
- if (rc != ZX_OK || (features & ZX_ARM64_FEATURE_ISA_ASIMD) == 0)
- return; /* Report nothing if ASIMD(NEON) is missing */
- arm_cpu_enable_crc32 = !!(features & ZX_ARM64_FEATURE_ISA_CRC32);
- arm_cpu_enable_pmull = !!(features & ZX_ARM64_FEATURE_ISA_PMULL);
-#elif defined(ARMV8_OS_WINDOWS)
- arm_cpu_enable_crc32 = IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
- arm_cpu_enable_pmull = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
-#endif
-}
-#endif
-#elif defined(X86_NOT_WINDOWS) || defined(X86_WINDOWS)
-/*
- * iOS@x86 (i.e. emulator) is another special case where we disable
- * SIMD optimizations.
- */
-#ifndef CPU_NO_SIMD
-/* On x86 we simply use a instruction to check the CPU features.
- * (i.e. CPUID).
- */
-static void _cpu_check_features(void)
-{
- int x86_cpu_has_sse2;
- int x86_cpu_has_ssse3;
- int x86_cpu_has_sse42;
- int x86_cpu_has_pclmulqdq;
- int abcd[4];
-
-#ifdef _MSC_VER
- __cpuid(abcd, 1);
-#else
- __cpuid(1, abcd[0], abcd[1], abcd[2], abcd[3]);
-#endif
-
- x86_cpu_has_sse2 = abcd[3] & 0x4000000;
- x86_cpu_has_ssse3 = abcd[2] & 0x000200;
- x86_cpu_has_sse42 = abcd[2] & 0x100000;
- x86_cpu_has_pclmulqdq = abcd[2] & 0x2;
-
- x86_cpu_enable_sse2 = x86_cpu_has_sse2;
-
- x86_cpu_enable_ssse3 = x86_cpu_has_ssse3;
-
- x86_cpu_enable_simd = x86_cpu_has_sse2 &&
- x86_cpu_has_sse42 &&
- x86_cpu_has_pclmulqdq;
-}
-#endif
-#endif
-#endif
diff --git a/cpu_features.h b/cpu_features.h
deleted file mode 100644
index c7b15c5..0000000
--- a/cpu_features.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* cpu_features.h -- Processor features detection.
- *
- * Copyright 2018 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#include "zlib.h"
-
-/* TODO(cavalcantii): remove checks for x86_flags on deflate.
- */
-extern int arm_cpu_enable_crc32;
-extern int arm_cpu_enable_pmull;
-extern int x86_cpu_enable_sse2;
-extern int x86_cpu_enable_ssse3;
-extern int x86_cpu_enable_simd;
-
-void cpu_check_features(void);
diff --git a/crc32.c b/crc32.c
deleted file mode 100644
index d4c3248..0000000
--- a/crc32.c
+++ /dev/null
@@ -1,527 +0,0 @@
-/* crc32.c -- compute the CRC-32 of a data stream
- * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- *
- * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
- * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
- * tables for updating the shift register in one step with three exclusive-ors
- * instead of four steps with four exclusive-ors. This results in about a
- * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
- */
-
-/* @(#) $Id$ */
-
-/*
- Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
- protection on the static variables used to control the first-use generation
- of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
- first call get_crc_table() to initialize the tables before allowing more than
- one thread to use crc32().
-
- DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
- */
-
-#ifdef MAKECRCH
-# include <stdio.h>
-# ifndef DYNAMIC_CRC_TABLE
-# define DYNAMIC_CRC_TABLE
-# endif /* !DYNAMIC_CRC_TABLE */
-#endif /* MAKECRCH */
-
-#include "deflate.h"
-#include "cpu_features.h"
-#include "zutil.h" /* for STDC and FAR definitions */
-
-#if defined(CRC32_SIMD_SSE42_PCLMUL) || defined(CRC32_ARMV8_CRC32)
-#include "crc32_simd.h"
-#endif
-
-/* Definitions for doing the crc four data bytes at a time. */
-#if !defined(NOBYFOUR) && defined(Z_U4)
-# define BYFOUR
-#endif
-#ifdef BYFOUR
- local unsigned long crc32_little OF((unsigned long,
- const unsigned char FAR *, z_size_t));
- local unsigned long crc32_big OF((unsigned long,
- const unsigned char FAR *, z_size_t));
-# define TBLS 8
-#else
-# define TBLS 1
-#endif /* BYFOUR */
-
-/* Local functions for crc concatenation */
-local unsigned long gf2_matrix_times OF((unsigned long *mat,
- unsigned long vec));
-local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
-local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
-
-
-#ifdef DYNAMIC_CRC_TABLE
-
-local volatile int crc_table_empty = 1;
-local z_crc_t FAR crc_table[TBLS][256];
-local void make_crc_table OF((void));
-#ifdef MAKECRCH
- local void write_table OF((FILE *, const z_crc_t FAR *));
-#endif /* MAKECRCH */
-/*
- Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
- x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
-
- Polynomials over GF(2) are represented in binary, one bit per coefficient,
- with the lowest powers in the most significant bit. Then adding polynomials
- is just exclusive-or, and multiplying a polynomial by x is a right shift by
- one. If we call the above polynomial p, and represent a byte as the
- polynomial q, also with the lowest power in the most significant bit (so the
- byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
- where a mod b means the remainder after dividing a by b.
-
- This calculation is done using the shift-register method of multiplying and
- taking the remainder. The register is initialized to zero, and for each
- incoming bit, x^32 is added mod p to the register if the bit is a one (where
- x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
- x (which is shifting right by one and adding x^32 mod p if the bit shifted
- out is a one). We start with the highest power (least significant bit) of
- q and repeat for all eight bits of q.
-
- The first table is simply the CRC of all possible eight bit values. This is
- all the information needed to generate CRCs on data a byte at a time for all
- combinations of CRC register values and incoming bytes. The remaining tables
- allow for word-at-a-time CRC calculation for both big-endian and little-
- endian machines, where a word is four bytes.
-*/
-local void make_crc_table()
-{
- z_crc_t c;
- int n, k;
- z_crc_t poly; /* polynomial exclusive-or pattern */
- /* terms of polynomial defining this crc (except x^32): */
- static volatile int first = 1; /* flag to limit concurrent making */
- static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
-
- /* See if another task is already doing this (not thread-safe, but better
- than nothing -- significantly reduces duration of vulnerability in
- case the advice about DYNAMIC_CRC_TABLE is ignored) */
- if (first) {
- first = 0;
-
- /* make exclusive-or pattern from polynomial (0xedb88320UL) */
- poly = 0;
- for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
- poly |= (z_crc_t)1 << (31 - p[n]);
-
- /* generate a crc for every 8-bit value */
- for (n = 0; n < 256; n++) {
- c = (z_crc_t)n;
- for (k = 0; k < 8; k++)
- c = c & 1 ? poly ^ (c >> 1) : c >> 1;
- crc_table[0][n] = c;
- }
-
-#ifdef BYFOUR
- /* generate crc for each value followed by one, two, and three zeros,
- and then the byte reversal of those as well as the first table */
- for (n = 0; n < 256; n++) {
- c = crc_table[0][n];
- crc_table[4][n] = ZSWAP32(c);
- for (k = 1; k < 4; k++) {
- c = crc_table[0][c & 0xff] ^ (c >> 8);
- crc_table[k][n] = c;
- crc_table[k + 4][n] = ZSWAP32(c);
- }
- }
-#endif /* BYFOUR */
-
- crc_table_empty = 0;
- }
- else { /* not first */
- /* wait for the other guy to finish (not efficient, but rare) */
- while (crc_table_empty)
- ;
- }
-
-#ifdef MAKECRCH
- /* write out CRC tables to crc32.h */
- {
- FILE *out;
-
- out = fopen("crc32.h", "w");
- if (out == NULL) return;
- fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
- fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
- fprintf(out, "local const z_crc_t FAR ");
- fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
- write_table(out, crc_table[0]);
-# ifdef BYFOUR
- fprintf(out, "#ifdef BYFOUR\n");
- for (k = 1; k < 8; k++) {
- fprintf(out, " },\n {\n");
- write_table(out, crc_table[k]);
- }
- fprintf(out, "#endif\n");
-# endif /* BYFOUR */
- fprintf(out, " }\n};\n");
- fclose(out);
- }
-#endif /* MAKECRCH */
-}
-
-#ifdef MAKECRCH
-local void write_table(out, table)
- FILE *out;
- const z_crc_t FAR *table;
-{
- int n;
-
- for (n = 0; n < 256; n++)
- fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
- (unsigned long)(table[n]),
- n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
-}
-#endif /* MAKECRCH */
-
-#else /* !DYNAMIC_CRC_TABLE */
-/* ========================================================================
- * Tables of CRC-32s of all single-byte values, made by make_crc_table().
- */
-#include "crc32.h"
-#endif /* DYNAMIC_CRC_TABLE */
-
-/* =========================================================================
- * This function can be used by asm versions of crc32()
- */
-const z_crc_t FAR * ZEXPORT get_crc_table()
-{
-#ifdef DYNAMIC_CRC_TABLE
- if (crc_table_empty)
- make_crc_table();
-#endif /* DYNAMIC_CRC_TABLE */
- return (const z_crc_t FAR *)crc_table;
-}
-
-/* ========================================================================= */
-#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
-#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
-
-/* ========================================================================= */
-unsigned long ZEXPORT crc32_z(crc, buf, len)
- unsigned long crc;
- const unsigned char FAR *buf;
- z_size_t len;
-{
- /*
- * zlib convention is to call crc32(0, NULL, 0); before making
- * calls to crc32(). So this is a good, early (and infrequent)
- * place to cache CPU features if needed for those later, more
- * interesting crc32() calls.
- */
-#if defined(CRC32_SIMD_SSE42_PCLMUL)
- /*
- * Use x86 sse4.2+pclmul SIMD to compute the crc32. Since this
- * routine can be freely used, check CPU features here.
- */
- if (buf == Z_NULL) {
- if (!len) /* Assume user is calling crc32(0, NULL, 0); */
- cpu_check_features();
- return 0UL;
- }
-
- if (x86_cpu_enable_simd && len >= Z_CRC32_SSE42_MINIMUM_LENGTH) {
- /* crc32 16-byte chunks */
- z_size_t chunk_size = len & ~Z_CRC32_SSE42_CHUNKSIZE_MASK;
- crc = ~crc32_sse42_simd_(buf, chunk_size, ~(uint32_t)crc);
- /* check remaining data */
- len -= chunk_size;
- if (!len)
- return crc;
- /* Fall into the default crc32 for the remaining data. */
- buf += chunk_size;
- }
-#else
- if (buf == Z_NULL) {
- return 0UL;
- }
-#endif /* CRC32_SIMD_SSE42_PCLMUL */
-
-#ifdef DYNAMIC_CRC_TABLE
- if (crc_table_empty)
- make_crc_table();
-#endif /* DYNAMIC_CRC_TABLE */
-
-#ifdef BYFOUR
- if (sizeof(void *) == sizeof(ptrdiff_t)) {
- z_crc_t endian;
-
- endian = 1;
- if (*((unsigned char *)(&endian)))
- return crc32_little(crc, buf, len);
- else
- return crc32_big(crc, buf, len);
- }
-#endif /* BYFOUR */
- crc = crc ^ 0xffffffffUL;
- while (len >= 8) {
- DO8;
- len -= 8;
- }
- if (len) do {
- DO1;
- } while (--len);
- return crc ^ 0xffffffffUL;
-}
-
-/* ========================================================================= */
-unsigned long ZEXPORT crc32(crc, buf, len)
- unsigned long crc;
- const unsigned char FAR *buf;
- uInt len;
-{
-#if defined(CRC32_ARMV8_CRC32)
- /* We got to verify ARM CPU features, so exploit the common usage pattern
- * of calling this function with Z_NULL for an initial valid crc value.
- * This allows to cache the result of the feature check and avoid extraneous
- * function calls.
- * TODO: try to move this to crc32_z if we don't loose performance on ARM.
- */
- if (buf == Z_NULL) {
- if (!len) /* Assume user is calling crc32(0, NULL, 0); */
- cpu_check_features();
- return 0UL;
- }
-
- if (arm_cpu_enable_crc32)
- return armv8_crc32_little(crc, buf, len);
-#endif
- return crc32_z(crc, buf, len);
-}
-
-#ifdef BYFOUR
-
-/*
- This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
- integer pointer type. This violates the strict aliasing rule, where a
- compiler can assume, for optimization purposes, that two pointers to
- fundamentally different types won't ever point to the same memory. This can
- manifest as a problem only if one of the pointers is written to. This code
- only reads from those pointers. So long as this code remains isolated in
- this compilation unit, there won't be a problem. For this reason, this code
- should not be copied and pasted into a compilation unit in which other code
- writes to the buffer that is passed to these routines.
- */
-
-/* ========================================================================= */
-#define DOLIT4 c ^= *buf4++; \
- c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
- crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
-#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
-
-/* ========================================================================= */
-local unsigned long crc32_little(crc, buf, len)
- unsigned long crc;
- const unsigned char FAR *buf;
- z_size_t len;
-{
- register z_crc_t c;
- register const z_crc_t FAR *buf4;
-
- c = (z_crc_t)crc;
- c = ~c;
- while (len && ((ptrdiff_t)buf & 3)) {
- c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
- len--;
- }
-
- buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
- while (len >= 32) {
- DOLIT32;
- len -= 32;
- }
- while (len >= 4) {
- DOLIT4;
- len -= 4;
- }
- buf = (const unsigned char FAR *)buf4;
-
- if (len) do {
- c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
- } while (--len);
- c = ~c;
- return (unsigned long)c;
-}
-
-/* ========================================================================= */
-#define DOBIG4 c ^= *buf4++; \
- c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
- crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
-#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
-
-/* ========================================================================= */
-local unsigned long crc32_big(crc, buf, len)
- unsigned long crc;
- const unsigned char FAR *buf;
- z_size_t len;
-{
- register z_crc_t c;
- register const z_crc_t FAR *buf4;
-
- c = ZSWAP32((z_crc_t)crc);
- c = ~c;
- while (len && ((ptrdiff_t)buf & 3)) {
- c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
- len--;
- }
-
- buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
- while (len >= 32) {
- DOBIG32;
- len -= 32;
- }
- while (len >= 4) {
- DOBIG4;
- len -= 4;
- }
- buf = (const unsigned char FAR *)buf4;
-
- if (len) do {
- c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
- } while (--len);
- c = ~c;
- return (unsigned long)(ZSWAP32(c));
-}
-
-#endif /* BYFOUR */
-
-#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
-
-/* ========================================================================= */
-local unsigned long gf2_matrix_times(mat, vec)
- unsigned long *mat;
- unsigned long vec;
-{
- unsigned long sum;
-
- sum = 0;
- while (vec) {
- if (vec & 1)
- sum ^= *mat;
- vec >>= 1;
- mat++;
- }
- return sum;
-}
-
-/* ========================================================================= */
-local void gf2_matrix_square(square, mat)
- unsigned long *square;
- unsigned long *mat;
-{
- int n;
-
- for (n = 0; n < GF2_DIM; n++)
- square[n] = gf2_matrix_times(mat, mat[n]);
-}
-
-/* ========================================================================= */
-local uLong crc32_combine_(crc1, crc2, len2)
- uLong crc1;
- uLong crc2;
- z_off64_t len2;
-{
- int n;
- unsigned long row;
- unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
- unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
-
- /* degenerate case (also disallow negative lengths) */
- if (len2 <= 0)
- return crc1;
-
- /* put operator for one zero bit in odd */
- odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
- row = 1;
- for (n = 1; n < GF2_DIM; n++) {
- odd[n] = row;
- row <<= 1;
- }
-
- /* put operator for two zero bits in even */
- gf2_matrix_square(even, odd);
-
- /* put operator for four zero bits in odd */
- gf2_matrix_square(odd, even);
-
- /* apply len2 zeros to crc1 (first square will put the operator for one
- zero byte, eight zero bits, in even) */
- do {
- /* apply zeros operator for this bit of len2 */
- gf2_matrix_square(even, odd);
- if (len2 & 1)
- crc1 = gf2_matrix_times(even, crc1);
- len2 >>= 1;
-
- /* if no more bits set, then done */
- if (len2 == 0)
- break;
-
- /* another iteration of the loop with odd and even swapped */
- gf2_matrix_square(odd, even);
- if (len2 & 1)
- crc1 = gf2_matrix_times(odd, crc1);
- len2 >>= 1;
-
- /* if no more bits set, then done */
- } while (len2 != 0);
-
- /* return combined crc */
- crc1 ^= crc2;
- return crc1;
-}
-
-/* ========================================================================= */
-uLong ZEXPORT crc32_combine(crc1, crc2, len2)
- uLong crc1;
- uLong crc2;
- z_off_t len2;
-{
- return crc32_combine_(crc1, crc2, len2);
-}
-
-uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
- uLong crc1;
- uLong crc2;
- z_off64_t len2;
-{
- return crc32_combine_(crc1, crc2, len2);
-}
-
-ZLIB_INTERNAL void crc_reset(deflate_state *const s)
-{
-#ifdef CRC32_SIMD_SSE42_PCLMUL
- if (x86_cpu_enable_simd) {
- crc_fold_init(s);
- return;
- }
-#endif
- s->strm->adler = crc32(0L, Z_NULL, 0);
-}
-
-ZLIB_INTERNAL void crc_finalize(deflate_state *const s)
-{
-#ifdef CRC32_SIMD_SSE42_PCLMUL
- if (x86_cpu_enable_simd)
- s->strm->adler = crc_fold_512to32(s);
-#endif
-}
-
-ZLIB_INTERNAL void copy_with_crc(z_streamp strm, Bytef *dst, long size)
-{
-#ifdef CRC32_SIMD_SSE42_PCLMUL
- if (x86_cpu_enable_simd) {
- crc_fold_copy(strm->state, dst, strm->next_in, size);
- return;
- }
-#endif
- zmemcpy(dst, strm->next_in, size);
- strm->adler = crc32(strm->adler, dst, size);
-}
diff --git a/crc32.h b/crc32.h
deleted file mode 100644
index 9e0c778..0000000
--- a/crc32.h
+++ /dev/null
@@ -1,441 +0,0 @@
-/* crc32.h -- tables for rapid CRC calculation
- * Generated automatically by crc32.c
- */
-
-local const z_crc_t FAR crc_table[TBLS][256] =
-{
- {
- 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
- 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
- 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
- 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
- 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
- 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
- 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
- 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
- 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
- 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
- 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
- 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
- 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
- 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
- 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
- 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
- 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
- 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
- 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
- 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
- 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
- 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
- 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
- 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
- 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
- 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
- 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
- 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
- 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
- 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
- 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
- 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
- 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
- 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
- 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
- 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
- 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
- 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
- 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
- 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
- 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
- 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
- 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
- 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
- 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
- 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
- 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
- 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
- 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
- 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
- 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
- 0x2d02ef8dUL
-#ifdef BYFOUR
- },
- {
- 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
- 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
- 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
- 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
- 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
- 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
- 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
- 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
- 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
- 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
- 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
- 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
- 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
- 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
- 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
- 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
- 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
- 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
- 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
- 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
- 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
- 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
- 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
- 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
- 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
- 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
- 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
- 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
- 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
- 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
- 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
- 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
- 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
- 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
- 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
- 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
- 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
- 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
- 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
- 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
- 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
- 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
- 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
- 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
- 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
- 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
- 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
- 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
- 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
- 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
- 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
- 0x9324fd72UL
- },
- {
- 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
- 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
- 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
- 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
- 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
- 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
- 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
- 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
- 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
- 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
- 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
- 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
- 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
- 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
- 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
- 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
- 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
- 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
- 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
- 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
- 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
- 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
- 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
- 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
- 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
- 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
- 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
- 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
- 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
- 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
- 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
- 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
- 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
- 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
- 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
- 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
- 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
- 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
- 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
- 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
- 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
- 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
- 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
- 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
- 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
- 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
- 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
- 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
- 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
- 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
- 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
- 0xbe9834edUL
- },
- {
- 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
- 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
- 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
- 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
- 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
- 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
- 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
- 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
- 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
- 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
- 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
- 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
- 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
- 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
- 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
- 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
- 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
- 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
- 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
- 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
- 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
- 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
- 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
- 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
- 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
- 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
- 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
- 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
- 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
- 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
- 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
- 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
- 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
- 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
- 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
- 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
- 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
- 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
- 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
- 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
- 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
- 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
- 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
- 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
- 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
- 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
- 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
- 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
- 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
- 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
- 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
- 0xde0506f1UL
- },
- {
- 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
- 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
- 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
- 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
- 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
- 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
- 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
- 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
- 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
- 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
- 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
- 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
- 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
- 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
- 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
- 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
- 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
- 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
- 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
- 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
- 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
- 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
- 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
- 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
- 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
- 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
- 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
- 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
- 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
- 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
- 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
- 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
- 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
- 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
- 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
- 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
- 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
- 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
- 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
- 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
- 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
- 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
- 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
- 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
- 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
- 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
- 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
- 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
- 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
- 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
- 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
- 0x8def022dUL
- },
- {
- 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
- 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
- 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
- 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
- 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
- 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
- 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
- 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
- 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
- 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
- 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
- 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
- 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
- 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
- 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
- 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
- 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
- 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
- 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
- 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
- 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
- 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
- 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
- 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
- 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
- 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
- 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
- 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
- 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
- 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
- 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
- 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
- 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
- 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
- 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
- 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
- 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
- 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
- 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
- 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
- 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
- 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
- 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
- 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
- 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
- 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
- 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
- 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
- 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
- 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
- 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
- 0x72fd2493UL
- },
- {
- 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
- 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
- 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
- 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
- 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
- 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
- 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
- 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
- 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
- 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
- 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
- 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
- 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
- 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
- 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
- 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
- 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
- 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
- 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
- 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
- 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
- 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
- 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
- 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
- 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
- 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
- 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
- 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
- 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
- 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
- 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
- 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
- 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
- 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
- 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
- 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
- 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
- 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
- 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
- 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
- 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
- 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
- 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
- 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
- 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
- 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
- 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
- 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
- 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
- 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
- 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
- 0xed3498beUL
- },
- {
- 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
- 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
- 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
- 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
- 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
- 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
- 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
- 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
- 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
- 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
- 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
- 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
- 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
- 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
- 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
- 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
- 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
- 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
- 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
- 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
- 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
- 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
- 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
- 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
- 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
- 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
- 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
- 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
- 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
- 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
- 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
- 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
- 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
- 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
- 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
- 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
- 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
- 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
- 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
- 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
- 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
- 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
- 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
- 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
- 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
- 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
- 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
- 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
- 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
- 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
- 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
- 0xf10605deUL
-#endif
- }
-};
diff --git a/crc32_simd.c b/crc32_simd.c
deleted file mode 100644
index c8e5592..0000000
--- a/crc32_simd.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/* crc32_simd.c
- *
- * Copyright 2017 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the Chromium source repository LICENSE file.
- */
-
-#include "crc32_simd.h"
-
-#if defined(CRC32_SIMD_SSE42_PCLMUL)
-
-/*
- * crc32_sse42_simd_(): compute the crc32 of the buffer, where the buffer
- * length must be at least 64, and a multiple of 16. Based on:
- *
- * "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction"
- * V. Gopal, E. Ozturk, et al., 2009, http://intel.ly/2ySEwL0
- */
-
-#include <emmintrin.h>
-#include <smmintrin.h>
-#include <wmmintrin.h>
-
-uint32_t ZLIB_INTERNAL crc32_sse42_simd_( /* SSE4.2+PCLMUL */
- const unsigned char *buf,
- z_size_t len,
- uint32_t crc)
-{
- /*
- * Definitions of the bit-reflected domain constants k1,k2,k3, etc and
- * the CRC32+Barrett polynomials given at the end of the paper.
- */
- static const uint64_t zalign(16) k1k2[] = { 0x0154442bd4, 0x01c6e41596 };
- static const uint64_t zalign(16) k3k4[] = { 0x01751997d0, 0x00ccaa009e };
- static const uint64_t zalign(16) k5k0[] = { 0x0163cd6124, 0x0000000000 };
- static const uint64_t zalign(16) poly[] = { 0x01db710641, 0x01f7011641 };
-
- __m128i x0, x1, x2, x3, x4, x5, x6, x7, x8, y5, y6, y7, y8;
-
- /*
- * There's at least one block of 64.
- */
- x1 = _mm_loadu_si128((__m128i *)(buf + 0x00));
- x2 = _mm_loadu_si128((__m128i *)(buf + 0x10));
- x3 = _mm_loadu_si128((__m128i *)(buf + 0x20));
- x4 = _mm_loadu_si128((__m128i *)(buf + 0x30));
-
- x1 = _mm_xor_si128(x1, _mm_cvtsi32_si128(crc));
-
- x0 = _mm_load_si128((__m128i *)k1k2);
-
- buf += 64;
- len -= 64;
-
- /*
- * Parallel fold blocks of 64, if any.
- */
- while (len >= 64)
- {
- x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
- x6 = _mm_clmulepi64_si128(x2, x0, 0x00);
- x7 = _mm_clmulepi64_si128(x3, x0, 0x00);
- x8 = _mm_clmulepi64_si128(x4, x0, 0x00);
-
- x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
- x2 = _mm_clmulepi64_si128(x2, x0, 0x11);
- x3 = _mm_clmulepi64_si128(x3, x0, 0x11);
- x4 = _mm_clmulepi64_si128(x4, x0, 0x11);
-
- y5 = _mm_loadu_si128((__m128i *)(buf + 0x00));
- y6 = _mm_loadu_si128((__m128i *)(buf + 0x10));
- y7 = _mm_loadu_si128((__m128i *)(buf + 0x20));
- y8 = _mm_loadu_si128((__m128i *)(buf + 0x30));
-
- x1 = _mm_xor_si128(x1, x5);
- x2 = _mm_xor_si128(x2, x6);
- x3 = _mm_xor_si128(x3, x7);
- x4 = _mm_xor_si128(x4, x8);
-
- x1 = _mm_xor_si128(x1, y5);
- x2 = _mm_xor_si128(x2, y6);
- x3 = _mm_xor_si128(x3, y7);
- x4 = _mm_xor_si128(x4, y8);
-
- buf += 64;
- len -= 64;
- }
-
- /*
- * Fold into 128-bits.
- */
- x0 = _mm_load_si128((__m128i *)k3k4);
-
- x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
- x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
- x1 = _mm_xor_si128(x1, x2);
- x1 = _mm_xor_si128(x1, x5);
-
- x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
- x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
- x1 = _mm_xor_si128(x1, x3);
- x1 = _mm_xor_si128(x1, x5);
-
- x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
- x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
- x1 = _mm_xor_si128(x1, x4);
- x1 = _mm_xor_si128(x1, x5);
-
- /*
- * Single fold blocks of 16, if any.
- */
- while (len >= 16)
- {
- x2 = _mm_loadu_si128((__m128i *)buf);
-
- x5 = _mm_clmulepi64_si128(x1, x0, 0x00);
- x1 = _mm_clmulepi64_si128(x1, x0, 0x11);
- x1 = _mm_xor_si128(x1, x2);
- x1 = _mm_xor_si128(x1, x5);
-
- buf += 16;
- len -= 16;
- }
-
- /*
- * Fold 128-bits to 64-bits.
- */
- x2 = _mm_clmulepi64_si128(x1, x0, 0x10);
- x3 = _mm_setr_epi32(~0, 0, ~0, 0);
- x1 = _mm_srli_si128(x1, 8);
- x1 = _mm_xor_si128(x1, x2);
-
- x0 = _mm_loadl_epi64((__m1