Ensure output.Write is not called outside of the stream decompressor function

This commit is contained in:
Kovid Goyal
2023-07-25 06:43:07 +05:30
parent 301f309444
commit b3819d3226
2 changed files with 67 additions and 8 deletions

View File

@@ -33,4 +33,25 @@ func TestStreamDecompressor(t *testing.T) {
if !bytes.Equal(o.Bytes(), input) {
t.Fatalf("Roundtripping via zlib failed output (%d) != input (%d)", len(o.Bytes()), len(input))
}
o.Reset()
sd = NewStreamDecompressor(zlib.NewReader, &o)
err := sd([]byte("abcd"), true)
if err == nil {
t.Fatalf("Did not get an invalid header error from zlib")
}
o.Reset()
sd = NewStreamDecompressor(zlib.NewReader, &o)
err = sd(b.Bytes(), false)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(o.Bytes(), input) {
t.Fatalf("Roundtripping via zlib failed output (%d) != input (%d)", len(o.Bytes()), len(input))
}
err = sd([]byte("extra trailing data"), true)
if err == nil {
t.Fatalf("Did not get an invalid header error from zlib")
}
}