Skip to content

Commit

Permalink
zlib: update depends
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Sep 24, 2023
1 parent 86d584c commit b4d6f8b
Show file tree
Hide file tree
Showing 25 changed files with 376 additions and 259 deletions.
2 changes: 1 addition & 1 deletion lib/archive/version.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
brotli 1.1.0
liblzma: https://tukaani.org/xz/ 5.4.4
zstd: https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz#lib
zlib: https://github.com/chromium/chromium/tree/9b0deb8f9e201aa47961b933f5c5309027f3d226/third_party/zlib
zlib: https://github.com/chromium/chromium/tree/2a07f84b20d878592fc1262cc5bc5e73210a9f39/third_party/zlib
69 changes: 31 additions & 38 deletions lib/archive/zlib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -124,45 +124,40 @@ source_set("zlib_adler32_simd") {

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")
}
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_ios) {
defines += [ "ARMV8_OS_IOS" ]
} 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+aes+crc" ]
}
include_dirs = [ "." ]

sources = [
"crc32_simd.c",
"crc32_simd.h",
]
if (!is_win && !is_clang) {
assert(!use_thin_lto,
"ThinLTO fails mixing different module-level targets")
cflags_c = [ "-march=armv8-a+aes+crc" ]
}

sources = [
"crc32_simd.c",
"crc32_simd.h",
]

configs += [ ":zlib_internal_config" ]

