adenilson / rpms / zlib

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