Skip to content

Commit 12bc7ed

Browse files
committed
Apply slide_hash and deflate patch with casts and asserts.
1 parent dcd113e commit 12bc7ed

File tree

13 files changed

+26
-11
lines changed

13 files changed

+26
-11
lines changed

src/native/external/zlib-ng/arch/arm/slide_hash_armv6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
3939
}
4040

4141
Z_INTERNAL void slide_hash_armv6(deflate_state *s) {
42-
unsigned int wsize = s->w_size;
42+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
43+
uint16_t wsize = (uint16_t)s->w_size;
4344

4445
slide_hash_chain(s->head, HASH_SIZE, wsize);
4546
slide_hash_chain(s->prev, wsize, wsize);

src/native/external/zlib-ng/arch/arm/slide_hash_neon.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
3838
}
3939

4040
Z_INTERNAL void slide_hash_neon(deflate_state *s) {
41-
unsigned int wsize = s->w_size;
41+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
42+
uint16_t wsize = (uint16_t)s->w_size;
4243

4344
slide_hash_chain(s->head, HASH_SIZE, wsize);
4445
slide_hash_chain(s->prev, wsize, wsize);

src/native/external/zlib-ng/arch/generic/crc32_braid_c.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ Z_INTERNAL uint32_t PREFIX(crc32_braid)(uint32_t crc, const uint8_t *buf, size_t
192192
#endif
193193
#endif
194194
words += N;
195-
c = ZSWAPWORD(comb);
195+
Assert(comb <= UINT32_MAX, "comb should fit in uint32_t");
196+
c = (uint32_t)ZSWAPWORD(comb);
196197

197198
/* Update the pointer to the remaining bytes to process. */
198199
buf = (const unsigned char *)words;

src/native/external/zlib-ng/arch/power/slide_ppc_tpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
2424
}
2525

2626
void Z_INTERNAL SLIDE_PPC(deflate_state *s) {
27-
uint16_t wsize = s->w_size;
27+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
28+
uint16_t wsize = (uint16_t)s->w_size;
2829

2930
slide_hash_chain(s->head, HASH_SIZE, wsize);
3031
slide_hash_chain(s->prev, wsize, wsize);

src/native/external/zlib-ng/arch/riscv/slide_hash_rvv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
2323
}
2424

2525
Z_INTERNAL void slide_hash_rvv(deflate_state *s) {
26+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
2627
uint16_t wsize = (uint16_t)s->w_size;
2728

2829
slide_hash_chain(s->head, HASH_SIZE, wsize);

src/native/external/zlib-ng/arch/x86/slide_hash_avx2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i
3131
}
3232

3333
Z_INTERNAL void slide_hash_avx2(deflate_state *s) {
34+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
3435
uint16_t wsize = (uint16_t)s->w_size;
3536
const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize);
3637

src/native/external/zlib-ng/arch/x86/slide_hash_sse2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0,
5252
}
5353

5454
Z_INTERNAL void slide_hash_sse2(deflate_state *s) {
55+
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
5556
uint16_t wsize = (uint16_t)s->w_size;
5657
const __m128i xmm_wsize = _mm_set1_epi16((short)wsize);
5758

src/native/external/zlib-ng/deflate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Z_INTERNAL deflate_allocs* alloc_deflate(PREFIX3(stream) *strm, int windowBits,
204204

205205
/* Define sizes */
206206
int window_size = DEFLATE_ADJUST_WINDOW_SIZE((1 << windowBits) * 2);
207-
int prev_size = (1 << windowBits) * sizeof(Pos);
207+
int prev_size = (1 << windowBits) * (int)sizeof(Pos);
208208
int head_size = HASH_SIZE * sizeof(Pos);
209209
int pending_size = lit_bufsize * LIT_BUFS;
210210
int state_size = sizeof(deflate_state);

src/native/external/zlib-ng/deflate_fast.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
5858
}
5959

6060
if (match_len >= WANT_MIN_MATCH) {
61-
check_match(s, s->strstart, s->match_start, match_len);
61+
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
62+
Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t");
63+
check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len);
6264

6365
bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH);
6466

src/native/external/zlib-ng/deflate_p.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t le
7878
/* dist: distance of matched string */
7979
/* len: match length-STD_MIN_MATCH */
8080
#ifdef LIT_MEM
81-
s->d_buf[s->sym_next] = dist;
82-
s->l_buf[s->sym_next++] = len;
81+
Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
82+
Assert(len <= UINT8_MAX, "len should fit in uint8_t");
83+
s->d_buf[s->sym_next] = (uint16_t)dist;
84+
s->l_buf[s->sym_next++] = (uint8_t)len;
8385
#else
8486
s->sym_buf[s->sym_next++] = (uint8_t)(dist);
8587
s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8);

0 commit comments

Comments
 (0)