Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,158 @@
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c
index 782d32469ae5d..a38881dca90a2 100644
--- a/contrib/minizip/ioapi.c
+++ b/contrib/minizip/ioapi.c
@@ -14,7 +14,7 @@
#define _CRT_SECURE_NO_WARNINGS
#endif
-#if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
+#if defined(__APPLE__) || defined(__Fuchsia__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_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)
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
index 08536e94b8a28..bbd7773e67146 100644
--- a/contrib/minizip/iowin32.c
+++ b/contrib/minizip/iowin32.c
@@ -25,7 +25,12 @@
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
#endif
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x601
+#endif
+#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
// see Include/shared/winapifamily.h in the Windows Kit
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
@@ -37,6 +42,7 @@
#define IOWIN32_USING_WINRT_API 1
#endif
#endif
+#endif
typedef struct
{
diff --git a/gzread.c b/gzread.c
index 956b91ea7d9e..832d3ef98c59 100644
--- a/gzread.c
+++ b/gzread.c
@@ -443,7 +443,11 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
# undef z_gzgetc
#else
# undef gzgetc
+# ifdef Z_CR_PREFIX_SET
+# define gzgetc Cr_z_gzgetc
+# endif
#endif
+
int ZEXPORT gzgetc(file)
gzFile file;
{
diff --git a/zconf.h b/zconf.h
index 5e1d68a004e9..a7a815f575a7 100644
--- a/zconf.h
+++ b/zconf.h
@@ -8,6 +8,10 @@
#ifndef ZCONF_H
#define ZCONF_H
+/*
+ * This library is also built as a part of AOSP, which does not need to include
+ * chromeconf.h. This config does not want chromeconf.h, so it can set this
+ * macro to opt out. While this works today, there's no guarantee that building
+ * zlib outside of Chromium keeps working in the future.
+ */
+#if !defined(CHROMIUM_ZLIB_NO_CHROMECONF)
+/* This include does prefixing as below, but with an updated set of names. Also
+ * sets up export macros in component builds. */
+#include "chromeconf.h"
+#endif
+
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
@@ -431,7 +434,7 @@ typedef uLong FAR uLongf;
typedef unsigned long z_crc_t;
#endif
-#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
+#if !defined(_WIN32)
# define Z_HAVE_UNISTD_H
#endif
diff --git a/zlib.h b/zlib.h
index f09cdaf1e054..99fd467f6b1a 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1824,6 +1824,11 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# undef z_gzgetc
# define z_gzgetc(g) \
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
+#elif defined(Z_CR_PREFIX_SET)
+# undef gzgetc
+# define gzgetc(g) \
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) \
+ : (Cr_z_gzgetc)(g))
#else
# define gzgetc(g) \
((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
@@ -1853,11 +1858,29 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
# define z_adler32_combine z_adler32_combine64
# define z_crc32_combine z_crc32_combine64
# else
+# ifdef gzopen
+# undef gzopen
+# endif
# define gzopen gzopen64
+# ifdef gzseek
+# undef gzseek
+# endif
# define gzseek gzseek64
+# ifdef gztell
+# undef gztell
+# endif
# define gztell gztell64
+# ifdef gzoffset
+# undef gzoffset
+# endif
# define gzoffset gzoffset64
+# ifdef adler32_combine
+# undef adler32_combine
+# endif
# define adler32_combine adler32_combine64
+# ifdef crc32_combine
+# undef crc32_combine
+# endif
# define crc32_combine crc32_combine64
# endif
# ifndef Z_LARGE64
diff --git a/zutil.h b/zutil.h
index b079ea6a80f5..80375b8b6109 100644
--- a/zutil.h
+++ b/zutil.h
@@ -28,6 +28,21 @@
# include <string.h>
# include <stdlib.h>
#endif
+#ifdef NO_ERRNO_H
+# ifdef _WIN32_WCE
+ /* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used. We rename it to
+ * avoid conflict with other libraries that use the same workaround.
+ */
+# define errno z_errno
+# endif
+ extern int errno;
+#else
+# ifndef _WIN32_WCE
+# include <errno.h>
+# endif
+#endif
#ifdef Z_SOLO
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
From 1a03e7aec95d89c659fd91f195b99893b6458cd7 Mon Sep 17 00:00:00 2001
From: Adenilson Cavalcanti <adenilson.cavalcanti@arm.com>
Date: Wed, 27 Sep 2017 13:59:04 -0700
Subject: [PATCH] Zlib patch: prevent uninitialized use of state->check
No need to call the Adler32 checksum function, just set
the struct field to the expected value.
Upstream bug: madler/zlib#245
---
third_party/zlib/inflate.c | 2 +-
1 files changed, 1 insertion(+), 1 deletions(-)
delete mode 100644 third_party/zlib/patches/0002-uninitializedcheck.patch
diff --git a/third_party/zlib/inflate.c b/third_party/zlib/inflate.c
index bec9497..5c40cf1 100644
--- a/third_party/zlib/inflate.c
+++ b/third_party/zlib/inflate.c
@@ -228,7 +228,7 @@ int stream_size;
state->strm = strm;
state->window = Z_NULL;
state->mode = HEAD; /* to pass state test in inflateReset2() */
- state->check = adler32(0L, Z_NULL, 0);
+ state->check = 1L; /* 1L is the result of adler32() zero length data */
ret = inflateReset2(strm, windowBits);
if (ret != Z_OK) {
ZFREE(strm, state);

View File

@ -0,0 +1,15 @@
diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c
index a39e62787862..c6053fd1c7ea 100644
--- a/third_party/zlib/deflate.c
+++ b/third_party/zlib/deflate.c
@@ -318,6 +318,10 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s->w_size + window_padding,
2*sizeof(Byte));
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
+ /* Avoid use of uninitialized value, see:
+ * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11360
+ */
+ zmemzero(s->prev, s->w_size * sizeof(Pos));
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
s->high_water = 0; /* nothing written to s->window yet */

View File

@ -0,0 +1,27 @@
diff --git a/third_party/zlib/contrib/minizip/iowin32.c b/third_party/zlib/contrib/minizip/iowin32.c
index bbd7773e67146..3f6867fd7e40b 100644
--- a/third_party/zlib/contrib/minizip/iowin32.c
+++ b/third_party/zlib/contrib/minizip/iowin32.c
@@ -30,19 +30,12 @@
#define _WIN32_WINNT 0x601
#endif
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-// see Include/shared/winapifamily.h in the Windows Kit
-#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
-
-#if !defined(WINAPI_FAMILY_ONE_PARTITION)
-#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition)
-#endif
-
-#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
+#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
-#endif
typedef struct
{

View File

@ -0,0 +1,405 @@
From 409594639f15d825202971db7a275023e05772ff Mon Sep 17 00:00:00 2001
From: Adenilson Cavalcanti <adenilson.cavalcanti@arm.com>
Date: Tue, 28 Apr 2020 10:48:01 -0700
Subject: [PATCH] Local Changes: - make C tests build as C++ code so we can
use gtest. - use gtest EXPECT_TRUE instead of C assert. - replace C
streams for C++ (portability issues).
---
test/infcover.c | 167 ++++++++++++++++++++++++++----------------------
1 file changed, 90 insertions(+), 77 deletions(-)
diff --git a/test/infcover.c b/test/infcover.c
index 2be0164..a8c51c7 100644
--- a/test/infcover.c
+++ b/test/infcover.c
@@ -4,11 +4,12 @@
*/
/* to use, do: ./configure --cover && make cover */
-
+// clang-format off
+#include "infcover.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
+
#include "zlib.h"
/* get definition of internal structure so we can mess with it (see pull()),
@@ -17,8 +18,22 @@
#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 -- */
/*
@@ -72,7 +87,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
{
void *ptr;
struct mem_item *item;
- struct mem_zone *zone = mem;
+ struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
size_t len = count * (size_t)size;
/* induced allocation failure */
@@ -87,7 +102,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
memset(ptr, 0xa5, len);
/* create a new item for the list */
- item = malloc(sizeof(struct mem_item));
+ item = static_cast<struct mem_item *>(malloc(sizeof(struct mem_item)));
if (item == NULL) {
free(ptr);
return NULL;
@@ -112,7 +127,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
local void mem_free(void *mem, void *ptr)
{
struct mem_item *item, *next;
- struct mem_zone *zone = mem;
+ struct mem_zone *zone = static_cast<struct mem_zone *>(mem);
/* if no zone, just do a free */
if (zone == NULL) {
@@ -159,7 +174,7 @@ local void mem_setup(z_stream *strm)
{
struct mem_zone *zone;
- zone = malloc(sizeof(struct mem_zone));
+ zone = static_cast<struct mem_zone *>(malloc(sizeof(struct mem_zone)));
assert(zone != NULL);
zone->first = NULL;
zone->total = 0;
@@ -175,33 +190,33 @@ local void mem_setup(z_stream *strm)
/* 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 = strm->opaque;
+ 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, char *prefix)
+local void mem_used(z_stream *strm, const char *prefix)
{
- struct mem_zone *zone = strm->opaque;
+ struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
- fprintf(stderr, "%s: %lu allocated\n", prefix, zone->total);
+ std::cout << prefix << ": " << zone->total << " allocated" << std::endl;
}
/* show the high water allocation in bytes */
-local void mem_high(z_stream *strm, char *prefix)
+local void mem_high(z_stream *strm, const char *prefix)
{
- struct mem_zone *zone = strm->opaque;
+ struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
- fprintf(stderr, "%s: %lu high water mark\n", prefix, zone->highwater);
+ 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, char *prefix)
+local void mem_done(z_stream *strm, const char *prefix)
{
int count = 0;
struct mem_item *item, *next;
- struct mem_zone *zone = strm->opaque;
+ struct mem_zone *zone = static_cast<struct mem_zone *>(strm->opaque);
/* show high water mark */
mem_high(strm, prefix);
@@ -218,13 +233,20 @@ local void mem_done(z_stream *strm, char *prefix)
/* issue alerts about anything unexpected */
if (count || zone->total)
- fprintf(stderr, "** %s: %lu bytes in %d blocks not freed\n",
- prefix, zone->total, count);
+ std::cout << "** " << prefix << ": "
+ << zone->total << " bytes in "
+ << count << " blocks not freed"
+ << std::endl;
+
if (zone->notlifo)
- fprintf(stderr, "** %s: %d frees not LIFO\n", prefix, zone->notlifo);
+ std::cout << "** " << prefix << ": "
+ << zone->notlifo << " frees not LIFO"
+ << std::endl;
+
if (zone->rogue)
- fprintf(stderr, "** %s: %d frees not recognized\n",
- prefix, zone->rogue);
+ std::cout << "** " << prefix << ": "
+ << zone->rogue << " frees not recognized"
+ << std::endl;
/* free the zone and delete from the stream */
free(zone);
@@ -247,7 +269,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
unsigned char *in, *re;
unsigned next, val;
- in = malloc((strlen(hex) + 1) >> 1);
+ in = static_cast<unsigned char *>(malloc((strlen(hex) + 1) >> 1));
if (in == NULL)
return NULL;
next = 0;
@@ -268,7 +290,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
} while (*hex++); /* go through the loop with the terminating null */
if (len != NULL)
*len = next;
- re = realloc(in, next);
+ re = static_cast<unsigned char *>(realloc(in, next));
return re == NULL ? in : re;
}
@@ -281,7 +303,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
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(char *hex, char *what, unsigned step, int win, unsigned len,
+local void inf(const char *hex, const char *what, unsigned step, int win, unsigned len,
int err)
{
int ret;
@@ -298,7 +320,7 @@ local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
mem_done(&strm, what);
return;
}
- out = malloc(len); assert(out != NULL);
+ out = static_cast<unsigned char *>(malloc(len)); assert(out != NULL);
if (win == 47) {
head.extra = out;
head.extra_max = len;
@@ -347,7 +369,7 @@ local void inf(char *hex, char *what, unsigned step, int win, unsigned len,
}
/* cover all of the lines in inflate.c up to inflate() */
-local void cover_support(void)
+void cover_support(void)
{
int ret;
z_stream strm;
@@ -381,11 +403,11 @@ local void cover_support(void)
strm.next_in = Z_NULL;
ret = inflateInit(&strm); assert(ret == Z_OK);
ret = inflateEnd(&strm); assert(ret == Z_OK);
- fputs("inflate built-in memory routines\n", stderr);
+ std::cout << "inflate built-in memory routines" << std::endl;;
}
/* cover all inflate() header and trailer cases and code after inflate() */
-local void cover_wrap(void)
+void cover_wrap(void)
{
int ret;
z_stream strm, copy;
@@ -394,7 +416,7 @@ local void cover_wrap(void)
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);
- fputs("inflate bad parameters\n", stderr);
+ 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);
@@ -415,9 +437,9 @@ local void cover_wrap(void)
strm.next_in = Z_NULL;
ret = inflateInit2(&strm, -8);
strm.avail_in = 2;
- strm.next_in = (void *)"\x63";
+ strm.next_in = (Bytef *)"\x63";
strm.avail_out = 1;
- strm.next_out = (void *)&ret;
+ 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);
@@ -428,11 +450,11 @@ local void cover_wrap(void)
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 = (void *)"\x80";
+ 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 = (void *)"\0\0\xff\xff";
+ strm.next_in = (Bytef *)"\0\0\xff\xff";
ret = inflateSync(&strm); assert(ret == Z_OK);
(void)inflateSyncPoint(&strm);
ret = inflateCopy(&copy, &strm); assert(ret == Z_MEM_ERROR);
@@ -454,7 +476,7 @@ local unsigned pull(void *desc, unsigned char **buf)
next = 0;
return 0; /* no input (already provided at next_in) */
}
- state = (void *)((z_stream *)desc)->state;
+ 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;
@@ -467,7 +489,7 @@ local int push(void *desc, unsigned char *buf, unsigned len)
}
/* cover inflateBack() up to common deflate data cases and after those */
-local void cover_back(void)
+void cover_back(void)
{
int ret;
z_stream strm;
@@ -479,17 +501,17 @@ local void cover_back(void)
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);
- fputs("inflateBack bad parameters\n", stderr);
+ 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 = (void *)"\x03";
+ 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 = (void *)"\x63\x00";
+ 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 */
@@ -500,11 +522,11 @@ local void cover_back(void)
ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK);
ret = inflateBackEnd(&strm); assert(ret == Z_OK);
- fputs("inflateBack built-in memory routines\n", stderr);
+ 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(char *hex, char *id, int err)
+local int try(const char *hex, const char *id, int err)
{
int ret;
unsigned len, size;
@@ -518,11 +540,11 @@ local int try(char *hex, char *id, int err)
/* allocate work areas */
size = len << 3;
- out = malloc(size);
+ out = static_cast<unsigned char *>(malloc(size));
assert(out != NULL);
- win = malloc(32768);
+ win = static_cast<unsigned char *>(malloc(32768));
assert(win != NULL);
- prefix = malloc(strlen(id) + 6);
+ prefix = static_cast<char *>(malloc(strlen(id) + 6));
assert(prefix != NULL);
/* first with inflate */
@@ -578,7 +600,7 @@ local int try(char *hex, char *id, int err)
}
/* cover deflate data cases in both inflate() and inflateBack() */
-local void cover_inflate(void)
+void cover_inflate(void)
{
try("0 0 0 0 0", "invalid stored block lengths", 1);
try("3 0", "fixed", 0);
@@ -613,32 +635,33 @@ local void cover_inflate(void)
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 */
-local 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);
-}
+/* 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 */
-local void cover_fast(void)
+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);
@@ -658,14 +681,4 @@ local void cover_fast(void)
Z_STREAM_END);
}
-int main(void)
-{
- fprintf(stderr, "%s\n", zlibVersion());
- cover_support();
- cover_wrap();
- cover_back();
- cover_inflate();
- cover_trees();
- cover_fast();
- return 0;
-}
+// clang-format on
--
2.21.1 (Apple Git-122.3)