public_configs = [ ":zlib_arm_crc32_config" ]
Expand Down Expand Up @@ -332,14 +327,6 @@ component("zlib") {
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",
Expand Down Expand Up @@ -398,6 +385,11 @@ config("minizip_warnings") {
}

static_library("minizip") {
include_dirs = [
".",
"//third_party/zlib",
]

sources = [
"contrib/minizip/ioapi.c",
"contrib/minizip/ioapi.h",
Expand Down Expand Up @@ -520,6 +512,7 @@ if (build_with_chromium) {
}

deps = [
":minizip",
":zlib",
"google:compression_utils",
"google:zip",
Expand Down
1 change: 1 addition & 0 deletions lib/archive/zlib/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ URL: http://zlib.net/
Version: 1.2.13
CPEPrefix: cpe:/a:zlib:zlib:1.2.13
Security Critical: yes
Shipped: yes
License: Custom license
License File: LICENSE
License Android Compatible: yes
Expand Down
4 changes: 2 additions & 2 deletions lib/archive/zlib/adler32.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
return adler | (sum2 << 16);
}

#if defined(ADLER32_SIMD_SSSE3)
#if defined(ADLER32_SIMD_SSSE3) || defined(ADLER32_SIMD_NEON)
/*
* Use SSSE3 to compute the adler32. Since this routine can be
* Use SIMD to compute the adler32. Since this function 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
Expand Down
1 change: 0 additions & 1 deletion lib/archive/zlib/contrib/bench/OWNERS

This file was deleted.

63 changes: 43 additions & 20 deletions lib/archive/zlib/contrib/bench/zlib_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ void check_file(const Data& file, zlib_wrapper type, int mode) {
error_exit("check file: error writing output", 3);
}

void zlib_file(const char* name, zlib_wrapper type, int width, int check) {
void zlib_file(const char* name,
zlib_wrapper type,
int width,
int check,
bool output_csv_format) {
/*
* Read the file data.
*/
Expand All @@ -257,7 +261,9 @@ void zlib_file(const char* name, zlib_wrapper type, int width, int check) {
* Report compression strategy and file name.
*/
const char* strategy = zlib_level_strategy_name(zlib_compression_level);
printf("%s%-40s :\n", strategy, name);
if (!output_csv_format) {
printf("%s%-40s :\n", strategy, name);
}

/*
* Chop the data into blocks.
Expand Down Expand Up @@ -329,19 +335,28 @@ void zlib_file(const char* name, zlib_wrapper type, int width, int check) {
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 %*d -> %*u %4.2f%%",
zlib_wrapper_name(type), block_size / (1 << 20), width, length, width,
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);
double deflate_rate_med, inflate_rate_med, deflate_rate_max, inflate_rate_max;
deflate_rate_med = length * repeats / mega_byte / ctime[runs / 2];
inflate_rate_med = length * repeats / mega_byte / utime[runs / 2];
deflate_rate_max = length * repeats / mega_byte / ctime[0];
inflate_rate_max = length * repeats / mega_byte / utime[0];
double compress_ratio = output_length * 100.0 / length;

if (!output_csv_format) {
// type, block size, compression ratio, etc
printf("%s: [b %dM] bytes %*d -> %*u %4.2f%%", zlib_wrapper_name(type),
block_size / (1 << 20), width, length, width,
unsigned(output_length), compress_ratio);

// 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);
} else {
printf("%s\t%.5lf\t%.5lf\t%.5lf\t%.5lf\t%.5lf\n", name, deflate_rate_med,
inflate_rate_med, deflate_rate_max, inflate_rate_max,
compress_ratio);
}
}

static int argn = 1;
Expand All @@ -363,8 +378,10 @@ void get_field_width(int argc, char* argv[], int& value) {
}

void usage_exit(const char* program) {
static auto* options = "gzip|zlib|raw"
" [--compression 0:9] [--huffman|--rle] [--field width] [--check]";
static auto* options =
"gzip|zlib|raw"
" [--compression 0:9] [--huffman|--rle] [--field width] [--check]"
" [--csv]";
printf("usage: %s %s files ...\n", program, options);
printf("zlib version: %s\n", ZLIB_VERSION);
exit(1);
Expand All @@ -383,7 +400,7 @@ int main(int argc, char* argv[]) {

int size_field_width = 0;
int file_check = 0;

bool output_csv = false;
while (argn < argc && argv[argn][0] == '-') {
if (get_option(argc, argv, "--compression")) {
if (!get_compression(argc, argv, zlib_compression_level))
Expand All @@ -398,6 +415,11 @@ int main(int argc, char* argv[]) {
file_check = 2;
} else if (get_option(argc, argv, "--field")) {
get_field_width(argc, argv, size_field_width);
} else if (get_option(argc, argv, "--csv")) {
output_csv = true;
printf(
"filename\tcompression\tdecompression\tcomp_max\t"
"decomp_max\tcompress_ratio\n");
} else {
usage_exit(argv[0]);
}
Expand All @@ -408,8 +430,9 @@ int main(int argc, char* argv[]) {

if (size_field_width < 6)
size_field_width = 6;
while (argn < argc)
zlib_file(argv[argn++], type, size_field_width, file_check);
while (argn < argc) {
zlib_file(argv[argn++], type, size_field_width, file_check, output_csv);
}

return 0;
}
5 changes: 5 additions & 0 deletions lib/archive/zlib/contrib/minizip/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Short Name: minizip
URL: https://github.com/madler/zlib/tree/master/contrib/minizip
Version: 1.2.12
License: Zlib
License File: //third_party/zlib/LICENSE
Security Critical: yes
Shipped: yes

Description:
Minizip provides API on top of zlib that can enumerate and extract ZIP archive
Expand All @@ -13,3 +15,6 @@ Local Modifications:
- Add parsing of the 'Info-ZIP Unicode Path Extra Field' as described in
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT section 4.6.9.
(see crrev.com/1002476)

- Check for overly long filename, comment, or extra field in
zipOpenNewFileInZip4_64 (crbug.com/1470539).
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/ioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include <stdio.h>
#include <stdlib.h>
#include "third_party/zlib/zlib.h"
#include "zlib.h"

#if defined(USE_FILE32API)
#define fopen64 fopen
Expand Down
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/mztools.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "third_party/zlib/zlib.h"
#include "zlib.h"
#include "unzip.h"

#define READ_8(adr) ((unsigned char)*(adr))
Expand Down
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/mztools.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
#endif

#ifndef _ZLIB_H
#include "third_party/zlib/zlib.h"
#include "zlib.h"
#endif

#include "unzip.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#include <stdlib.h>
#include <string.h>

#include "third_party/zlib/zlib.h"
#include "zlib.h"
#include "unzip.h"

#ifdef STDC
Expand Down
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/unzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
#endif

#ifndef _ZLIB_H
#include "third_party/zlib/zlib.h"
#include "zlib.h"
#endif

#ifndef _ZLIBIOAPI_H
Expand Down
13 changes: 12 additions & 1 deletion lib/archive/zlib/contrib/minizip/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "third_party/zlib/zlib.h"
#include "zlib.h"
#include "zip.h"

#ifdef STDC
Expand Down Expand Up @@ -1083,6 +1083,17 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
return ZIP_PARAMERROR;
#endif

// The filename and comment length must fit in 16 bits.
if ((filename!=NULL) && (strlen(filename)>0xffff))
return ZIP_PARAMERROR;
if ((comment!=NULL) && (strlen(comment)>0xffff))
return ZIP_PARAMERROR;
// The extra field length must fit in 16 bits. If the member also requires
// a Zip64 extra block, that will also need to fit within that 16-bit
// length, but that will be checked for later.
if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
return ZIP_PARAMERROR;

zi = (zip64_internal*)file;

if (zi->in_opened_file_inzip == 1)
Expand Down
2 changes: 1 addition & 1 deletion lib/archive/zlib/contrib/minizip/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C" {
//#define HAVE_BZIP2

#ifndef _ZLIB_H
#include "third_party/zlib/zlib.h"
#include "zlib.h"
#endif

#ifndef _ZLIBIOAPI_H
Expand Down
5 changes: 3 additions & 2 deletions lib/archive/zlib/contrib/optimizations/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,9 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
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));
window = (unsigned char FAR *)ZALLOC(
source, (1U << state->wbits) + CHUNKCOPY_CHUNK_SIZE,
sizeof(unsigned char));
if (window == Z_NULL) {
ZFREE(source, copy);
return Z_MEM_ERROR;
Expand Down
1 change: 1 addition & 0 deletions lib/archive/zlib/contrib/tests/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+testing/gtest",
"+third_party/zlib/contrib/minizip",
"+base",
]
9 changes: 9 additions & 0 deletions lib/archive/zlib/contrib/tests/standalone_test_runner.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the Chromium source repository LICENSE file.
#include <gtest/gtest.h>

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading

0 comments on commit b4d6f8b

Please sign in to comment.