]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add variable 'wbufsize' to track window buffer including padding, to allow
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 25 Sep 2024 15:21:28 +0000 (17:21 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 8 Oct 2024 13:51:12 +0000 (15:51 +0200)
the chunkset code to spill garbage data into the padding area if available.

infback.c
inffast_tpl.h
inflate.c
inflate.h

index 6e5dcd03e82091716a859323f7fb8cd4d52e96f5..0f5b51f78bca27fcbde9d3bc65f03cf0cc4d29c6 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -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;
index cd5c79e8cb58223a8f26d4792f296749f0210370..1b36acaa35340a53117b918819344ab176dbeb32 100644 (file)
@@ -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); \
index fdf80c0722c5738931f84cb94ec39c163cd8d04d..2ce508f8d03b728da0d6f816e6786686f15e59b2 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -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;
index 7fd6c44cf05e4bd8c4e45227ff7d8763d0605c0c..66e6129d28e2201eccb65f645a13e62795dd6a4c 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -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 */