View File

@ -0,0 +1,42 @@
From 8304bdda5293ffd5b3efce8e4f54904b387029d6 Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans@chromium.org>
Date: Wed, 23 Sep 2020 16:36:38 +0200
Subject: [PATCH] Avoid crashing in check_match when prev_match == -1
prev_match can be set to -1 after sliding the window. In that case, the
window has slid past the first byte of the last match, which means it
cannot be compared in check_match.
This would cause zlib to crash on some inputs to deflate when built
with ZLIB_DEBUG enabled.
Check for this situation and avoid crashing by not trying to compare
the first byte.
Bug: 1113142
---
third_party/zlib/deflate.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c
index cfdd2f46b230..d70732ec6fc2 100644
--- a/third_party/zlib/deflate.c
+++ b/third_party/zlib/deflate.c
@@ -2060,7 +2060,13 @@ local block_state deflate_slow(s, flush)
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */
- check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+ if (s->prev_match == -1) {
+ /* The window has slid one byte past the previous match,
+ * so the first byte cannot be compared. */
+ check_match(s, s->strstart, s->prev_match+1, s->prev_length-1);
+ } else {
+ check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+ }
_tr_tally_dist(s, s->strstart -1 - s->prev_match,
s->prev_length - MIN_MATCH, bflush);
--
2.28.0.681.g6f77f65b4e-goog

