Limit hash table inserts after switch from stored deflate.

2d80d3f6b5
This commit is contained in:
Alex Kocharin 2022-06-10 17:01:53 +03:00
parent 2326b42e45
commit b579434679

View file

@ -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;