Skip to content

Commit a5c20ed

Browse files
committed
Add variable 'wbufsize' to track window buffer including padding, to allow
the chunkset code to spill garbage data into the padding area if available.
1 parent 39e9c86 commit a5c20ed

4 files changed

Lines changed: 4 additions & 1 deletion

File tree

infback.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t wi
5555
strm->state = (struct internal_state *)state;
5656
state->wbits = (unsigned int)windowBits;
5757
state->wsize = 1U << windowBits;
58+
state->wbufsize = 1U << windowBits;
5859
state->window = window;
5960
state->wnext = 0;
6061
state->whave = 0;

inffast_tpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
137137
/* Detect if out and window point to the same memory allocation. In this instance it is
138138
necessary to use safe chunk copy functions to prevent overwriting the window. If the
139139
window is overwritten then future matches with far distances will fail to copy correctly. */
140-
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);
140+
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + state->wbufsize);
141141

142142
#define REFILL() do { \
143143
hold |= load_64_bits(in, bits); \

inflate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windo
240240
state = alloc_bufs->state;
241241
state->window = alloc_bufs->window;
242242
state->alloc_bufs = alloc_bufs;
243+
state->wbufsize = INFLATE_ADJUST_WINDOW_SIZE((1 << MAX_WBITS) + 64);
243244
Tracev((stderr, "inflate: allocated\n"));
244245

245246
strm->state = (struct internal_state *)state;

inflate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct ALIGNED_(64) inflate_state {
111111
/* sliding window */
112112
unsigned wbits; /* log base 2 of requested window size */
113113
uint32_t wsize; /* window size or zero if not using window */
114+
uint32_t wbufsize; /* real size of the allocated window buffer, including padding */
114115
uint32_t whave; /* valid bytes in the window */
115116
uint32_t wnext; /* window write index */
116117
unsigned char *window; /* allocated sliding window, if needed */

0 commit comments

Comments
 (0)