diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-24 11:30:15 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-30 12:56:19 +0000 |
commit | 6036726eb981b6c4b42047513b9d3f4ac865daac (patch) | |
tree | 673593e70678e7789766d1f732eb51f613a2703b /chromium/third_party/zlib | |
parent | 466052c4e7c052268fd931888cd58961da94c586 (diff) | |
download | qtwebengine-chromium-6036726eb981b6c4b42047513b9d3f4ac865daac.tar.gz |
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/zlib')
-rw-r--r-- | chromium/third_party/zlib/BUILD.gn | 7 | ||||
-rw-r--r-- | chromium/third_party/zlib/contrib/bench/zlib_bench.cc | 63 | ||||
-rw-r--r-- | chromium/third_party/zlib/contrib/minizip/unzip.c | 5 | ||||
-rw-r--r-- | chromium/third_party/zlib/contrib/optimizations/slide_hash_neon.h | 65 | ||||
-rw-r--r-- | chromium/third_party/zlib/crc32_simd.c | 49 | ||||
-rw-r--r-- | chromium/third_party/zlib/crc32_simd.h | 6 | ||||
-rw-r--r-- | chromium/third_party/zlib/deflate.c | 94 | ||||
-rw-r--r-- | chromium/third_party/zlib/deflate.h | 25 | ||||
-rw-r--r-- | chromium/third_party/zlib/google/zip_reader.cc | 7 | ||||
-rw-r--r-- | chromium/third_party/zlib/google/zip_reader.h | 4 | ||||
-rw-r--r-- | chromium/third_party/zlib/google/zip_reader_unittest.cc | 17 | ||||
-rw-r--r-- | chromium/third_party/zlib/trees.c | 50 |
12 files changed, 298 insertions, 94 deletions
diff --git a/chromium/third_party/zlib/BUILD.gn b/chromium/third_party/zlib/BUILD.gn index 902e287f8a0..b44bda66a1e 100644 --- a/chromium/third_party/zlib/BUILD.gn +++ b/chromium/third_party/zlib/BUILD.gn @@ -78,7 +78,7 @@ if (current_cpu == "arm" || current_cpu == "arm64") { source_set("zlib_arm_crc32") { visibility = [ ":*" ] - if (!is_ios && !is_chromeos && !is_fuchsia) { + if (is_clang && (!is_ios && !is_chromeos && !is_fuchsia)) { include_dirs = [ "." ] if (is_android) { @@ -97,10 +97,6 @@ if (current_cpu == "arm" || current_cpu == "arm64") { "crc32_simd.h", ] - if (!is_win || is_clang) { - cflags_c = [ "-march=armv8-a+crc" ] - } - if (!is_debug) { configs -= [ "//build/config/compiler:default_optimization" ] configs += [ "//build/config/compiler:optimize_speed" ] @@ -283,6 +279,7 @@ static_library("zlib") { deps += [ ":zlib_inflate_chunk_simd" ] sources -= [ "inflate.c" ] + sources += [ "contrib/optimizations/slide_hash_neon.h" ] } } diff --git a/chromium/third_party/zlib/contrib/bench/zlib_bench.cc b/chromium/third_party/zlib/contrib/bench/zlib_bench.cc index b2954e64bed..452e42e6929 100644 --- a/chromium/third_party/zlib/contrib/bench/zlib_bench.cc +++ b/chromium/third_party/zlib/contrib/bench/zlib_bench.cc @@ -112,6 +112,7 @@ void zlib_compress( const char* input, const size_t input_size, std::string* output, + const int compression_level, bool resize_output = false) { if (resize_output) @@ -121,7 +122,7 @@ void zlib_compress( z_stream stream; memset(&stream, 0, sizeof(stream)); - int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, + int result = deflateInit2(&stream, compression_level, Z_DEFLATED, zlib_stream_wrapper_type(type), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (result != Z_OK) error_exit("deflateInit2 failed", result); @@ -181,7 +182,8 @@ void verify_equal(const char* input, size_t size, std::string* output) { exit(3); } -void zlib_file(const char* name, const zlib_wrapper type) { +void zlib_file(const char* name, const zlib_wrapper type, + const int compression_level) { /* * Read the file data. */ @@ -229,13 +231,15 @@ void zlib_file(const char* name, const zlib_wrapper type) { 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]); + zlib_compress(type, input[b], input_length[b], &compressed[b], + compression_level); 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); + zlib_compress(type, input[b], input_length[b], &compressed[b], + compression_level, true); for (int b = 0; b < blocks; ++b) output[b].resize(input_length[b]); @@ -277,22 +281,57 @@ void zlib_file(const char* name, const zlib_wrapper type) { int main(int argc, char* argv[]) { zlib_wrapper type = kWrapperNONE; + int file_index = 3; + // DEFAULT is equivalent to level 6. Compression level ranges from 1 to 9, + // being 0 used for Z_NO_COMPRESSION. + int compression_level = Z_DEFAULT_COMPRESSION; + + auto help_msg_exit = [&argv] { + printf("usage: %s -wrapper gzip|zlib|raw -compression [0:9] files...\n", argv[0]); + exit(1); + }; + + // If no arguments were passed, print usage and exit. + if (argc == 1) + help_msg_exit(); if (argc > 1) { - if (!strcmp(argv[1], "zlib")) + if (strcmp(argv[1], "-wrapper") || !(strcmp(argv[1], "-h")) || + !(strcmp(argv[1], "--help"))) + help_msg_exit(); + + // Got check the argument count before reading. + if (argc < 3) + help_msg_exit(); + + if (!strcmp(argv[2], "zlib")) type = kWrapperZLIB; - else if (!strcmp(argv[1], "gzip")) + else if (!strcmp(argv[2], "gzip")) type = kWrapperGZIP; - else if (!strcmp(argv[1], "raw")) + else if (!strcmp(argv[2], "raw")) type = kWrapperZRAW; + else + help_msg_exit(); + } + + if (argc >= 4) { + if (!strcmp(argv[3], "-compression")) { + int user_level = atoi(argv[4]); + if ((user_level <= 9) && (user_level >= 0)) { + compression_level = user_level; + file_index = 5; + } else + help_msg_exit(); + } } if ((type != kWrapperNONE) && (argc > 2)) { - for (int file = 2; file < argc; ++file) - zlib_file(argv[file], type); - return 0; + while (file_index < argc) { + // TODO: return a status (e.g. success | fail). + zlib_file(argv[file_index], type, compression_level); + ++file_index; + } } - printf("usage: %s gzip|zlib|raw files...\n", argv[0]); - return 1; + return 0; } diff --git a/chromium/third_party/zlib/contrib/minizip/unzip.c b/chromium/third_party/zlib/contrib/minizip/unzip.c index 199b4723fcf..e8b2bc5c766 100644 --- a/chromium/third_party/zlib/contrib/minizip/unzip.c +++ b/chromium/third_party/zlib/contrib/minizip/unzip.c @@ -68,10 +68,6 @@ #include <stdlib.h> #include <string.h> -#ifndef NOUNCRYPT - #define NOUNCRYPT -#endif - #include "third_party/zlib/zlib.h" #include "unzip.h" @@ -1630,6 +1626,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, 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 diff --git a/chromium/third_party/zlib/contrib/optimizations/slide_hash_neon.h b/chromium/third_party/zlib/contrib/optimizations/slide_hash_neon.h new file mode 100644 index 00000000000..26995d70f70 --- /dev/null +++ b/chromium/third_party/zlib/contrib/optimizations/slide_hash_neon.h @@ -0,0 +1,65 @@ +/* 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/chromium/third_party/zlib/crc32_simd.c b/chromium/third_party/zlib/crc32_simd.c index f5d9dd89ac2..03698adf752 100644 --- a/chromium/third_party/zlib/crc32_simd.c +++ b/chromium/third_party/zlib/crc32_simd.c @@ -160,8 +160,34 @@ uint32_t ZLIB_INTERNAL crc32_sse42_simd_( /* SSE4.2+PCLMUL */ * * TODO: implement a version using the PMULL instruction. */ -#include <arm_acle.h> +/* CRC32 intrinsics are #ifdef'ed out of arm_acle.h unless we build with an + * armv8 target, which is incompatible with ThinLTO optimizations on Android. + * (Namely, mixing and matching different module-level targets makes ThinLTO + * warn, and Android defaults to armv7-a. This restriction does not apply to + * function-level `target`s, however.) + * + * Since we only need three crc intrinsics, and since clang's implementation of + * those are just wrappers around compiler builtins, it's simplest to #define + * those builtins directly. If this #define list grows too much (or we depend on + * an intrinsic that isn't a trivial wrapper), we may have to find a better way + * to go about this. + * + * NOTE: clang currently complains that "'+soft-float-abi' is not a recognized + * feature for this target (ignoring feature)." This appears to be a harmless + * bug in clang. + */ +#define __crc32b __builtin_arm_crc32b +#define __crc32d __builtin_arm_crc32d +#define __crc32w __builtin_arm_crc32w + +#if defined(__aarch64__) +#define TARGET_ARMV8_WITH_CRC __attribute__((target("crc"))) +#else +#define TARGET_ARMV8_WITH_CRC __attribute__((target("armv8-a,crc"))) +#endif + +TARGET_ARMV8_WITH_CRC uint32_t ZLIB_INTERNAL armv8_crc32_little(unsigned long crc, const unsigned char *buf, z_size_t len) @@ -202,4 +228,25 @@ uint32_t ZLIB_INTERNAL armv8_crc32_little(unsigned long crc, return ~c; } +TARGET_ARMV8_WITH_CRC +Pos ZLIB_INTERNAL insert_string_arm(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; + + h = __crc32w(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 diff --git a/chromium/third_party/zlib/crc32_simd.h b/chromium/third_party/zlib/crc32_simd.h index d3d0bce7446..08f175617c5 100644 --- a/chromium/third_party/zlib/crc32_simd.h +++ b/chromium/third_party/zlib/crc32_simd.h @@ -9,6 +9,7 @@ #include "zconf.h" #include "zutil.h" +#include "deflate.h" /* * crc32_sse42_simd_(): compute the crc32 of the buffer, where the buffer @@ -33,3 +34,8 @@ uint32_t ZLIB_INTERNAL armv8_crc32_little(unsigned long crc, const unsigned char* buf, z_size_t len); +/* + * Insert hash string. + */ +Pos ZLIB_INTERNAL insert_string_arm(deflate_state *const s, const Pos str); + diff --git a/chromium/third_party/zlib/deflate.c b/chromium/third_party/zlib/deflate.c index 6fe9c7e09de..471fb198177 100644 --- a/chromium/third_party/zlib/deflate.c +++ b/chromium/third_party/zlib/deflate.c @@ -52,6 +52,17 @@ #include "deflate.h" #include "x86.h" +#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) +#include "contrib/optimizations/slide_hash_neon.h" +#endif +/* We need crypto extension crc32 to implement optimized hash in + * insert_string. + */ +#if defined(CRC32_ARMV8_CRC32) +#include "arm_features.h" +#include "crc32_simd.h" +#endif + const char deflate_copyright[] = " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; /* @@ -204,12 +215,16 @@ local INLINE Pos insert_string_c(deflate_state *const s, const Pos str) local INLINE Pos insert_string(deflate_state *const s, const Pos str) { +#if defined(CRC32_ARMV8_CRC32) + if (arm_cpu_enable_crc32) + return insert_string_arm(s, str); +#endif if (x86_cpu_enable_simd) return insert_string_sse(s, str); + return insert_string_c(s, str); } - /* =========================================================================== * Initialize the hash table (avoiding 64K overflow for 16 bit systems). * prev[] will be initialized on the fly. @@ -226,6 +241,10 @@ local INLINE Pos insert_string(deflate_state *const s, const Pos str) local void slide_hash(s) deflate_state *s; { +#if (defined(__ARM_NEON__) || defined(__ARM_NEON)) + /* NEON based hash table rebase. */ + return neon_slide_hash(s->head, s->prev, s->w_size, s->hash_size); +#endif unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -278,11 +297,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, int wrap = 1; static const char my_version[] = ZLIB_VERSION; - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - x86_check_features(); if (version == Z_NULL || version[0] != my_version[0] || @@ -361,9 +375,46 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + /* We overlay pending_buf and sym_buf. This works since the average size + * for length/distance pairs over any compressed block is assured to be 31 + * bits or less. + * + * Analysis: The longest fixed codes are a length code of 8 bits plus 5 + * extra bits, for lengths 131 to 257. The longest fixed distance codes are + * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest + * possible fixed-codes length/distance pair is then 31 bits total. + * + * sym_buf starts one-fourth of the way into pending_buf. So there are + * three bytes in sym_buf for every four bytes in pending_buf. Each symbol + * in sym_buf is three bytes -- two for the distance and one for the + * literal/length. As each symbol is consumed, the pointer to the next + * sym_buf value to read moves forward three bytes. From that symbol, up to + * 31 bits are written to pending_buf. The closest the written pending_buf + * bits gets to the next sym_buf symbol to read is just before the last + * code is written. At that time, 31*(n-2) bits have been written, just + * after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at + * 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1 + * symbols are written.) The closest the writing gets to what is unread is + * then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and + * can range from 128 to 32768. + * + * Therefore, at a minimum, there are 142 bits of space between what is + * written and what is read in the overlain buffers, so the symbols cannot + * be overwritten by the compressed data. That space is actually 139 bits, + * due to the three-bit fixed-code block header. + * + * That covers the case where either Z_FIXED is specified, forcing fixed + * codes, or when the use of fixed codes is chosen, because that choice + * results in a smaller compressed block than dynamic codes. That latter + * condition then assures that the above analysis also covers all dynamic + * blocks. A dynamic-code block will only be chosen to be emitted if it has + * fewer bits than a fixed-code block would for the same set of symbols. + * Therefore its average symbol length is assured to be less than 31. So + * the compressed data for a dynamic block also cannot overwrite the + * symbols from which it is being constructed. + */ + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); + s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { @@ -372,8 +423,12 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, deflateEnd (strm); return Z_MEM_ERROR; } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + s->sym_buf = s->pending_buf + s->lit_bufsize; + s->sym_end = (s->lit_bufsize - 1) * 3; + /* We avoid equality with lit_bufsize*3 because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ s->level = level; s->strategy = strategy; @@ -580,7 +635,7 @@ int ZEXPORT deflatePrime (strm, bits, value) if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; - if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) + if (s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; do { put = Buf_size - s->bi_valid; @@ -1140,7 +1195,6 @@ int ZEXPORT deflateCopy (dest, source) #else deflate_state *ds; deflate_state *ss; - ushf *overlay; if (deflateStateCheck(source) || dest == Z_NULL) { @@ -1160,8 +1214,7 @@ int ZEXPORT deflateCopy (dest, source) ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1175,8 +1228,7 @@ int ZEXPORT deflateCopy (dest, source) zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + ds->sym_buf = ds->pending_buf + ds->lit_bufsize; ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; @@ -1957,7 +2009,7 @@ local block_state deflate_fast(s, flush) FLUSH_BLOCK(s, 1); return finish_done; } - if (s->last_lit) + if (s->sym_next) FLUSH_BLOCK(s, 0); return block_done; } @@ -2088,7 +2140,7 @@ local block_state deflate_slow(s, flush) FLUSH_BLOCK(s, 1); return finish_done; } - if (s->last_lit) + if (s->sym_next) FLUSH_BLOCK(s, 0); return block_done; } @@ -2163,7 +2215,7 @@ local block_state deflate_rle(s, flush) FLUSH_BLOCK(s, 1); return finish_done; } - if (s->last_lit) + if (s->sym_next) FLUSH_BLOCK(s, 0); return block_done; } @@ -2202,7 +2254,7 @@ local block_state deflate_huff(s, flush) FLUSH_BLOCK(s, 1); return finish_done; } - if (s->last_lit) + if (s->sym_next) FLUSH_BLOCK(s, 0); return block_done; } diff --git a/chromium/third_party/zlib/deflate.h b/chromium/third_party/zlib/deflate.h index ab56df7663b..6838296a0e3 100644 --- a/chromium/third_party/zlib/deflate.h +++ b/chromium/third_party/zlib/deflate.h @@ -217,7 +217,7 @@ typedef struct internal_state { /* Depth of each subtree used as tie breaker for trees of equal frequency */ - uchf *l_buf; /* buffer for literals or lengths */ + uchf *sym_buf; /* buffer for distances and literals/lengths */ uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,13 +239,8 @@ typedef struct internal_state { * - I can't count above 4 */ - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ + uInt sym_next; /* running index in sym_buf */ + uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ ulg static_len; /* bit length of current block with static trees */ @@ -325,20 +320,22 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ + s->sym_buf[s->sym_next++] = 0; \ + s->sym_buf[s->sym_next++] = 0; \ + s->sym_buf[s->sym_next++] = cc; \ s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ + flush = (s->sym_next == s->sym_end); \ } # define _tr_tally_dist(s, distance, length, flush) \ { uch len = (uch)(length); \ ush dist = (ush)(distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ + s->sym_buf[s->sym_next++] = dist; \ + s->sym_buf[s->sym_next++] = dist >> 8; \ + s->sym_buf[s->sym_next++] = len; \ dist--; \ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ + flush = (s->sym_next == s->sym_end); \ } #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) diff --git a/chromium/third_party/zlib/google/zip_reader.cc b/chromium/third_party/zlib/google/zip_reader.cc index 207683c004e..63d23195a0d 100644 --- a/chromium/third_party/zlib/google/zip_reader.cc +++ b/chromium/third_party/zlib/google/zip_reader.cc @@ -89,7 +89,9 @@ void StringWriterDelegate::SetTimeModified(const base::Time& time) { ZipReader::EntryInfo::EntryInfo(const std::string& file_name_in_zip, const unz_file_info& raw_file_info) : file_path_(base::FilePath::FromUTF8Unsafe(file_name_in_zip)), - is_directory_(false) { + is_directory_(false), + is_unsafe_(false), + is_encrypted_(false) { original_size_ = raw_file_info.uncompressed_size; // Directory entries in zip files end with "/". @@ -113,6 +115,9 @@ ZipReader::EntryInfo::EntryInfo(const std::string& file_name_in_zip, base::CompareCase::INSENSITIVE_ASCII)) is_unsafe_ = true; + // Whether the file is encrypted is bit 0 of the flag. + is_encrypted_ = raw_file_info.flag & 1; + // Construct the last modified time. The timezone info is not present in // zip files, so we construct the time as local time. base::Time::Exploded exploded_time = {}; // Zero-clear. diff --git a/chromium/third_party/zlib/google/zip_reader.h b/chromium/third_party/zlib/google/zip_reader.h index cd24075ec80..d44fc8bdf7f 100644 --- a/chromium/third_party/zlib/google/zip_reader.h +++ b/chromium/third_party/zlib/google/zip_reader.h @@ -107,12 +107,16 @@ class ZipReader { // UTF-8 characters in its file name, or the file path is absolute. bool is_unsafe() const { return is_unsafe_; } + // Returns true if the entry is encrypted. + bool is_encrypted() const { return is_encrypted_; } + private: const base::FilePath file_path_; int64_t original_size_; base::Time last_modified_; bool is_directory_; bool is_unsafe_; + bool is_encrypted_; DISALLOW_COPY_AND_ASSIGN(EntryInfo); }; diff --git a/chromium/third_party/zlib/google/zip_reader_unittest.cc b/chromium/third_party/zlib/google/zip_reader_unittest.cc index dabe9f68b0f..7eba1229149 100644 --- a/chromium/third_party/zlib/google/zip_reader_unittest.cc +++ b/chromium/third_party/zlib/google/zip_reader_unittest.cc @@ -149,6 +149,7 @@ class ZipReaderTest : public PlatformTest { ASSERT_TRUE(GetTestDataDirectory(&test_data_dir_)); test_zip_file_ = test_data_dir_.AppendASCII("test.zip"); + encrypted_zip_file_ = test_data_dir_.AppendASCII("test_encrypted.zip"); evil_zip_file_ = test_data_dir_.AppendASCII("evil.zip"); evil_via_invalid_utf8_zip_file_ = test_data_dir_.AppendASCII( "evil_via_invalid_utf8.zip"); @@ -201,6 +202,8 @@ class ZipReaderTest : public PlatformTest { base::FilePath test_data_dir_; // The path to test.zip in the test data directory. base::FilePath test_zip_file_; + // The path to test_encrypted.zip in the test data directory. + base::FilePath encrypted_zip_file_; // The path to evil.zip in the test data directory. base::FilePath evil_zip_file_; // The path to evil_via_invalid_utf8.zip in the test data directory. @@ -366,6 +369,20 @@ TEST_F(ZipReaderTest, current_entry_info_Directory) { EXPECT_TRUE(current_entry_info->is_directory()); } +TEST_F(ZipReaderTest, current_entry_info_EncryptedFile) { + ZipReader reader; + base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); + + ASSERT_TRUE(reader.Open(encrypted_zip_file_)); + ASSERT_TRUE(LocateAndOpenEntry(&reader, target_path)); + EXPECT_TRUE(reader.current_entry_info()->is_encrypted()); + reader.Close(); + + ASSERT_TRUE(reader.Open(test_zip_file_)); + ASSERT_TRUE(LocateAndOpenEntry(&reader, target_path)); + EXPECT_FALSE(reader.current_entry_info()->is_encrypted()); +} + // Verifies that the ZipReader class can extract a file from a zip archive // stored in memory. This test opens a zip archive in a std::string object, // extracts its content, and verifies the content is the same as the expected diff --git a/chromium/third_party/zlib/trees.c b/chromium/third_party/zlib/trees.c index 50cf4b4571c..5f89d056ef9 100644 --- a/chromium/third_party/zlib/trees.c +++ b/chromium/third_party/zlib/trees.c @@ -416,7 +416,7 @@ local void init_block(s) s->dyn_ltree[END_BLOCK].Freq = 1; s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; + s->sym_next = s->matches = 0; } #define SMALLEST 1 @@ -947,7 +947,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); + s->sym_next / 3)); if (static_lenb <= opt_lenb) opt_lenb = static_lenb; @@ -1016,8 +1016,9 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc) unsigned dist; /* distance of matched string */ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ { - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; + s->sym_buf[s->sym_next++] = dist; + s->sym_buf[s->sym_next++] = dist >> 8; + s->sym_buf[s->sym_next++] = lc; if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; @@ -1032,30 +1033,7 @@ int ZLIB_INTERNAL _tr_tally (s, dist, lc) s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_dtree[d_code(dist)].Freq++; } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ + return (s->sym_next == s->sym_end); } /* =========================================================================== @@ -1068,13 +1046,14 @@ local void compress_block(s, ltree, dtree) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ + unsigned sx = 0; /* running index in sym_buf */ unsigned code; /* the code to send */ int extra; /* number of extra bits to send */ - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; + if (s->sym_next != 0) do { + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; if (dist == 0) { send_code(s, lc, ltree); /* send a literal byte */ Tracecv(isgraph(lc), (stderr," '%c' ", lc)); @@ -1099,11 +1078,10 @@ local void compress_block(s, ltree, dtree) } } /* literal or match pair ? */ - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, - "pendingBuf overflow"); + /* Check that the overlay between pending_buf and sym_buf is ok: */ + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - } while (lx < s->last_lit); + } while (sx < s->sym_next); send_code(s, END_BLOCK, ltree); } |