adenilson / rpms / zlib

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