View File

@ -0,0 +1,40 @@
From 92537ee19784e0e545f06d89b7d89ab532a18cff Mon Sep 17 00:00:00 2001
From: Hans Wennborg <hans@chromium.org>
Date: Tue, 3 Nov 2020 15:54:09 +0100
Subject: [PATCH] [zlib] Zero-initialize the window used for deflation
Otherwise MSan complains about use-of-uninitialized values in the
window.
This happens in both regular deflate's longest_match and deflate_rle.
Before crrev.com/822755 we used to suppress those reports, but it seems
better to fix it properly. That will also allow us to catch other
potential issues with MSan in these functions.
The instances of this that we've seen only reproduce with
fill_window_sse(), not with the regular fill_window() function. Since
the former doesn't exist in upstream zlib, I'm not planning to send this
patch upstream.
Bug: 1137613, 1144420
---
third_party/zlib/deflate.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/third_party/zlib/deflate.c b/third_party/zlib/deflate.c
index 8bf93e524875..fc7ae45905ff 100644
--- a/third_party/zlib/deflate.c
+++ b/third_party/zlib/deflate.c
@@ -321,6 +321,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
s->window = (Bytef *) ZALLOC(strm,
s->w_size + window_padding,
2*sizeof(Byte));
+ /* Avoid use of unitialized values in the window, see crbug.com/1137613 and
+ * crbug.com/1144420 */
+ zmemzero(s->window, (s->w_size + window_padding) * (2 * sizeof(Byte)));
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
/* Avoid use of uninitialized value, see:
* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11360
--
2.29.1.341.ge80a0c044ae-goog

View File

@ -0,0 +1,82 @@
From 0c7de17000659f4f79de878296892c46be0aff77 Mon Sep 17 00:00:00 2001
From: Noel Gordon <noel@chromium.org>
Date: Wed, 26 May 2021 21:57:43 +1000
Subject: [PATCH] Build minizip zip and unzip tools
---
third_party/zlib/contrib/minizip/miniunz.c | 13 ++++++-------
third_party/zlib/contrib/minizip/minizip.c | 7 +++----
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/third_party/zlib/contrib/minizip/miniunz.c b/third_party/zlib/contrib/minizip/miniunz.c
index 616c30325e07c..f4ad16bdd377b 100644
--- a/third_party/zlib/contrib/minizip/miniunz.c
+++ b/third_party/zlib/contrib/minizip/miniunz.c
@@ -12,7 +12,7 @@
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/
-#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
+#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) && (!defined(__ANDROID_API__))
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
@@ -27,7 +27,7 @@
#endif
#endif
-#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) || defined(__Fuchsia__) || defined(__ANDROID_API__)
// 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)
@@ -97,7 +97,7 @@ static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_dat
LocalFileTimeToFileTime(&ftLocal,&ftm);
SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
CloseHandle(hFile);
-#elif defined(__unix__) || defined(__unix) || defined(__APPLE__)
+#elif defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__ANDROID_API__)
(void)dosdate;
struct utimbuf ut;
struct tm newdate;
@@ -129,7 +129,7 @@ static int mymkdir(const char* dirname) {
int ret=0;
#ifdef _WIN32
ret = _mkdir(dirname);
-#elif defined(__unix__) || defined(__unix) || defined(__APPLE__)
+#elif defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__ANDROID_API__)
ret = mkdir (dirname,0775);
#else
(void)dirname;
diff --git a/third_party/zlib/contrib/minizip/minizip.c b/third_party/zlib/contrib/minizip/minizip.c
index a44e36a01869d..53fdd363e6222 100644
--- a/third_party/zlib/contrib/minizip/minizip.c
+++ b/third_party/zlib/contrib/minizip/minizip.c
@@ -12,8 +12,7 @@
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/
-
-#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
+#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) && (!defined(__ANDROID_API__))
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
@@ -28,7 +27,7 @@
#endif
#endif
-#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) || defined(__Fuchsia__) || defined(__ANDROID_API__)
// 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)
@@ -96,7 +95,7 @@ static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {
}
return ret;
}
-#elif defined(__unix__) || defined(__unix) || defined(__APPLE__)
+#elif defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__ANDROID_API__)
/* f: name of file to get info on, tmzip: return value: access,
modification and creation times, dt: dostime */
static int filetime(const char *f, tm_zip *tmzip, uLong *dt) {

View File

@ -0,0 +1,24 @@
From 75690b2683667be5535ac6243438115dc9c40f6a Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer@google.com>
Date: Wed, 16 Mar 2022 16:38:36 -0700
Subject: [PATCH] Fix out of bounds in infcover.c.
---
test/infcover.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/infcover.c b/test/infcover.c
index 2be01646c..a6d83693c 100644
--- a/test/infcover.c
+++ b/test/infcover.c
@@ -373,7 +373,9 @@ local void cover_support(void)
mem_setup(&strm);
strm.avail_in = 0;
strm.next_in = Z_NULL;
- ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
+ char versioncpy[] = ZLIB_VERSION;
+ versioncpy[0] -= 1;
+ ret = inflateInit_(&strm, versioncpy, (int)sizeof(z_stream));
assert(ret == Z_VERSION_ERROR);
mem_done(&strm, "wrong version");

View File

@ -0,0 +1,96 @@
diff --git a/third_party/zlib/CMakeLists.txt b/third_party/zlib/CMakeLists.txt
index b412dc7feb732..0431278405046 100644
--- a/third_party/zlib/CMakeLists.txt
+++ b/third_party/zlib/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.4.4)
+cmake_minimum_required(VERSION 3.0)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
project(zlib C)
@@ -21,6 +21,26 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stddef.h HAVE_STDDEF_H)
+option(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF)
+
+# TODO(cavalcantii): add support for other OSes (e.g. Android, fuchsia, osx)
+# and architectures (e.g. Arm).
+if (ENABLE_SIMD_OPTIMIZATIONS)
+ add_definitions(-DINFLATE_CHUNK_SIMD_SSE2)
+ add_definitions(-DADLER32_SIMD_SSSE3)
+ add_definitions(-DINFLATE_CHUNK_READ_64LE)
+ add_definitions(-DCRC32_SIMD_SSE42_PCLMUL)
+ add_definitions(-DDEFLATE_SLIDE_HASH_SSE2)
+ add_compile_options(-msse4.2 -mpclmul)
+ # Required by CPU features detection code.
+ add_definitions(-DX86_NOT_WINDOWS)
+ # Apparently some environments (e.g. CentOS) require to explicitly link
+ # with pthread and that is required by the CPU features detection code.
+ find_package (Threads REQUIRED)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+endif()
+
#
# Check to see if we have large file support
#
@@ -120,10 +140,25 @@ set(ZLIB_SRCS
zutil.c
)
-if(NOT MINGW)
- set(ZLIB_DLL_SRCS
- win32/zlib1.rc # If present will override custom build rule below.
- )
+
+#============================================================================
+# Update list of source files if optimizations were enabled
+#============================================================================
+if (ENABLE_SIMD_OPTIMIZATIONS)
+ list(REMOVE_ITEM ZLIB_SRCS inflate.c)
+
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.h)
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/chunkcopy.h)
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inffast_chunk.h)
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.h)
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/crc32_simd.h)
+
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inffast_chunk.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inflate.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/crc32_simd.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/crc_folding.c)
endif()
# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
@@ -191,23 +226,9 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
endif()
#============================================================================
-# Example binaries
+# Benchmarker
#============================================================================
-
-add_executable(example test/example.c)
-target_link_libraries(example zlib)
-add_test(example example)
-
-add_executable(minigzip test/minigzip.c)
-target_link_libraries(minigzip zlib)
-
-if(HAVE_OFF64_T)
- add_executable(example64 test/example.c)
- target_link_libraries(example64 zlib)
- set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
- add_test(example64 example64)
-
- add_executable(minigzip64 test/minigzip.c)
- target_link_libraries(minigzip64 zlib)
- set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
-endif()
+enable_language(CXX)
+set(CMAKE_CXX_STANDARD 14) # workaround for older compilers (e.g. g++ 5.4).
+add_executable(zlib_bench contrib/bench/zlib_bench.cc)
+target_link_libraries(zlib_bench zlib)

