From b57943467960b179931f42fa94445f4211d4afda Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 10 Jun 2022 17:01:53 +0300 Subject: [PATCH] Limit hash table inserts after switch from stored deflate. https://github.com/madler/zlib/commit/2d80d3f6b52f9fa454c26c89d2d6a1790e1cecb0 --- lib/zlib/deflate.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index b7a2d3f..59e8578 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -380,6 +380,9 @@ const fill_window = (s) => { s.strstart -= _w_size; /* we now have strstart >= MAX_DIST */ s.block_start -= _w_size; + if (s.insert > s.strstart) { + s.insert = s.strstart; + } slide_hash(s); more += _w_size; } @@ -591,6 +594,7 @@ const deflate_stored = (s, flush) => { //zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size); s.window.set(s.strm.input.subarray(s.strm.next_in - s.w_size, s.strm.next_in), 0); s.strstart = s.w_size; + s.insert = s.strstart; } else { if (s.window_size - s.strstart <= used) { @@ -601,13 +605,16 @@ const deflate_stored = (s, flush) => { if (s.matches < 2) { s.matches++; /* add a pending slide_hash() */ } + if (s.insert > s.strstart) { + s.insert = s.strstart; + } } //zmemcpy(s->window + s->strstart, s->strm->next_in - used, used); s.window.set(s.strm.input.subarray(s.strm.next_in - used, s.strm.next_in), s.strstart); s.strstart += used; + s.insert += used > s.w_size - s.insert ? s.w_size - s.insert : used; } s.block_start = s.strstart; - s.insert += used > s.w_size - s.insert ? s.w_size - s.insert : used; } if (s.high_water < s.strstart) { s.high_water = s.strstart; @@ -636,6 +643,9 @@ const deflate_stored = (s, flush) => { 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; @@ -643,6 +653,7 @@ const deflate_stored = (s, flush) => { if (have) { read_buf(s.strm, s.window, s.strstart, have); s.strstart += have; + s.insert += have > s.w_size - s.insert ? s.w_size - s.insert : have; } if (s.high_water < s.strstart) { s.high_water = s.strstart;