From 2453cc7323cb5d5aad4abea889fc4ff412c8296c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:31:56 -0700 Subject: [PATCH 01/19] Make ZLIB_DEBUG a build option --- src/native/external/zlib-ng/CMakeLists.txt | 6 +++++- src/native/external/zlib-ng/README.md | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 8bcfaf7ea23e4e..30170356c5ef8d 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -76,6 +76,7 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON) option(ZLIB_COMPAT "Compile with zlib compatible API" OFF) option(ZLIB_ENABLE_TESTS "Build test binaries" ON) option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON) +option(ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration" ON) option(WITH_GTEST "Build gtest_zlib" ON) option(WITH_FUZZERS "Build test/fuzz" OFF) option(WITH_BENCHMARKS "Build test/benchmarks" OFF) @@ -486,7 +487,9 @@ if(NOT HAVE_PTRDIFF_T) endif() endif() -add_compile_options($<$:-DZLIB_DEBUG>) +if (ZLIB_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-DZLIB_DEBUG) +endif() if(MSVC) set(CMAKE_DEBUG_POSTFIX "d") @@ -1242,6 +1245,7 @@ add_feature_info(WITH_GZFILEOP WITH_GZFILEOP "Compile with support for gzFile re add_feature_info(ZLIB_COMPAT ZLIB_COMPAT "Compile with zlib compatible API") add_feature_info(ZLIB_ENABLE_TESTS ZLIB_ENABLE_TESTS "Build test binaries") add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API") +add_feature_info(ZLIB_DEBUG ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration") add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer support") add_feature_info(WITH_GTEST WITH_GTEST "Build gtest_zlib") add_feature_info(WITH_FUZZERS WITH_FUZZERS "Build test/fuzz") diff --git a/src/native/external/zlib-ng/README.md b/src/native/external/zlib-ng/README.md index 4f9fe09c69115f..a0b66ead591699 100644 --- a/src/native/external/zlib-ng/README.md +++ b/src/native/external/zlib-ng/README.md @@ -98,6 +98,7 @@ Build Options | CMake | configure | Description | Default | |:-------------------------|:-------------------------|:--------------------------------------------------------------------------------------|---------| | ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF | +| ZLIB_DEBUG | | Compile using the ZLIB_DEBUG option when building using the Debug configuration | ON | | ZLIB_ENABLE_TESTS | | Build test binaries | ON | | WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON | | WITH_OPTIM | --without-optimizations | Build with optimisations | ON | From a3d456514c5c2fc86f00171108e68fb732b2b77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:32:10 -0700 Subject: [PATCH 02/19] Turn off ZLIB_DEBUG in our zlib-ng.cmake --- src/native/external/zlib-ng.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index c9829842c458bd..60c720901b53cd 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -8,6 +8,7 @@ set(ZLIB_COMPAT ON) set(ZLIB_ENABLE_TESTS OFF) set(ZLIBNG_ENABLE_TESTS OFF) set(Z_PREFIX ON) +set(ZLIB_DEBUG OFF) # TODO: Turn back on when Linux kernels with proper RISC-V extension detection (>= 6.5) are more commonplace set(WITH_RVV OFF) @@ -15,8 +16,6 @@ set(WITH_RVV OFF) add_compile_options($<$:-Wno-unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' add_compile_options($<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant -add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files -add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files # 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt. if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) From 9e23740db0cb361325a00a3244cd49b7b52b8ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:35:47 -0700 Subject: [PATCH 03/19] Patch for zlib-ng/ --- .../0001-Make-ZLIB_DEBUG-a-build-option.patch | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch diff --git a/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch b/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch new file mode 100644 index 00000000000000..8528d439a64558 --- /dev/null +++ b/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch @@ -0,0 +1,57 @@ +From 2453cc7323cb5d5aad4abea889fc4ff412c8296c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= + <1175054+carlossanlop@users.noreply.github.com> +Date: Wed, 24 Jul 2024 15:31:56 -0700 +Subject: [PATCH] Make ZLIB_DEBUG a build option + +--- + src/native/external/zlib-ng/CMakeLists.txt | 6 +++++- + src/native/external/zlib-ng/README.md | 1 + + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt +index 8bcfaf7ea23..30170356c5e 100644 +--- a/src/native/external/zlib-ng/CMakeLists.txt ++++ b/src/native/external/zlib-ng/CMakeLists.txt +@@ -76,6 +76,7 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON) + option(ZLIB_COMPAT "Compile with zlib compatible API" OFF) + option(ZLIB_ENABLE_TESTS "Build test binaries" ON) + option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON) ++option(ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration" ON) + option(WITH_GTEST "Build gtest_zlib" ON) + option(WITH_FUZZERS "Build test/fuzz" OFF) + option(WITH_BENCHMARKS "Build test/benchmarks" OFF) +@@ -486,7 +487,9 @@ if(NOT HAVE_PTRDIFF_T) + endif() + endif() + +-add_compile_options($<$:-DZLIB_DEBUG>) ++if (ZLIB_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") ++ add_definitions(-DZLIB_DEBUG) ++endif() + + if(MSVC) + set(CMAKE_DEBUG_POSTFIX "d") +@@ -1242,6 +1245,7 @@ add_feature_info(WITH_GZFILEOP WITH_GZFILEOP "Compile with support for gzFile re + add_feature_info(ZLIB_COMPAT ZLIB_COMPAT "Compile with zlib compatible API") + add_feature_info(ZLIB_ENABLE_TESTS ZLIB_ENABLE_TESTS "Build test binaries") + add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API") ++add_feature_info(ZLIB_DEBUG ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration") + add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer support") + add_feature_info(WITH_GTEST WITH_GTEST "Build gtest_zlib") + add_feature_info(WITH_FUZZERS WITH_FUZZERS "Build test/fuzz") +diff --git a/src/native/external/zlib-ng/README.md b/src/native/external/zlib-ng/README.md +index 4f9fe09c691..a0b66ead591 100644 +--- a/src/native/external/zlib-ng/README.md ++++ b/src/native/external/zlib-ng/README.md +@@ -98,6 +98,7 @@ Build Options + | CMake | configure | Description | Default | + |:-------------------------|:-------------------------|:--------------------------------------------------------------------------------------|---------| + | ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF | ++| ZLIB_DEBUG | | Compile using the ZLIB_DEBUG option when building using the Debug configuration | ON | + | ZLIB_ENABLE_TESTS | | Build test binaries | ON | + | WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON | + | WITH_OPTIM | --without-optimizations | Build with optimisations | ON | +-- +2.45.2.windows.1 + From 9f5e23453c5a86f73a1614ef6e1c3dafd821c013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:00:37 -0700 Subject: [PATCH 04/19] Mention the applied patch in zlib-ng-version.txt --- src/native/external/zlib-ng-version.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/external/zlib-ng-version.txt b/src/native/external/zlib-ng-version.txt index 1b6fdae17b30c6..2750637f29774a 100644 --- a/src/native/external/zlib-ng-version.txt +++ b/src/native/external/zlib-ng-version.txt @@ -8,3 +8,5 @@ We have removed the following folders from our local copy as these files are not - zlib-ng/docs/ - zlib-ng/test/ - zlib-ng/arch/s390/self-hosted-builder/ + +We have also applied the custom patches under the patches/zlib-ng/ folder. From f066d482651452d782a8490dcd6a78309b82491a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:37:11 -0700 Subject: [PATCH 05/19] Revert that --- src/native/external/zlib-ng.cmake | 1 - src/native/external/zlib-ng/CMakeLists.txt | 6 +----- src/native/external/zlib-ng/README.md | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 60c720901b53cd..6ed1ae2deb20d4 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -8,7 +8,6 @@ set(ZLIB_COMPAT ON) set(ZLIB_ENABLE_TESTS OFF) set(ZLIBNG_ENABLE_TESTS OFF) set(Z_PREFIX ON) -set(ZLIB_DEBUG OFF) # TODO: Turn back on when Linux kernels with proper RISC-V extension detection (>= 6.5) are more commonplace set(WITH_RVV OFF) diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 30170356c5ef8d..48749a03c8f6f9 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -76,7 +76,6 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON) option(ZLIB_COMPAT "Compile with zlib compatible API" OFF) option(ZLIB_ENABLE_TESTS "Build test binaries" ON) option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON) -option(ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration" ON) option(WITH_GTEST "Build gtest_zlib" ON) option(WITH_FUZZERS "Build test/fuzz" OFF) option(WITH_BENCHMARKS "Build test/benchmarks" OFF) @@ -487,9 +486,7 @@ if(NOT HAVE_PTRDIFF_T) endif() endif() -if (ZLIB_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DZLIB_DEBUG) -endif() +add_compile_options($<$:-DZLIB_DEBUG>) if(MSVC) set(CMAKE_DEBUG_POSTFIX "d") @@ -1245,7 +1242,6 @@ add_feature_info(WITH_GZFILEOP WITH_GZFILEOP "Compile with support for gzFile re add_feature_info(ZLIB_COMPAT ZLIB_COMPAT "Compile with zlib compatible API") add_feature_info(ZLIB_ENABLE_TESTS ZLIB_ENABLE_TESTS "Build test binaries") add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API") -add_feature_info(ZLIB_DEBUG ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration") add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer support") add_feature_info(WITH_GTEST WITH_GTEST "Build gtest_zlib") add_feature_info(WITH_FUZZERS WITH_FUZZERS "Build test/fuzz") diff --git a/src/native/external/zlib-ng/README.md b/src/native/external/zlib-ng/README.md index a0b66ead591699..4f9fe09c69115f 100644 --- a/src/native/external/zlib-ng/README.md +++ b/src/native/external/zlib-ng/README.md @@ -98,7 +98,6 @@ Build Options | CMake | configure | Description | Default | |:-------------------------|:-------------------------|:--------------------------------------------------------------------------------------|---------| | ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF | -| ZLIB_DEBUG | | Compile using the ZLIB_DEBUG option when building using the Debug configuration | ON | | ZLIB_ENABLE_TESTS | | Build test binaries | ON | | WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON | | WITH_OPTIM | --without-optimizations | Build with optimisations | ON | From e2106cd3e5771690867d826e525e4ad80619d76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:43:38 -0700 Subject: [PATCH 06/19] Add aserts and casts to slide_hash* --- src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 4 +++- src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 4 +++- src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 4 +++- src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 ++ src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 ++ src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c | 1 + 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c index 0a2eeccf92692a..ef226fad5d4f97 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c @@ -7,6 +7,7 @@ #include "acle_intrins.h" #include "../../zbuild.h" #include "../../deflate.h" +#include /* SIMD version of hash_chain rebase */ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { @@ -39,7 +40,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_armv6(deflate_state *s) { - unsigned int wsize = s->w_size; + assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); slide_hash_chain(s->prev, wsize, wsize); diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c index a96ca11799b5a8..b9574a308e067d 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c @@ -12,6 +12,7 @@ #include "neon_intrins.h" #include "../../zbuild.h" #include "../../deflate.h" +#include /* SIMD version of hash_chain rebase */ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { @@ -38,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_neon(deflate_state *s) { - unsigned int wsize = s->w_size; + assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); slide_hash_chain(s->prev, wsize, wsize); diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h index 5c17e38fb31036..44c61c27da1b0e 100644 --- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h @@ -6,6 +6,7 @@ #include #include "zbuild.h" #include "deflate.h" +#include static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { const vector unsigned short vmx_wsize = vec_splats(wsize); @@ -24,7 +25,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } void Z_INTERNAL SLIDE_PPC(deflate_state *s) { - uint16_t wsize = s->w_size; + assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); slide_hash_chain(s->prev, wsize, wsize); diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c index 1164e89ba250f0..2e7587423730da 100644 --- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c @@ -10,6 +10,7 @@ #include "../../zbuild.h" #include "../../deflate.h" +#include static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { size_t vl; @@ -25,6 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_rvv(deflate_state *s) { + assert(s->w_size <= _UI16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c index 94fe10c7bf4a4e..144b5672940426 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c @@ -13,6 +13,7 @@ #include "../../deflate.h" #include +#include static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i wsize) { table += entries; @@ -31,6 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i } Z_INTERNAL void slide_hash_avx2(deflate_state *s) { + assert(s->w_size <= _UI16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c index 5daac4a73981c3..04db335e3de1e0 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c @@ -52,6 +52,7 @@ static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0, } Z_INTERNAL void slide_hash_sse2(deflate_state *s) { + assert(s->w_size <= _UI16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); From 51c39e062b7df96a789da1818c3e2446e9f60d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:44:08 -0700 Subject: [PATCH 07/19] Add asserts and casts to check_match --- src/native/external/zlib-ng/deflate_fast.c | 4 +++- src/native/external/zlib-ng/deflate_quick.c | 3 ++- src/native/external/zlib-ng/deflate_rle.c | 4 +++- src/native/external/zlib-ng/deflate_slow.c | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/native/external/zlib-ng/deflate_fast.c b/src/native/external/zlib-ng/deflate_fast.c index 3184aa718c7ead..6c6e227136bd0e 100644 --- a/src/native/external/zlib-ng/deflate_fast.c +++ b/src/native/external/zlib-ng/deflate_fast.c @@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { } if (match_len >= WANT_MIN_MATCH) { - check_match(s, s->strstart, s->match_start, match_len); + Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); + Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); + check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); diff --git a/src/native/external/zlib-ng/deflate_quick.c b/src/native/external/zlib-ng/deflate_quick.c index df5a17b9e6623c..8dd32ae32a9049 100644 --- a/src/native/external/zlib-ng/deflate_quick.c +++ b/src/native/external/zlib-ng/deflate_quick.c @@ -102,7 +102,8 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { if (UNLIKELY(match_len > STD_MAX_MATCH)) match_len = STD_MAX_MATCH; - check_match(s, s->strstart, hash_head, match_len); + Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); + check_match(s, (Pos)s->strstart, hash_head, match_len); zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); s->lookahead -= match_len; diff --git a/src/native/external/zlib-ng/deflate_rle.c b/src/native/external/zlib-ng/deflate_rle.c index cd08509946066a..cf1f3bf4bba28c 100644 --- a/src/native/external/zlib-ng/deflate_rle.c +++ b/src/native/external/zlib-ng/deflate_rle.c @@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) { /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ if (match_len >= STD_MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, match_len); + Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); + Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); + check_match(s, (Pos)s->strstart, (Pos)s->strstart - 1, match_len); bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); diff --git a/src/native/external/zlib-ng/deflate_slow.c b/src/native/external/zlib-ng/deflate_slow.c index 9f1c913467b7e8..b71c0e5a331512 100644 --- a/src/native/external/zlib-ng/deflate_slow.c +++ b/src/native/external/zlib-ng/deflate_slow.c @@ -78,7 +78,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH; /* Do not insert strings in hash table beyond this. */ - check_match(s, s->strstart-1, s->prev_match, s->prev_length); + Assert((s->strstart-1) <= _UI16_MAX,"strstart-1 should fit in uint16_t"); + check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); From f4e5207ef8bff37c897f3248ccb295ee4a63ebe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:44:19 -0700 Subject: [PATCH 08/19] Remove previous patch --- .../0001-Make-ZLIB_DEBUG-a-build-option.patch | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch diff --git a/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch b/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch deleted file mode 100644 index 8528d439a64558..00000000000000 --- a/src/native/external/patches/zlib-ng/0001-Make-ZLIB_DEBUG-a-build-option.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 2453cc7323cb5d5aad4abea889fc4ff412c8296c Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= - <1175054+carlossanlop@users.noreply.github.com> -Date: Wed, 24 Jul 2024 15:31:56 -0700 -Subject: [PATCH] Make ZLIB_DEBUG a build option - ---- - src/native/external/zlib-ng/CMakeLists.txt | 6 +++++- - src/native/external/zlib-ng/README.md | 1 + - 2 files changed, 6 insertions(+), 1 deletion(-) - -diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt -index 8bcfaf7ea23..30170356c5e 100644 ---- a/src/native/external/zlib-ng/CMakeLists.txt -+++ b/src/native/external/zlib-ng/CMakeLists.txt -@@ -76,6 +76,7 @@ option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON) - option(ZLIB_COMPAT "Compile with zlib compatible API" OFF) - option(ZLIB_ENABLE_TESTS "Build test binaries" ON) - option(ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API" ON) -+option(ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration" ON) - option(WITH_GTEST "Build gtest_zlib" ON) - option(WITH_FUZZERS "Build test/fuzz" OFF) - option(WITH_BENCHMARKS "Build test/benchmarks" OFF) -@@ -486,7 +487,9 @@ if(NOT HAVE_PTRDIFF_T) - endif() - endif() - --add_compile_options($<$:-DZLIB_DEBUG>) -+if (ZLIB_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug") -+ add_definitions(-DZLIB_DEBUG) -+endif() - - if(MSVC) - set(CMAKE_DEBUG_POSTFIX "d") -@@ -1242,6 +1245,7 @@ add_feature_info(WITH_GZFILEOP WITH_GZFILEOP "Compile with support for gzFile re - add_feature_info(ZLIB_COMPAT ZLIB_COMPAT "Compile with zlib compatible API") - add_feature_info(ZLIB_ENABLE_TESTS ZLIB_ENABLE_TESTS "Build test binaries") - add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Test zlib-ng specific API") -+add_feature_info(ZLIB_DEBUG ZLIB_DEBUG "Compile using the ZLIB_DEBUG option when building using the Debug configuration") - add_feature_info(WITH_SANITIZER WITH_SANITIZER "Enable sanitizer support") - add_feature_info(WITH_GTEST WITH_GTEST "Build gtest_zlib") - add_feature_info(WITH_FUZZERS WITH_FUZZERS "Build test/fuzz") -diff --git a/src/native/external/zlib-ng/README.md b/src/native/external/zlib-ng/README.md -index 4f9fe09c691..a0b66ead591 100644 ---- a/src/native/external/zlib-ng/README.md -+++ b/src/native/external/zlib-ng/README.md -@@ -98,6 +98,7 @@ Build Options - | CMake | configure | Description | Default | - |:-------------------------|:-------------------------|:--------------------------------------------------------------------------------------|---------| - | ZLIB_COMPAT | --zlib-compat | Compile with zlib compatible API | OFF | -+| ZLIB_DEBUG | | Compile using the ZLIB_DEBUG option when building using the Debug configuration | ON | - | ZLIB_ENABLE_TESTS | | Build test binaries | ON | - | WITH_GZFILEOP | --without-gzfileops | Compile with support for gzFile related functions | ON | - | WITH_OPTIM | --without-optimizations | Build with optimisations | ON | --- -2.45.2.windows.1 - From 735a61be6ea3ea487cb736c01d10e2817b1d6236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:45:05 -0700 Subject: [PATCH 09/19] Add the other patches --- ...1-Add-aserts-and-casts-to-slide_hash.patch | 136 ++++++++++++++++++ ...Add-asserts-and-casts-to-check_match.patch | 74 ++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch create mode 100644 src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch diff --git a/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch b/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch new file mode 100644 index 00000000000000..99b85ecd3e8c62 --- /dev/null +++ b/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch @@ -0,0 +1,136 @@ +From e2106cd3e5771690867d826e525e4ad80619d76b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= + <1175054+carlossanlop@users.noreply.github.com> +Date: Wed, 24 Jul 2024 18:43:38 -0700 +Subject: [PATCH 1/2] Add aserts and casts to slide_hash* + +--- + src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 4 +++- + src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 4 +++- + src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 4 +++- + src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 ++ + src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 ++ + src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c | 1 + + 6 files changed, 14 insertions(+), 3 deletions(-) + +diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +index 0a2eeccf926..ef226fad5d4 100644 +--- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c ++++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +@@ -7,6 +7,7 @@ + #include "acle_intrins.h" + #include "../../zbuild.h" + #include "../../deflate.h" ++#include + + /* SIMD version of hash_chain rebase */ + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { +@@ -39,7 +40,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize + } + + Z_INTERNAL void slide_hash_armv6(deflate_state *s) { +- unsigned int wsize = s->w_size; ++ assert(s->w_size <= _UI16_MAX); ++ uint16_t wsize = (uint16_t)s->w_size; + + slide_hash_chain(s->head, HASH_SIZE, wsize); + slide_hash_chain(s->prev, wsize, wsize); +diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +index a96ca11799b..b9574a308e0 100644 +--- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c ++++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +@@ -12,6 +12,7 @@ + #include "neon_intrins.h" + #include "../../zbuild.h" + #include "../../deflate.h" ++#include + + /* SIMD version of hash_chain rebase */ + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { +@@ -38,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize + } + + Z_INTERNAL void slide_hash_neon(deflate_state *s) { +- unsigned int wsize = s->w_size; ++ assert(s->w_size <= _UI16_MAX); ++ uint16_t wsize = (uint16_t)s->w_size; + + slide_hash_chain(s->head, HASH_SIZE, wsize); + slide_hash_chain(s->prev, wsize, wsize); +diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +index 5c17e38fb31..44c61c27da1 100644 +--- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h ++++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +@@ -6,6 +6,7 @@ + #include + #include "zbuild.h" + #include "deflate.h" ++#include + + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { + const vector unsigned short vmx_wsize = vec_splats(wsize); +@@ -24,7 +25,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize + } + + void Z_INTERNAL SLIDE_PPC(deflate_state *s) { +- uint16_t wsize = s->w_size; ++ assert(s->w_size <= _UI16_MAX); ++ uint16_t wsize = (uint16_t)s->w_size; + + slide_hash_chain(s->head, HASH_SIZE, wsize); + slide_hash_chain(s->prev, wsize, wsize); +diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +index 1164e89ba25..2e758742373 100644 +--- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c ++++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +@@ -10,6 +10,7 @@ + + #include "../../zbuild.h" + #include "../../deflate.h" ++#include + + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { + size_t vl; +@@ -25,6 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize + } + + Z_INTERNAL void slide_hash_rvv(deflate_state *s) { ++ assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; + + slide_hash_chain(s->head, HASH_SIZE, wsize); +diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +index 94fe10c7bf4..144b5672940 100644 +--- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c ++++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +@@ -13,6 +13,7 @@ + #include "../../deflate.h" + + #include ++#include + + static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i wsize) { + table += entries; +@@ -31,6 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i + } + + Z_INTERNAL void slide_hash_avx2(deflate_state *s) { ++ assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; + const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); + +diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c +index 5daac4a7398..04db335e3de 100644 +--- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c ++++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c +@@ -52,6 +52,7 @@ next_chain: + } + + Z_INTERNAL void slide_hash_sse2(deflate_state *s) { ++ assert(s->w_size <= _UI16_MAX); + uint16_t wsize = (uint16_t)s->w_size; + const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); + +-- +2.45.2.windows.1 + diff --git a/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch b/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch new file mode 100644 index 00000000000000..4b4268f6c5524d --- /dev/null +++ b/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch @@ -0,0 +1,74 @@ +From 51c39e062b7df96a789da1818c3e2446e9f60d64 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= + <1175054+carlossanlop@users.noreply.github.com> +Date: Wed, 24 Jul 2024 18:44:08 -0700 +Subject: [PATCH 2/2] Add asserts and casts to check_match + +--- + src/native/external/zlib-ng/deflate_fast.c | 4 +++- + src/native/external/zlib-ng/deflate_quick.c | 3 ++- + src/native/external/zlib-ng/deflate_rle.c | 4 +++- + src/native/external/zlib-ng/deflate_slow.c | 3 ++- + 4 files changed, 10 insertions(+), 4 deletions(-) + +diff --git a/src/native/external/zlib-ng/deflate_fast.c b/src/native/external/zlib-ng/deflate_fast.c +index 3184aa718c7..6c6e227136b 100644 +--- a/src/native/external/zlib-ng/deflate_fast.c ++++ b/src/native/external/zlib-ng/deflate_fast.c +@@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { + } + + if (match_len >= WANT_MIN_MATCH) { +- check_match(s, s->strstart, s->match_start, match_len); ++ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); ++ Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); ++ check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); + + bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); + +diff --git a/src/native/external/zlib-ng/deflate_quick.c b/src/native/external/zlib-ng/deflate_quick.c +index df5a17b9e66..8dd32ae32a9 100644 +--- a/src/native/external/zlib-ng/deflate_quick.c ++++ b/src/native/external/zlib-ng/deflate_quick.c +@@ -102,7 +102,8 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { + if (UNLIKELY(match_len > STD_MAX_MATCH)) + match_len = STD_MAX_MATCH; + +- check_match(s, s->strstart, hash_head, match_len); ++ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); ++ check_match(s, (Pos)s->strstart, hash_head, match_len); + + zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); + s->lookahead -= match_len; +diff --git a/src/native/external/zlib-ng/deflate_rle.c b/src/native/external/zlib-ng/deflate_rle.c +index cd085099460..cf1f3bf4bba 100644 +--- a/src/native/external/zlib-ng/deflate_rle.c ++++ b/src/native/external/zlib-ng/deflate_rle.c +@@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) { + + /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ + if (match_len >= STD_MIN_MATCH) { +- check_match(s, s->strstart, s->strstart - 1, match_len); ++ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); ++ Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); ++ check_match(s, (Pos)s->strstart, (Pos)s->strstart - 1, match_len); + + bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); + +diff --git a/src/native/external/zlib-ng/deflate_slow.c b/src/native/external/zlib-ng/deflate_slow.c +index 9f1c913467b..b71c0e5a331 100644 +--- a/src/native/external/zlib-ng/deflate_slow.c ++++ b/src/native/external/zlib-ng/deflate_slow.c +@@ -78,7 +78,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { + unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + +- check_match(s, s->strstart-1, s->prev_match, s->prev_length); ++ Assert((s->strstart-1) <= _UI16_MAX,"strstart-1 should fit in uint16_t"); ++ check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); + + bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); + +-- +2.45.2.windows.1 + From bb4722d38a75d0f7bc4d2f1955ac344916472502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:47:30 -0700 Subject: [PATCH 10/19] extra space --- src/native/external/zlib-ng/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 48749a03c8f6f9..8bcfaf7ea23e4e 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -486,7 +486,7 @@ if(NOT HAVE_PTRDIFF_T) endif() endif() -add_compile_options($<$:-DZLIB_DEBUG>) +add_compile_options($<$:-DZLIB_DEBUG>) if(MSVC) set(CMAKE_DEBUG_POSTFIX "d") From 8babcbe6f40656646276a1731db90e86ae9a68b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:15:13 +0000 Subject: [PATCH 11/19] Try with UINT16_MAX instead --- .../0001-Add-aserts-and-casts-to-slide_hash.patch | 12 ++++++------ .../0002-Add-asserts-and-casts-to-check_match.patch | 12 ++++++------ .../external/zlib-ng/arch/arm/slide_hash_armv6.c | 2 +- .../external/zlib-ng/arch/arm/slide_hash_neon.c | 2 +- .../external/zlib-ng/arch/power/slide_ppc_tpl.h | 2 +- .../external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 +- .../external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 +- .../external/zlib-ng/arch/x86/slide_hash_sse2.c | 2 +- src/native/external/zlib-ng/deflate_fast.c | 4 ++-- src/native/external/zlib-ng/deflate_quick.c | 2 +- src/native/external/zlib-ng/deflate_rle.c | 4 ++-- src/native/external/zlib-ng/deflate_slow.c | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch b/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch index 99b85ecd3e8c62..1f3d103a8ee35f 100644 --- a/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch +++ b/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch @@ -30,7 +30,7 @@ index 0a2eeccf926..ef226fad5d4 100644 Z_INTERNAL void slide_hash_armv6(deflate_state *s) { - unsigned int wsize = s->w_size; -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); @@ -52,7 +52,7 @@ index a96ca11799b..b9574a308e0 100644 Z_INTERNAL void slide_hash_neon(deflate_state *s) { - unsigned int wsize = s->w_size; -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); @@ -74,7 +74,7 @@ index 5c17e38fb31..44c61c27da1 100644 void Z_INTERNAL SLIDE_PPC(deflate_state *s) { - uint16_t wsize = s->w_size; -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); + uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); @@ -95,7 +95,7 @@ index 1164e89ba25..2e758742373 100644 } Z_INTERNAL void slide_hash_rvv(deflate_state *s) { -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); @@ -115,7 +115,7 @@ index 94fe10c7bf4..144b5672940 100644 } Z_INTERNAL void slide_hash_avx2(deflate_state *s) { -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); @@ -127,7 +127,7 @@ index 5daac4a7398..04db335e3de 100644 } Z_INTERNAL void slide_hash_sse2(deflate_state *s) { -+ assert(s->w_size <= _UI16_MAX); ++ assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); diff --git a/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch b/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch index 4b4268f6c5524d..b2992a834623b3 100644 --- a/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch +++ b/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch @@ -20,8 +20,8 @@ index 3184aa718c7..6c6e227136b 100644 if (match_len >= WANT_MIN_MATCH) { - check_match(s, s->strstart, s->match_start, match_len); -+ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); -+ Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); ++ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); ++ Assert(s->match_start <= UINT16_MAX,"match_start should fit in uint16_t"); + check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); @@ -35,7 +35,7 @@ index df5a17b9e66..8dd32ae32a9 100644 match_len = STD_MAX_MATCH; - check_match(s, s->strstart, hash_head, match_len); -+ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); ++ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); + check_match(s, (Pos)s->strstart, hash_head, match_len); zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); @@ -49,8 +49,8 @@ index cd085099460..cf1f3bf4bba 100644 /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ if (match_len >= STD_MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, match_len); -+ Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); -+ Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); ++ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); ++ Assert(s->match_start <= UINT16_MAX,"match_start should fit in uint16_t"); + check_match(s, (Pos)s->strstart, (Pos)s->strstart - 1, match_len); bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); @@ -64,7 +64,7 @@ index 9f1c913467b..b71c0e5a331 100644 /* Do not insert strings in hash table beyond this. */ - check_match(s, s->strstart-1, s->prev_match, s->prev_length); -+ Assert((s->strstart-1) <= _UI16_MAX,"strstart-1 should fit in uint16_t"); ++ Assert((s->strstart-1) <= UINT16_MAX,"strstart-1 should fit in uint16_t"); + check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c index ef226fad5d4f97..34f8bfc0e6ce2f 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c @@ -40,7 +40,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_armv6(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c index b9574a308e067d..0c2f0938bd09fe 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c @@ -39,7 +39,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_neon(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h index 44c61c27da1b0e..653868bbc5dcf8 100644 --- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h @@ -25,7 +25,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } void Z_INTERNAL SLIDE_PPC(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c index 2e7587423730da..db3cb16d4a9743 100644 --- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c @@ -26,7 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_rvv(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c index 144b5672940426..951e160c327ec9 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c @@ -32,7 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i } Z_INTERNAL void slide_hash_avx2(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c index 04db335e3de1e0..c4178d12796081 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c @@ -52,7 +52,7 @@ static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0, } Z_INTERNAL void slide_hash_sse2(deflate_state *s) { - assert(s->w_size <= _UI16_MAX); + assert(s->w_size <= UINT16_MAX); uint16_t wsize = (uint16_t)s->w_size; const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); diff --git a/src/native/external/zlib-ng/deflate_fast.c b/src/native/external/zlib-ng/deflate_fast.c index 6c6e227136bd0e..eada7b46e329a9 100644 --- a/src/native/external/zlib-ng/deflate_fast.c +++ b/src/native/external/zlib-ng/deflate_fast.c @@ -58,8 +58,8 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { } if (match_len >= WANT_MIN_MATCH) { - Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); - Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); + Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); + Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t"); check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); diff --git a/src/native/external/zlib-ng/deflate_quick.c b/src/native/external/zlib-ng/deflate_quick.c index 8dd32ae32a9049..6dfd35df510f85 100644 --- a/src/native/external/zlib-ng/deflate_quick.c +++ b/src/native/external/zlib-ng/deflate_quick.c @@ -102,7 +102,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { if (UNLIKELY(match_len > STD_MAX_MATCH)) match_len = STD_MAX_MATCH; - Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); + Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); check_match(s, (Pos)s->strstart, hash_head, match_len); zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); diff --git a/src/native/external/zlib-ng/deflate_rle.c b/src/native/external/zlib-ng/deflate_rle.c index cf1f3bf4bba28c..9691b30a85c857 100644 --- a/src/native/external/zlib-ng/deflate_rle.c +++ b/src/native/external/zlib-ng/deflate_rle.c @@ -58,8 +58,8 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) { /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ if (match_len >= STD_MIN_MATCH) { - Assert(s->strstart <= _UI16_MAX,"strstart should fit in uint16_t"); - Assert(s->match_start <= _UI16_MAX,"match_start should fit in uint16_t"); + Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t"); + Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t"); check_match(s, (Pos)s->strstart, (Pos)s->strstart - 1, match_len); bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); diff --git a/src/native/external/zlib-ng/deflate_slow.c b/src/native/external/zlib-ng/deflate_slow.c index b71c0e5a331512..69549347b00b4a 100644 --- a/src/native/external/zlib-ng/deflate_slow.c +++ b/src/native/external/zlib-ng/deflate_slow.c @@ -78,7 +78,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH; /* Do not insert strings in hash table beyond this. */ - Assert((s->strstart-1) <= _UI16_MAX,"strstart-1 should fit in uint16_t"); + Assert((s->strstart-1) <= UINT16_MAX,"strstart-1 should fit in uint16_t"); check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); From d360ce84b7d537703323c63f145faedfd8b2fa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 05:10:59 +0000 Subject: [PATCH 12/19] Change data type in _MonoVarianceSearchTableEntry --- src/mono/mono/metadata/class-internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/class-internals.h b/src/mono/mono/metadata/class-internals.h index fc967bb0adb5f6..e44ba4c7b49026 100644 --- a/src/mono/mono/metadata/class-internals.h +++ b/src/mono/mono/metadata/class-internals.h @@ -1467,7 +1467,7 @@ mono_method_has_unmanaged_callers_only_attribute (MonoMethod *method); typedef struct _MonoVarianceSearchTableEntry { MonoClass *klass; - guint16 offset; + int offset; } MonoVarianceSearchTableEntry; MonoVarianceSearchTableEntry * From 39485fa2cde08288ebe50110b4804c59c9315e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:49:53 -0700 Subject: [PATCH 13/19] Delete patches. If needed, will be submitted in separate PR. --- ...1-Add-aserts-and-casts-to-slide_hash.patch | 136 ------------------ ...Add-asserts-and-casts-to-check_match.patch | 74 ---------- 2 files changed, 210 deletions(-) delete mode 100644 src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch delete mode 100644 src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch diff --git a/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch b/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch deleted file mode 100644 index 1f3d103a8ee35f..00000000000000 --- a/src/native/external/patches/zlib-ng/0001-Add-aserts-and-casts-to-slide_hash.patch +++ /dev/null @@ -1,136 +0,0 @@ -From e2106cd3e5771690867d826e525e4ad80619d76b Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= - <1175054+carlossanlop@users.noreply.github.com> -Date: Wed, 24 Jul 2024 18:43:38 -0700 -Subject: [PATCH 1/2] Add aserts and casts to slide_hash* - ---- - src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 4 +++- - src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 4 +++- - src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 4 +++- - src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 ++ - src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 ++ - src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c | 1 + - 6 files changed, 14 insertions(+), 3 deletions(-) - -diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c -index 0a2eeccf926..ef226fad5d4 100644 ---- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c -+++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c -@@ -7,6 +7,7 @@ - #include "acle_intrins.h" - #include "../../zbuild.h" - #include "../../deflate.h" -+#include - - /* SIMD version of hash_chain rebase */ - static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { -@@ -39,7 +40,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize - } - - Z_INTERNAL void slide_hash_armv6(deflate_state *s) { -- unsigned int wsize = s->w_size; -+ assert(s->w_size <= UINT16_MAX); -+ uint16_t wsize = (uint16_t)s->w_size; - - slide_hash_chain(s->head, HASH_SIZE, wsize); - slide_hash_chain(s->prev, wsize, wsize); -diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c -index a96ca11799b..b9574a308e0 100644 ---- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c -+++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c -@@ -12,6 +12,7 @@ - #include "neon_intrins.h" - #include "../../zbuild.h" - #include "../../deflate.h" -+#include - - /* SIMD version of hash_chain rebase */ - static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { -@@ -38,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize - } - - Z_INTERNAL void slide_hash_neon(deflate_state *s) { -- unsigned int wsize = s->w_size; -+ assert(s->w_size <= UINT16_MAX); -+ uint16_t wsize = (uint16_t)s->w_size; - - slide_hash_chain(s->head, HASH_SIZE, wsize); - slide_hash_chain(s->prev, wsize, wsize); -diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h -index 5c17e38fb31..44c61c27da1 100644 ---- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h -+++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h -@@ -6,6 +6,7 @@ - #include - #include "zbuild.h" - #include "deflate.h" -+#include - - static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { - const vector unsigned short vmx_wsize = vec_splats(wsize); -@@ -24,7 +25,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize - } - - void Z_INTERNAL SLIDE_PPC(deflate_state *s) { -- uint16_t wsize = s->w_size; -+ assert(s->w_size <= UINT16_MAX); -+ uint16_t wsize = (uint16_t)s->w_size; - - slide_hash_chain(s->head, HASH_SIZE, wsize); - slide_hash_chain(s->prev, wsize, wsize); -diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c -index 1164e89ba25..2e758742373 100644 ---- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c -+++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c -@@ -10,6 +10,7 @@ - - #include "../../zbuild.h" - #include "../../deflate.h" -+#include - - static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { - size_t vl; -@@ -25,6 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize - } - - Z_INTERNAL void slide_hash_rvv(deflate_state *s) { -+ assert(s->w_size <= UINT16_MAX); - uint16_t wsize = (uint16_t)s->w_size; - - slide_hash_chain(s->head, HASH_SIZE, wsize); -diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c -index 94fe10c7bf4..144b5672940 100644 ---- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c -+++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c -@@ -13,6 +13,7 @@ - #include "../../deflate.h" - - #include -+#include - - static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i wsize) { - table += entries; -@@ -31,6 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i - } - - Z_INTERNAL void slide_hash_avx2(deflate_state *s) { -+ assert(s->w_size <= UINT16_MAX); - uint16_t wsize = (uint16_t)s->w_size; - const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); - -diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c -index 5daac4a7398..04db335e3de 100644 ---- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c -+++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c -@@ -52,6 +52,7 @@ next_chain: - } - - Z_INTERNAL void slide_hash_sse2(deflate_state *s) { -+ assert(s->w_size <= UINT16_MAX); - uint16_t wsize = (uint16_t)s->w_size; - const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); - --- -2.45.2.windows.1 - diff --git a/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch b/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch deleted file mode 100644 index b2992a834623b3..00000000000000 --- a/src/native/external/patches/zlib-ng/0002-Add-asserts-and-casts-to-check_match.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 51c39e062b7df96a789da1818c3e2446e9f60d64 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= - <1175054+carlossanlop@users.noreply.github.com> -Date: Wed, 24 Jul 2024 18:44:08 -0700 -Subject: [PATCH 2/2] Add asserts and casts to check_match - ---- - src/native/external/zlib-ng/deflate_fast.c | 4 +++- - src/native/external/zlib-ng/deflate_quick.c | 3 ++- - src/native/external/zlib-ng/deflate_rle.c | 4 +++- - src/native/external/zlib-ng/deflate_slow.c | 3 ++- - 4 files changed, 10 insertions(+), 4 deletions(-) - -diff --git a/src/native/external/zlib-ng/deflate_fast.c b/src/native/external/zlib-ng/deflate_fast.c -index 3184aa718c7..6c6e227136b 100644 ---- a/src/native/external/zlib-ng/deflate_fast.c -+++ b/src/native/external/zlib-ng/deflate_fast.c -@@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { - } - - if (match_len >= WANT_MIN_MATCH) { -- check_match(s, s->strstart, s->match_start, match_len); -+ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); -+ Assert(s->match_start <= UINT16_MAX,"match_start should fit in uint16_t"); -+ check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len); - - bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); - -diff --git a/src/native/external/zlib-ng/deflate_quick.c b/src/native/external/zlib-ng/deflate_quick.c -index df5a17b9e66..8dd32ae32a9 100644 ---- a/src/native/external/zlib-ng/deflate_quick.c -+++ b/src/native/external/zlib-ng/deflate_quick.c -@@ -102,7 +102,8 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { - if (UNLIKELY(match_len > STD_MAX_MATCH)) - match_len = STD_MAX_MATCH; - -- check_match(s, s->strstart, hash_head, match_len); -+ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); -+ check_match(s, (Pos)s->strstart, hash_head, match_len); - - zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist); - s->lookahead -= match_len; -diff --git a/src/native/external/zlib-ng/deflate_rle.c b/src/native/external/zlib-ng/deflate_rle.c -index cd085099460..cf1f3bf4bba 100644 ---- a/src/native/external/zlib-ng/deflate_rle.c -+++ b/src/native/external/zlib-ng/deflate_rle.c -@@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) { - - /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */ - if (match_len >= STD_MIN_MATCH) { -- check_match(s, s->strstart, s->strstart - 1, match_len); -+ Assert(s->strstart <= UINT16_MAX,"strstart should fit in uint16_t"); -+ Assert(s->match_start <= UINT16_MAX,"match_start should fit in uint16_t"); -+ check_match(s, (Pos)s->strstart, (Pos)s->strstart - 1, match_len); - - bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH); - -diff --git a/src/native/external/zlib-ng/deflate_slow.c b/src/native/external/zlib-ng/deflate_slow.c -index 9f1c913467b..b71c0e5a331 100644 ---- a/src/native/external/zlib-ng/deflate_slow.c -+++ b/src/native/external/zlib-ng/deflate_slow.c -@@ -78,7 +78,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { - unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - -- check_match(s, s->strstart-1, s->prev_match, s->prev_length); -+ Assert((s->strstart-1) <= UINT16_MAX,"strstart-1 should fit in uint16_t"); -+ check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); - - bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); - --- -2.45.2.windows.1 - From 41c1b4485732a84de88f41c605394937de61496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:53:49 -0700 Subject: [PATCH 14/19] Remove unnecessary comment --- src/native/external/zlib-ng-version.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/native/external/zlib-ng-version.txt b/src/native/external/zlib-ng-version.txt index 2750637f29774a..1b6fdae17b30c6 100644 --- a/src/native/external/zlib-ng-version.txt +++ b/src/native/external/zlib-ng-version.txt @@ -8,5 +8,3 @@ We have removed the following folders from our local copy as these files are not - zlib-ng/docs/ - zlib-ng/test/ - zlib-ng/arch/s390/self-hosted-builder/ - -We have also applied the custom patches under the patches/zlib-ng/ folder. From 6e7b5b45de3beb8160a2ad016591efef8d750879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:03:41 -0700 Subject: [PATCH 15/19] Comment for PR patch --- src/native/external/zlib-ng-version.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/external/zlib-ng-version.txt b/src/native/external/zlib-ng-version.txt index 1b6fdae17b30c6..4292d95a0fca5d 100644 --- a/src/native/external/zlib-ng-version.txt +++ b/src/native/external/zlib-ng-version.txt @@ -8,3 +8,5 @@ We have removed the following folders from our local copy as these files are not - zlib-ng/docs/ - zlib-ng/test/ - zlib-ng/arch/s390/self-hosted-builder/ + +Apply https://github.com/dotnet/runtime/pull/105433.patch \ No newline at end of file From ec56c25e99d05ddd71e69c3147a145480b525499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:11:51 -0700 Subject: [PATCH 16/19] Add comment at the top of zlib-ng.cmake to warn about using add_compile_options --- src/native/external/zlib-ng.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 6ed1ae2deb20d4..aee5572ef06f60 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -1,3 +1,5 @@ + # IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects + include(FetchContent) FetchContent_Declare( From 2969513a664c0b4c9b274e55bc44b8fe483230f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:12:29 -0700 Subject: [PATCH 17/19] Remove the add_compile_options, only use target_compile_options specifically for zlib --- src/native/external/zlib-ng.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index aee5572ef06f60..08f7356f27e74c 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -14,10 +14,6 @@ set(Z_PREFIX ON) # TODO: Turn back on when Linux kernels with proper RISC-V extension detection (>= 6.5) are more commonplace set(WITH_RVV OFF) -add_compile_options($<$:-Wno-unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' -add_compile_options($<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning -add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant - # 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt. if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE) @@ -31,6 +27,7 @@ set(SKIP_INSTALL_ALL OFF) set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/zlib-ng PROPERTY MSVC_WARNING_LEVEL 3) # Set the MSVC warning level for all zlib-ng targets to 3. target_compile_options(zlib PRIVATE $<$:-Wno-unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments target_compile_options(zlib PRIVATE $<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning +target_compile_options(zlib PRIVATE $<$:/wd4127>) # warning C4127: conditional expression is constant target_compile_options(zlib PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "") # Workaround: zlib's debug lib name is zlibd.lib From 5074685ad75df66e44ee6f196c8ca1b6fe1d92a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:26:13 -0700 Subject: [PATCH 18/19] Switch to Assert instead of assert --- src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 2 +- src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 2 +- src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 2 +- src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 +- src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 +- src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c | 2 +- src/native/external/zlib-ng/deflate_slow.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c index 34f8bfc0e6ce2f..b6a897ad14f634 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c @@ -40,7 +40,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_armv6(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c index 0c2f0938bd09fe..9442b7702e40e9 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c @@ -39,7 +39,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_neon(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h index 653868bbc5dcf8..a2e2ce02cf4840 100644 --- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h @@ -25,7 +25,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } void Z_INTERNAL SLIDE_PPC(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c index db3cb16d4a9743..e1a8fcd0803ef0 100644 --- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c @@ -26,7 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize } Z_INTERNAL void slide_hash_rvv(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; slide_hash_chain(s->head, HASH_SIZE, wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c index 951e160c327ec9..fa59aa6d5afe33 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c @@ -32,7 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i } Z_INTERNAL void slide_hash_avx2(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c index c4178d12796081..5e75aedba5efbc 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c @@ -52,7 +52,7 @@ static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0, } Z_INTERNAL void slide_hash_sse2(deflate_state *s) { - assert(s->w_size <= UINT16_MAX); + Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); uint16_t wsize = (uint16_t)s->w_size; const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); diff --git a/src/native/external/zlib-ng/deflate_slow.c b/src/native/external/zlib-ng/deflate_slow.c index 69549347b00b4a..913d828928bf8e 100644 --- a/src/native/external/zlib-ng/deflate_slow.c +++ b/src/native/external/zlib-ng/deflate_slow.c @@ -78,7 +78,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH; /* Do not insert strings in hash table beyond this. */ - Assert((s->strstart-1) <= UINT16_MAX,"strstart-1 should fit in uint16_t"); + Assert((s->strstart-1) <= UINT16_MAX, "strstart-1 should fit in uint16_t"); check_match(s, (Pos)(s->strstart-1), s->prev_match, s->prev_length); bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH); From d99757e02ad414f2da2f2cffc089a3847a567bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:27:55 -0700 Subject: [PATCH 19/19] Remove the assert includes too --- src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 1 - src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 1 - src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 1 - src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 1 - src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 1 - 5 files changed, 5 deletions(-) diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c index b6a897ad14f634..3a715a1551df6d 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c @@ -7,7 +7,6 @@ #include "acle_intrins.h" #include "../../zbuild.h" #include "../../deflate.h" -#include /* SIMD version of hash_chain rebase */ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { diff --git a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c index 9442b7702e40e9..2889e9c0460274 100644 --- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c +++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c @@ -12,7 +12,6 @@ #include "neon_intrins.h" #include "../../zbuild.h" #include "../../deflate.h" -#include /* SIMD version of hash_chain rebase */ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { diff --git a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h index a2e2ce02cf4840..680a7f8e2af407 100644 --- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h +++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h @@ -6,7 +6,6 @@ #include #include "zbuild.h" #include "deflate.h" -#include static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { const vector unsigned short vmx_wsize = vec_splats(wsize); diff --git a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c index e1a8fcd0803ef0..b70a44b63e0e70 100644 --- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c +++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c @@ -10,7 +10,6 @@ #include "../../zbuild.h" #include "../../deflate.h" -#include static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { size_t vl; diff --git a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c index fa59aa6d5afe33..39254204ef4621 100644 --- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c +++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c @@ -13,7 +13,6 @@ #include "../../deflate.h" #include -#include static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i wsize) { table += entries;