Skip to content

Commit

Permalink
flate: Fix reset with dictionary on custom window encodes (#912)
Browse files Browse the repository at this point in the history
Dictionary was being ignored when compressing with a custom window size.

Fixes #911
  • Loading branch information
klauspost authored Jan 19, 2024
1 parent d9b6e1e commit 32312d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flate/deflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions flate/deflate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 32312d5

Please sign in to comment.