]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Limit hash table inserts after switch from stored deflate.
authorMark Adler <madler@alumni.caltech.edu>
Sat, 21 Jan 2017 09:50:26 +0000 (01:50 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 15 Jan 2019 11:13:03 +0000 (12:13 +0100)
This limits hash table inserts to the available data in the window
and to the sliding window size in deflate_stored(). The hash table
inserts are deferred until deflateParams() switches to a non-zero
compression level.

deflate.c

index fc48a31d73eb721b50ed7071b52d7d37d242d212..9746302e0631d27757cebf41203f52ff62cafef3 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -1248,7 +1248,8 @@ void ZLIB_INTERNAL fill_window_c(deflate_state *s) {
             s->match_start -= wsize;
             s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
             s->block_start -= (long) wsize;
-
+            if (s->insert > s->strstart)
+                s->insert = s->strstart;
             slide_hash(s);
             more += wsize;
         }
@@ -1451,6 +1452,7 @@ static block_state deflate_stored(deflate_state *s, int flush) {
             s->matches = 2;         /* clear hash */
             memcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
             s->strstart = s->w_size;
+            s->insert = s->strstart;
         }
         else {
             if (s->window_size - s->strstart <= used) {
@@ -1459,12 +1461,14 @@ static block_state deflate_stored(deflate_state *s, int flush) {
                 memcpy(s->window, s->window + s->w_size, s->strstart);
                 if (s->matches < 2)
                     s->matches++;   /* add a pending slide_hash() */
+                if (s->insert > s->strstart)
+                    s->insert = s->strstart;
             }
             memcpy(s->window + s->strstart, s->strm->next_in - used, used);
             s->strstart += used;
+            s->insert += MIN(used, s->w_size - s->insert);
         }
         s->block_start = s->strstart;
-        s->insert += MIN(used, s->w_size - s->insert);
     }
     if (s->high_water < s->strstart)
         s->high_water = s->strstart;
@@ -1488,12 +1492,15 @@ static block_state deflate_stored(deflate_state *s, int flush) {
         if (s->matches < 2)
             s->matches++;           /* add a pending slide_hash() */
         have += s->w_size;          /* more space now */
+        if (s->insert > s->strstart)
+            s->insert = s->strstart;
     }
     if (have > s->strm->avail_in)
         have = s->strm->avail_in;
     if (have) {
         read_buf(s->strm, s->window + s->strstart, have);
         s->strstart += have;
+        s->insert += MIN(have, s->w_size - s->insert);
     }
     if (s->high_water < s->strstart)
         s->high_water = s->strstart;