Skip to content

Commit

Permalink
Add variable 'wbufsize' to track window buffer including padding, to …
Browse files Browse the repository at this point in the history
…allow

the chunkset code to spill garbage data into the padding area if available.
  • Loading branch information
Dead2 committed Oct 8, 2024
1 parent 39e9c86 commit a5c20ed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t wi
strm->state = (struct internal_state *)state;
state->wbits = (unsigned int)windowBits;
state->wsize = 1U << windowBits;
state->wbufsize = 1U << windowBits;
state->window = window;
state->wnext = 0;
state->whave = 0;
Expand Down
2 changes: 1 addition & 1 deletion inffast_tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
/* Detect if out and window point to the same memory allocation. In this instance it is
necessary to use safe chunk copy functions to prevent overwriting the window. If the
window is overwritten then future matches with far distances will fail to copy correctly. */
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);
extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + state->wbufsize);

#define REFILL() do { \
hold |= load_64_bits(in, bits); \
Expand Down
1 change: 1 addition & 0 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windo
state = alloc_bufs->state;
state->window = alloc_bufs->window;
state->alloc_bufs = alloc_bufs;
state->wbufsize = INFLATE_ADJUST_WINDOW_SIZE((1 << MAX_WBITS) + 64);
Tracev((stderr, "inflate: allocated\n"));

strm->state = (struct internal_state *)state;
Expand Down
1 change: 1 addition & 0 deletions inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct ALIGNED_(64) inflate_state {
/* sliding window */
unsigned wbits; /* log base 2 of requested window size */
uint32_t wsize; /* window size or zero if not using window */
uint32_t wbufsize; /* real size of the allocated window buffer, including padding */
uint32_t whave; /* valid bytes in the window */
uint32_t wnext; /* window write index */
unsigned char *window; /* allocated sliding window, if needed */
Expand Down

0 comments on commit a5c20ed

Please sign in to comment.