From 32312d57f3c73b61c6b4cb5e3eff422fa6263e6d Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 19 Jan 2024 02:05:16 -0800 Subject: [PATCH] flate: Fix reset with dictionary on custom window encodes (#912) Dictionary was being ignored when compressing with a custom window size. Fixes #911 --- flate/deflate.go | 2 +- flate/deflate_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flate/deflate.go b/flate/deflate.go index de912e187c..66d1657d2c 100644 --- a/flate/deflate.go +++ b/flate/deflate.go @@ -212,7 +212,7 @@ func (d *compressor) writeBlockSkip(tok *tokens, index int, eof bool) error { // Should only be used after a start/reset. func (d *compressor) fillWindow(b []byte) { // Do not fill window if we are in store-only or huffman mode. - if d.level <= 0 { + if d.level <= 0 && d.level > -MinCustomWindowSize { return } if d.fast != nil { diff --git a/flate/deflate_test.go b/flate/deflate_test.go index f9584ceb3a..7390338ce1 100644 --- a/flate/deflate_test.go +++ b/flate/deflate_test.go @@ -538,6 +538,14 @@ func TestWriterReset(t *testing.T) { return w2, nil }) } + testResetOutput(t, fmt.Sprint("dict-reset-window"), func(w io.Writer) (*Writer, error) { + w2, err := NewWriterWindow(nil, 1024) + if err != nil { + return w2, err + } + w2.ResetDict(w, dict) + return w2, nil + }) } func testResetOutput(t *testing.T, name string, newWriter func(w io.Writer) (*Writer, error)) {