adenilson / rpms / zlib

Forked from rpms/zlib 8 months ago
Clone
c55b40
From 2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0 Mon Sep 17 00:00:00 2001
c55b40
From: Mark Adler <madler@alumni.caltech.edu>
c55b40
Date: Sat, 21 Jan 2017 01:50:26 -0800
c55b40
Subject: [PATCH] Limit hash table inserts after switch from stored deflate.
c55b40
c55b40
This limits hash table inserts to the available data in the window
c55b40
and to the sliding window size in deflate_stored(). The hash table
c55b40
inserts are deferred until deflateParams() switches to a non-zero
c55b40
compression level.
c55b40
---
c55b40
 deflate.c | 10 +++++++++-
c55b40
 1 file changed, 9 insertions(+), 1 deletion(-)
c55b40
c55b40
diff --git a/deflate.c b/deflate.c
c55b40
index 20bda4f..d368b25 100644
c55b40
--- a/deflate.c
c55b40
+++ b/deflate.c
c55b40
@@ -1513,6 +1513,8 @@ local void fill_window(s)
c55b40
             s->match_start -= wsize;
c55b40
             s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
c55b40
             s->block_start -= (long) wsize;
c55b40
+            if (s->insert > s->strstart)
c55b40
+                s->insert = s->strstart;
c55b40
             slide_hash(s);
c55b40
             more += wsize;
c55b40
         }
c55b40
@@ -1742,6 +1744,7 @@ local block_state deflate_stored(s, flush)
c55b40
             s->matches = 2;         /* clear hash */
c55b40
             zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
c55b40
             s->strstart = s->w_size;
c55b40
+            s->insert = s->strstart;
c55b40
         }
c55b40
         else {
c55b40
             if (s->window_size - s->strstart <= used) {
c55b40
@@ -1750,12 +1753,14 @@ local block_state deflate_stored(s, flush)
c55b40
                 zmemcpy(s->window, s->window + s->w_size, s->strstart);
c55b40
                 if (s->matches < 2)
c55b40
                     s->matches++;   /* add a pending slide_hash() */
c55b40
+                if (s->insert > s->strstart)
c55b40
+                    s->insert = s->strstart;
c55b40
             }
c55b40
             zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
c55b40
             s->strstart += used;
c55b40
+            s->insert += MIN(used, s->w_size - s->insert);
c55b40
         }
c55b40
         s->block_start = s->strstart;
c55b40
-        s->insert += MIN(used, s->w_size - s->insert);
c55b40
     }
c55b40
     if (s->high_water < s->strstart)
c55b40
         s->high_water = s->strstart;
c55b40
@@ -1779,12 +1784,15 @@ local block_state deflate_stored(s, flush)
c55b40
         if (s->matches < 2)
c55b40
             s->matches++;           /* add a pending slide_hash() */
c55b40
         have += s->w_size;          /* more space now */
c55b40
+        if (s->insert > s->strstart)
c55b40
+            s->insert = s->strstart;
c55b40
     }
c55b40
     if (have > s->strm->avail_in)
c55b40
         have = s->strm->avail_in;
c55b40
     if (have) {
c55b40
         read_buf(s->strm, s->window + s->strstart, have);
c55b40
         s->strstart += have;
c55b40
+        s->insert += MIN(have, s->w_size - s->insert);
c55b40
     }
c55b40
     if (s->high_water < s->strstart)
c55b40
         s->high_water = s->strstart;
c55b40
-- 
c55b40
2.39.1
c55b40