@@ -380,6 +380,9 @@ const fill_window = (s) => {
380380 s . strstart -= _w_size ;
381381 /* we now have strstart >= MAX_DIST */
382382 s . block_start -= _w_size ;
383+ if ( s . insert > s . strstart ) {
384+ s . insert = s . strstart ;
385+ }
383386 slide_hash ( s ) ;
384387 more += _w_size ;
385388 }
@@ -591,6 +594,7 @@ const deflate_stored = (s, flush) => {
591594 //zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
592595 s . window . set ( s . strm . input . subarray ( s . strm . next_in - s . w_size , s . strm . next_in ) , 0 ) ;
593596 s . strstart = s . w_size ;
597+ s . insert = s . strstart ;
594598 }
595599 else {
596600 if ( s . window_size - s . strstart <= used ) {
@@ -601,13 +605,16 @@ const deflate_stored = (s, flush) => {
601605 if ( s . matches < 2 ) {
602606 s . matches ++ ; /* add a pending slide_hash() */
603607 }
608+ if ( s . insert > s . strstart ) {
609+ s . insert = s . strstart ;
610+ }
604611 }
605612 //zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
606613 s . window . set ( s . strm . input . subarray ( s . strm . next_in - used , s . strm . next_in ) , s . strstart ) ;
607614 s . strstart += used ;
615+ s . insert += used > s . w_size - s . insert ? s . w_size - s . insert : used ;
608616 }
609617 s . block_start = s . strstart ;
610- s . insert += used > s . w_size - s . insert ? s . w_size - s . insert : used ;
611618 }
612619 if ( s . high_water < s . strstart ) {
613620 s . high_water = s . strstart ;
@@ -636,13 +643,17 @@ const deflate_stored = (s, flush) => {
636643 s . matches ++ ; /* add a pending slide_hash() */
637644 }
638645 have += s . w_size ; /* more space now */
646+ if ( s . insert > s . strstart ) {
647+ s . insert = s . strstart ;
648+ }
639649 }
640650 if ( have > s . strm . avail_in ) {
641651 have = s . strm . avail_in ;
642652 }
643653 if ( have ) {
644654 read_buf ( s . strm , s . window , s . strstart , have ) ;
645655 s . strstart += have ;
656+ s . insert += have > s . w_size - s . insert ? s . w_size - s . insert : have ;
646657 }
647658 if ( s . high_water < s . strstart ) {
648659 s . high_water = s . strstart ;
0 commit comments