View File

@ -0,0 +1,357 @@
From 87fc8e3e38323cfdabf8da3927488e3e57073b02 Mon Sep 17 00:00:00 2001
From: Jia Liu <jia3.liu@intel.com>
Date: Thu, 30 Mar 2023 11:13:16 +0800
Subject: [PATCH] Enabled AVX512 for CRC32
Enabled AVX512 for CRC32 that provide best of known performance
beyond current SSE SIMD optimization. It enables multiple folding
operations and AVX512 new instructions, providing ~3.5X CRC32
performance and ~3.7% gain on Zlib_bench gzip performance.
---
CMakeLists.txt | 8 +-
cpu_features.c | 9 +++
cpu_features.h | 1 +
crc32.c | 14 +++-
crc32_simd.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++-
crc32_simd.h | 6 ++
6 files changed, 230 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f06e193..d45b902 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,6 +22,7 @@ check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stddef.h HAVE_STDDEF_H)
option(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF)
+option(ENABLE_SIMD_AVX512 "Enable SIMD AXV512 optimizations" OFF)
# TODO(cavalcantii): add support for other OSes (e.g. Android, fuchsia, osx)
# and architectures (e.g. Arm).
@@ -30,8 +31,13 @@ if (ENABLE_SIMD_OPTIMIZATIONS)
add_definitions(-DADLER32_SIMD_SSSE3)
add_definitions(-DINFLATE_CHUNK_READ_64LE)
add_definitions(-DCRC32_SIMD_SSE42_PCLMUL)
+ if (ENABLE_SIMD_AVX512)
+ add_definitions(-DCRC32_SIMD_AVX512_PCLMUL)
+ add_compile_options(-mvpclmulqdq -msse2 -mavx512f -mpclmul)
+ else()
+ add_compile_options(-msse4.2 -mpclmul)
+ endif()
add_definitions(-DDEFLATE_SLIDE_HASH_SSE2)
- add_compile_options(-msse4.2 -mpclmul)
# Required by CPU features detection code.
add_definitions(-DX86_NOT_WINDOWS)
# Apparently some environments (e.g. CentOS) require to explicitly link
diff --git a/cpu_features.c b/cpu_features.c
index 877d5f2..ac6ee88 100644
--- a/cpu_features.c
+++ b/cpu_features.c
@@ -31,6 +31,7 @@ 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;
+int ZLIB_INTERNAL x86_cpu_enable_avx512 = 0;
#ifndef CPU_NO_SIMD
@@ -138,6 +139,10 @@ static void _cpu_check_features(void)
/* On x86 we simply use a instruction to check the CPU features.
* (i.e. CPUID).
*/
+#ifdef CRC32_SIMD_AVX512_PCLMUL
+#include <immintrin.h>
+#include <xsaveintrin.h>
+#endif
static void _cpu_check_features(void)
{
int x86_cpu_has_sse2;
@@ -164,6 +169,10 @@ static void _cpu_check_features(void)
x86_cpu_enable_simd = x86_cpu_has_sse2 &&
x86_cpu_has_sse42 &&
x86_cpu_has_pclmulqdq;
+
+#ifdef CRC32_SIMD_AVX512_PCLMUL
+ x86_cpu_enable_avx512 = _xgetbv(0) & 0x00000040;
+#endif
}
#endif
#endif
diff --git a/cpu_features.h b/cpu_features.h
index 279246c..aed3e83 100644
--- a/cpu_features.h
+++ b/cpu_features.h
@@ -14,5 +14,6 @@ extern int arm_cpu_enable_pmull;
extern int x86_cpu_enable_sse2;
extern int x86_cpu_enable_ssse3;
extern int x86_cpu_enable_simd;
+extern int x86_cpu_enable_avx512;
void cpu_check_features(void);
diff --git a/crc32.c b/crc32.c
index 4486098..acb6972 100644
--- a/crc32.c
+++ b/crc32.c
@@ -773,7 +773,19 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
}
#endif
-#if defined(CRC32_SIMD_SSE42_PCLMUL)
+#if defined(CRC32_SIMD_AVX512_PCLMUL)
+ if (x86_cpu_enable_avx512 && len >= Z_CRC32_AVX512_MINIMUM_LENGTH) {
+ /* crc32 64-byte chunks */
+ z_size_t chunk_size = len & ~Z_CRC32_AVX512_CHUNKSIZE_MASK;
+ crc = ~crc32_avx512_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;
+ }
+#elif defined(CRC32_SIMD_SSE42_PCLMUL)
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;
diff --git a/crc32_simd.c b/crc32_simd.c
index d80beba..7428270 100644
--- a/crc32_simd.c
+++ b/crc32_simd.c
@@ -6,17 +6,207 @@
*/
#include "crc32_simd.h"
-
-#if defined(CRC32_SIMD_SSE42_PCLMUL)
+#if defined(CRC32_SIMD_AVX512_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:
+ * crc32_avx512_simd_(): compute the crc32 of the buffer, where the buffer
+ * length must be at least 256, and a multiple of 64. 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>
+#include <immintrin.h>
+
+uint32_t ZLIB_INTERNAL crc32_avx512_simd_( /* AVX512+PCLMUL */
+ const unsigned char *buf,
+ z_size_t len,
+ uint32_t crc)
+{
+ /*
+ * Definitions of the bit-reflected domain constants k1,k2,k3,k4
+ * are similar to those given at the end of the paper, and remaining
+ * constants and CRC32+Barrett polynomials remain unchanged.
+ *
+ * Replace the index of x from 128 to 512. As follows:
+ * k1 = ( x ^ ( 512 * 4 + 32 ) mod P(x) << 32 )' << 1 = 0x011542778a
+ * k2 = ( x ^ ( 512 * 4 - 32 ) mod P(x) << 32 )' << 1 = 0x01322d1430
+ * k3 = ( x ^ ( 512 + 32 ) mod P(x) << 32 )' << 1 = 0x0154442bd4
+ * k4 = ( x ^ ( 512 - 32 ) mod P(x) << 32 )' << 1 = 0x01c6e41596
+ */
+ static const uint64_t zalign(64) k1k2[] = { 0x011542778a, 0x01322d1430,
+ 0x011542778a, 0x01322d1430,
+ 0x011542778a, 0x01322d1430,
+ 0x011542778a, 0x01322d1430 };
+ static const uint64_t zalign(64) k3k4[] = { 0x0154442bd4, 0x01c6e41596,
+ 0x0154442bd4, 0x01c6e41596,
+ 0x0154442bd4, 0x01c6e41596,
+ 0x0154442bd4, 0x01c6e41596 };
+ static const uint64_t zalign(16) k5k6[] = { 0x01751997d0, 0x00ccaa009e };
+ static const uint64_t zalign(16) k7k8[] = { 0x0163cd6124, 0x0000000000 };
+ static const uint64_t zalign(16) poly[] = { 0x01db710641, 0x01f7011641 };
+ __m512i x0, x1, x2, x3, x4, x5, x6, x7, x8, y5, y6, y7, y8;
+ __m128i a0, a1, a2, a3;
+
+ /*
+ * There's at least one block of 256.
+ */
+ x1 = _mm512_loadu_si512((__m512i *)(buf + 0x00));
+ x2 = _mm512_loadu_si512((__m512i *)(buf + 0x40));
+ x3 = _mm512_loadu_si512((__m512i *)(buf + 0x80));
+ x4 = _mm512_loadu_si512((__m512i *)(buf + 0xC0));
+
+ x1 = _mm512_xor_si512(x1, _mm512_castsi128_si512(_mm_cvtsi32_si128(crc)));
+
+ x0 = _mm512_load_si512((__m512i *)k1k2);
+
+ buf += 256;
+ len -= 256;
+
+ /*
+ * Parallel fold blocks of 256, if any.
+ */
+ while (len >= 256)
+ {
+ x5 = _mm512_clmulepi64_epi128(x1, x0, 0x00);
+ x6 = _mm512_clmulepi64_epi128(x2, x0, 0x00);
+ x7 = _mm512_clmulepi64_epi128(x3, x0, 0x00);
+ x8 = _mm512_clmulepi64_epi128(x4, x0, 0x00);
+
+
+ x1 = _mm512_clmulepi64_epi128(x1, x0, 0x11);
+ x2 = _mm512_clmulepi64_epi128(x2, x0, 0x11);
+ x3 = _mm512_clmulepi64_epi128(x3, x0, 0x11);
+ x4 = _mm512_clmulepi64_epi128(x4, x0, 0x11);
+
+ y5 = _mm512_loadu_si512((__m512i *)(buf + 0x00));
+ y6 = _mm512_loadu_si512((__m512i *)(buf + 0x40));
+ y7 = _mm512_loadu_si512((__m512i *)(buf + 0x80));
+ y8 = _mm512_loadu_si512((__m512i *)(buf + 0xC0));
+
+ x1 = _mm512_xor_si512(x1, x5);
+ x2 = _mm512_xor_si512(x2, x6);
+ x3 = _mm512_xor_si512(x3, x7);
+ x4 = _mm512_xor_si512(x4, x8);
+
+ x1 = _mm512_xor_si512(x1, y5);
+ x2 = _mm512_xor_si512(x2, y6);
+ x3 = _mm512_xor_si512(x3, y7);
+ x4 = _mm512_xor_si512(x4, y8);
+
+ buf += 256;
+ len -= 256;
+ }
+
+ /*
+ * Fold into 512-bits.
+ */
+ x0 = _mm512_load_si512((__m512i *)k3k4);
+
+ x5 = _mm512_clmulepi64_epi128(x1, x0, 0x00);
+ x1 = _mm512_clmulepi64_epi128(x1, x0, 0x11);
+ x1 = _mm512_xor_si512(x1, x2);
+ x1 = _mm512_xor_si512(x1, x5);
+
+ x5 = _mm512_clmulepi64_epi128(x1, x0, 0x00);
+ x1 = _mm512_clmulepi64_epi128(x1, x0, 0x11);
+ x1 = _mm512_xor_si512(x1, x3);
+ x1 = _mm512_xor_si512(x1, x5);
+
+ x5 = _mm512_clmulepi64_epi128(x1, x0, 0x00);
+ x1 = _mm512_clmulepi64_epi128(x1, x0, 0x11);
+ x1 = _mm512_xor_si512(x1, x4);
+ x1 = _mm512_xor_si512(x1, x5);
+
+ /*
+ * Single fold blocks of 64, if any.
+ */
+ while (len >= 64)
+ {
+ x2 = _mm512_loadu_si512((__m512i *)buf);
+
+ x5 = _mm512_clmulepi64_epi128(x1, x0, 0x00);
+ x1 = _mm512_clmulepi64_epi128(x1, x0, 0x11);
+ x1 = _mm512_xor_si512(x1, x2);
+ x1 = _mm512_xor_si512(x1, x5);
+
+ buf += 64;
+ len -= 64;
+ }
+
+ /*
+ * Fold 512-bits to 384-bits.
+ */
+ a0 = _mm_load_si128((__m128i *)k5k6);
+
+ a1 = _mm512_extracti32x4_epi32(x1, 0);
+ a2 = _mm512_extracti32x4_epi32(x1, 1);
+
+ a3 = _mm_clmulepi64_si128(a1, a0, 0x00);
+ a1 = _mm_clmulepi64_si128(a1, a0, 0x11);
+
+ a1 = _mm_xor_si128(a1, a3);
+ a1 = _mm_xor_si128(a1, a2);
+
+ /*
+ * Fold 384-bits to 256-bits.
+ */
+ a2 = _mm512_extracti32x4_epi32(x1, 2);
+ a3 = _mm_clmulepi64_si128(a1, a0, 0x00);
+ a1 = _mm_clmulepi64_si128(a1, a0, 0x11);
+ a1 = _mm_xor_si128(a1, a3);
+ a1 = _mm_xor_si128(a1, a2);
+
+ /*
+ * Fold 256-bits to 128-bits.
+ */
+ a2 = _mm512_extracti32x4_epi32(x1, 3);
+ a3 = _mm_clmulepi64_si128(a1, a0, 0x00);
+ a1 = _mm_clmulepi64_si128(a1, a0, 0x11);
+ a1 = _mm_xor_si128(a1, a3);
+ a1 = _mm_xor_si128(a1, a2);
+
+ /*
+ * Fold 128-bits to 64-bits.
+ */
+ a2 = _mm_clmulepi64_si128(a1, a0, 0x10);
+ a3 = _mm_setr_epi32(~0, 0, ~0, 0);
+ a1 = _mm_srli_si128(a1, 8);
+ a1 = _mm_xor_si128(a1, a2);
+
+ a0 = _mm_loadl_epi64((__m128i*)k7k8);
+ a2 = _mm_srli_si128(a1, 4);
+ a1 = _mm_and_si128(a1, a3);
+ a1 = _mm_clmulepi64_si128(a1, a0, 0x00);
+ a1 = _mm_xor_si128(a1, a2);
+
+ /*
+ * Barret reduce to 32-bits.
+ */
+ a0 = _mm_load_si128((__m128i*)poly);
+
+ a2 = _mm_and_si128(a1, a3);
+ a2 = _mm_clmulepi64_si128(a2, a0, 0x10);
+ a2 = _mm_and_si128(a2, a3);
+ a2 = _mm_clmulepi64_si128(a2, a0, 0x00);
+ a1 = _mm_xor_si128(a1, a2);
+
+ /*
+ * Return the crc32.
+ */
+ return _mm_extract_epi32(a1, 1);
+}
+
+#elif 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.
+ */
+
#include <emmintrin.h>
#include <smmintrin.h>
#include <wmmintrin.h>
diff --git a/crc32_simd.h b/crc32_simd.h
index c0346dc..8462464 100644
--- a/crc32_simd.h
+++ b/crc32_simd.h
@@ -19,12 +19,18 @@ uint32_t ZLIB_INTERNAL crc32_sse42_simd_(const unsigned char* buf,
z_size_t len,
uint32_t crc);
+uint32_t ZLIB_INTERNAL crc32_avx512_simd_(const unsigned char* buf,
+ z_size_t len,
+ uint32_t crc);
+
/*
* crc32_sse42_simd_ buffer size constraints: see the use in zlib/crc32.c
* for computing the crc32 of an arbitrary length buffer.
*/
#define Z_CRC32_SSE42_MINIMUM_LENGTH 64
#define Z_CRC32_SSE42_CHUNKSIZE_MASK 15
+#define Z_CRC32_AVX512_MINIMUM_LENGTH 256
+#define Z_CRC32_AVX512_CHUNKSIZE_MASK 63
/*
* CRC32 checksums using ARMv8-a crypto instructions.
--
2.34.1

View File

@ -0,0 +1,40 @@
From 6f21cb4b209d750486ede5472fdf7e35cf5ac3aa Mon Sep 17 00:00:00 2001
From: Ramin Halavati <rhalavati@chromium.org>
Date: Wed, 17 May 2023 15:21:43 +0200
Subject: [PATCH] Add open64 for Large File System support to gzlib.
---
third_party/zlib/gzlib.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/third_party/zlib/gzlib.c b/third_party/zlib/gzlib.c
index 55da46a453fd1..bbdb797e8079d 100644
--- a/third_party/zlib/gzlib.c
+++ b/third_party/zlib/gzlib.c
@@ -7,11 +7,14 @@
#if defined(_WIN32) && !defined(__BORLANDC__)
# define LSEEK _lseeki64
+# define OPEN open
#else
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64
+# define OPEN open64
#else
# define LSEEK lseek
+# define OPEN open
#endif
#endif
@@ -244,7 +247,7 @@ local gzFile gz_open(path, fd, mode)
#ifdef WIDECHAR
fd == -2 ? _wopen(path, oflag, 0666) :
#endif
- open((const char *)path, oflag, 0666));
+ OPEN((const char *)path, oflag, 0666));
if (state->fd == -1) {
free(state->path);
free(state);
--
2.40.1.606.ga4b1b128d6-goog

View File

@ -0,0 +1,30 @@
From c43ba7a55f091c0dcbfd8d89f7a5121269ce1b81 Mon Sep 17 00:00:00 2001
From: Ho Cheung <uioptt24@gmail.com>
Date: Thu, 27 Jul 2023 09:47:52 +0800
Subject: [PATCH] [zlib] Perform CPU feature detection for ARM inside adler32()
Perform CPU feature detection for ARM within adler32() to have the same
behavior as x86.
---
third_party/zlib/adler32.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/third_party/zlib/adler32.c b/third_party/zlib/adler32.c
index 81c584f68e233..99a294496f7eb 100644
--- a/third_party/zlib/adler32.c
+++ b/third_party/zlib/adler32.c
@@ -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
--
2.41.0.windows.3

View File

@ -0,0 +1,34 @@
commit 764f0715d75c8d49339aa73d0ee2feb75d63473f
Author: joaoe@opera.com <joaoe@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed May 7 20:53:02 2014 +0000
Fixed uncompressing files with wrong uncompressed size set.
A zip file carries some metadata for each archived file, including the total
uncompressed size. If that size was incorrect, therefore the compressed file
being different in size when unpacking, the minizip code would fail with a
CRC error. Every other zip utility handles these files, so should the minizip
code for safety sake.
BUG=359516
Review URL: https://codereview.chromium.org/222243003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268940 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/third_party/zlib/contrib/minizip/unzip.c b/third_party/zlib/contrib/minizip/unzip.c
index ed763f89f1f87..82275d6c1775d 100644
--- a/third_party/zlib/contrib/minizip/unzip.c
+++ b/third_party/zlib/contrib/minizip/unzip.c
@@ -1572,11 +1572,6 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len) {
pfile_in_zip_read_info->stream.avail_out = (uInt)len;
- if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
- (!(pfile_in_zip_read_info->raw)))
- pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
-
if ((len>pfile_in_zip_read_info->rest_read_compressed+
pfile_in_zip_read_info->stream.avail_in) &&
(pfile_in_zip_read_info->raw))

View File

@ -0,0 +1,28 @@
commit f3ace98803035b8425d127fb3d874dafe0b9475a
Author: Che-yu Wu <cheyuw@google.com>
Date: Mon Aug 6 14:09:22 2018 +0000
Enable traditional PKWARE decryption in zlib/contrib/minizip.
Remove the #define which enables NOUNCRYPT by default.
Correct the value of rest_read_compressed when decompressing an encrypted zip.
Bug: crbug.com/869541
Change-Id: Ia86c1d234a8193f405147d35ad05c29fe86f812d
Reviewed-on: https://chromium-review.googlesource.com/1161109
Reviewed-by: Chris Blume <cblume@chromium.org>
Commit-Queue: Che-yu Wu <cheyuw@google.com>
Cr-Commit-Position: refs/heads/master@{#580862}
diff --git a/third_party/zlib/contrib/minizip/unzip.c b/third_party/zlib/contrib/minizip/unzip.c
index 82275d6c1775d..c8a01b23efd42 100644
--- a/third_party/zlib/contrib/minizip/unzip.c
+++ b/third_party/zlib/contrib/minizip/unzip.c
@@ -1502,6 +1498,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

View File

@ -0,0 +1,117 @@
commit c8834821f452a3d424edd0ed2a1e9ceeda38d0ea
Author: Alex Danilo <adanilo@chromium.org>
Date: Thu May 12 03:29:52 2022 +0000
Extract: Parse Unicode Path Extra field in minizip
Adds parsing of the Info-ZIP Extra field which overrides the
file name in the File Header only if the CRC in the extra field
is a CRC of the file name in the File Header.
See https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
section 4.6.9 for reference.
Also tidied up some whitespace indent.
Bug: 953256, 953599
Tests: Manually tested, auto test in follow on CL
Change-Id: I1283dcb88a203c3bb56c1d9c504035a2e51aecbd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3641742
Reviewed-by: Noel Gordon <noel@chromium.org>
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002476}
diff --git a/third_party/zlib/contrib/minizip/unzip.c b/third_party/zlib/contrib/minizip/unzip.c
index c8a01b23efd42..42677cff82c96 100644
--- a/third_party/zlib/contrib/minizip/unzip.c
+++ b/third_party/zlib/contrib/minizip/unzip.c
@@ -193,6 +193,26 @@ typedef struct
Reads a long in LSB order from the given gz_stream. Sets
*/
+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
+ {
+ *pi = 0;
+ if (ZERROR64(*pzlib_filefunc_def,filestream))
+ return UNZ_ERRNO;
+ else
+ return UNZ_EOF;
+ }
+}
+
local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def,
voidpf filestream,
uLong *pX) {
@@ -948,6 +968,62 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
}
}
+ else if (headerId == 0x7075) /* Info-ZIP Unicode Path Extra Field */
+ {
+ int version = 0;
+
+ if (unz64local_getByte(&s->z_filefunc, s->filestream, &version) != UNZ_OK)
+ {
+ err = UNZ_ERRNO;
+ }
+ if (version != 1)
+ {
+ if (ZSEEK64(s->z_filefunc, s->filestream,dataSize - 1, ZLIB_FILEFUNC_SEEK_CUR) != 0)
+ {
+ err = UNZ_ERRNO;
+ }
+ }
+ else
+ {
+ uLong uCrc, uHeaderCrc, fileNameSize;
+
+ if (unz64local_getLong(&s->z_filefunc, s->filestream, &uCrc) != UNZ_OK)
+ {
+ err = UNZ_ERRNO;
+ }
+ uHeaderCrc = crc32(0, (const unsigned char *)szFileName, file_info.size_filename);
+ fileNameSize = dataSize - (2 * sizeof (short) + 1);
+ /* Check CRC against file name in the header. */
+ if (uHeaderCrc != uCrc)
+ {
+ if (ZSEEK64(s->z_filefunc, s->filestream, fileNameSize, ZLIB_FILEFUNC_SEEK_CUR) != 0)
+ {
+ err = UNZ_ERRNO;
+ }
+ }
+ else
+ {
+ uLong uSizeRead;
+
+ if (fileNameSize < fileNameBufferSize)
+ {
+ *(szFileName + fileNameSize) = '\0';
+ uSizeRead = fileNameSize;
+ }
+ else
+ {
+ uSizeRead = fileNameBufferSize;
+ }
+ if ((fileNameSize > 0) && (fileNameBufferSize > 0))
+ {
+ if (ZREAD64(s->z_filefunc, s->filestream, szFileName, uSizeRead) != uSizeRead)
+ {
+ err = UNZ_ERRNO;
+ }
+ }
+ }
+ }
+ }
else
{
if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)

