|
| 1 | +From e2106cd3e5771690867d826e525e4ad80619d76b Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= |
| 3 | + |
| 4 | +Date: Wed, 24 Jul 2024 18:43:38 -0700 |
| 5 | +Subject: [PATCH 1/2] Add aserts and casts to slide_hash* |
| 6 | + |
| 7 | +--- |
| 8 | + src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c | 4 +++- |
| 9 | + src/native/external/zlib-ng/arch/arm/slide_hash_neon.c | 4 +++- |
| 10 | + src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h | 4 +++- |
| 11 | + src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c | 2 ++ |
| 12 | + src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c | 2 ++ |
| 13 | + src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c | 1 + |
| 14 | + 6 files changed, 14 insertions(+), 3 deletions(-) |
| 15 | + |
| 16 | +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 |
| 17 | +index 0a2eeccf926..ef226fad5d4 100644 |
| 18 | +--- a/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c |
| 19 | ++++ b/src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c |
| 20 | +@@ -7,6 +7,7 @@ |
| 21 | + #include "acle_intrins.h" |
| 22 | + #include "../../zbuild.h" |
| 23 | + #include "../../deflate.h" |
| 24 | ++#include <assert.h> |
| 25 | + |
| 26 | + /* SIMD version of hash_chain rebase */ |
| 27 | + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { |
| 28 | +@@ -39,7 +40,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize |
| 29 | + } |
| 30 | + |
| 31 | + Z_INTERNAL void slide_hash_armv6(deflate_state *s) { |
| 32 | +- unsigned int wsize = s->w_size; |
| 33 | ++ assert(s->w_size <= _UI16_MAX); |
| 34 | ++ uint16_t wsize = (uint16_t)s->w_size; |
| 35 | + |
| 36 | + slide_hash_chain(s->head, HASH_SIZE, wsize); |
| 37 | + slide_hash_chain(s->prev, wsize, wsize); |
| 38 | +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 |
| 39 | +index a96ca11799b..b9574a308e0 100644 |
| 40 | +--- a/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c |
| 41 | ++++ b/src/native/external/zlib-ng/arch/arm/slide_hash_neon.c |
| 42 | +@@ -12,6 +12,7 @@ |
| 43 | + #include "neon_intrins.h" |
| 44 | + #include "../../zbuild.h" |
| 45 | + #include "../../deflate.h" |
| 46 | ++#include <assert.h> |
| 47 | + |
| 48 | + /* SIMD version of hash_chain rebase */ |
| 49 | + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { |
| 50 | +@@ -38,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize |
| 51 | + } |
| 52 | + |
| 53 | + Z_INTERNAL void slide_hash_neon(deflate_state *s) { |
| 54 | +- unsigned int wsize = s->w_size; |
| 55 | ++ assert(s->w_size <= _UI16_MAX); |
| 56 | ++ uint16_t wsize = (uint16_t)s->w_size; |
| 57 | + |
| 58 | + slide_hash_chain(s->head, HASH_SIZE, wsize); |
| 59 | + slide_hash_chain(s->prev, wsize, wsize); |
| 60 | +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 |
| 61 | +index 5c17e38fb31..44c61c27da1 100644 |
| 62 | +--- a/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h |
| 63 | ++++ b/src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h |
| 64 | +@@ -6,6 +6,7 @@ |
| 65 | + #include <altivec.h> |
| 66 | + #include "zbuild.h" |
| 67 | + #include "deflate.h" |
| 68 | ++#include <assert.h> |
| 69 | + |
| 70 | + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { |
| 71 | + const vector unsigned short vmx_wsize = vec_splats(wsize); |
| 72 | +@@ -24,7 +25,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize |
| 73 | + } |
| 74 | + |
| 75 | + void Z_INTERNAL SLIDE_PPC(deflate_state *s) { |
| 76 | +- uint16_t wsize = s->w_size; |
| 77 | ++ assert(s->w_size <= _UI16_MAX); |
| 78 | ++ uint16_t wsize = (uint16_t)s->w_size; |
| 79 | + |
| 80 | + slide_hash_chain(s->head, HASH_SIZE, wsize); |
| 81 | + slide_hash_chain(s->prev, wsize, wsize); |
| 82 | +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 |
| 83 | +index 1164e89ba25..2e758742373 100644 |
| 84 | +--- a/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c |
| 85 | ++++ b/src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c |
| 86 | +@@ -10,6 +10,7 @@ |
| 87 | + |
| 88 | + #include "../../zbuild.h" |
| 89 | + #include "../../deflate.h" |
| 90 | ++#include <assert.h> |
| 91 | + |
| 92 | + static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize) { |
| 93 | + size_t vl; |
| 94 | +@@ -25,6 +26,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize |
| 95 | + } |
| 96 | + |
| 97 | + Z_INTERNAL void slide_hash_rvv(deflate_state *s) { |
| 98 | ++ assert(s->w_size <= _UI16_MAX); |
| 99 | + uint16_t wsize = (uint16_t)s->w_size; |
| 100 | + |
| 101 | + slide_hash_chain(s->head, HASH_SIZE, wsize); |
| 102 | +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 |
| 103 | +index 94fe10c7bf4..144b5672940 100644 |
| 104 | +--- a/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c |
| 105 | ++++ b/src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c |
| 106 | +@@ -13,6 +13,7 @@ |
| 107 | + #include "../../deflate.h" |
| 108 | + |
| 109 | + #include <immintrin.h> |
| 110 | ++#include <assert.h> |
| 111 | + |
| 112 | + static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i wsize) { |
| 113 | + table += entries; |
| 114 | +@@ -31,6 +32,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i |
| 115 | + } |
| 116 | + |
| 117 | + Z_INTERNAL void slide_hash_avx2(deflate_state *s) { |
| 118 | ++ assert(s->w_size <= _UI16_MAX); |
| 119 | + uint16_t wsize = (uint16_t)s->w_size; |
| 120 | + const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize); |
| 121 | + |
| 122 | +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 |
| 123 | +index 5daac4a7398..04db335e3de 100644 |
| 124 | +--- a/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c |
| 125 | ++++ b/src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c |
| 126 | +@@ -52,6 +52,7 @@ next_chain: |
| 127 | + } |
| 128 | + |
| 129 | + Z_INTERNAL void slide_hash_sse2(deflate_state *s) { |
| 130 | ++ assert(s->w_size <= _UI16_MAX); |
| 131 | + uint16_t wsize = (uint16_t)s->w_size; |
| 132 | + const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); |
| 133 | + |
| 134 | +-- |
| 135 | +2.45.2.windows.1 |
| 136 | + |
0 commit comments