43
deps/v8/third_party/zlib/patches/README vendored Normal file
View File

@ -0,0 +1,43 @@
== Patches applied on top of zlib ==
- 0000-build.patch: changes from the upstream version, mostly related to the
build.
- 0001-simd.patch: integrate Intel SIMD optimizations from
https://github.com/jtkukunas/zlib/
- 0002-uninitializedcheck.patch: prevent uninitialized use of state->check
== Procedure to create a patch file ==
Assuming you are working in a new feature branch:
- git format-patch master --stdout > foo.patch # where naming follows a growing
# number plus patch description.
- git add foo.patch
- git commit -a -m "Local patch."
- git rebase -i HEAD~2 # Squashing the second commit
As patches created in this way will feature a ChangeLog, there is no longer
the need to append this file with a description of what the patch does. This
should help to solve frequent conflicts in pending new patches on
Chromium's zlib.
The plan for the near future is to better insulate the platform specific
changes to ease update adoption with new releases of zlib. This insulation
happens by making changes inside contrib/ rather than the root directory
(where conflicts can happen).
If a change modifies enough things inside the root directory that the
intention is not immediately clear, generate a .patch file to go with your
change. If the change's modifications in the root directory are small, like:
#ifdef FEATURE_FLAG
use_special_feature();
#elif
use_default_behavior();
#endif
then the intent is clear and a .patch file doesn't need to be generated (since
it would not provide much value).
Ideally local changes should have a merge request featured in either:
- canonical zlib: https://github.com/madler/zlib/
- zlib-ng: https://github.com/Dead2/zlib-ng