From eaf4b06330d96d58d043f862d1c25f4bc8db7f37 Mon Sep 17 00:00:00 2001 From: Vianney Tran Date: Wed, 6 Apr 2022 17:28:16 -0400 Subject: [PATCH] [zstd_test] Add a test for ZipBomb payload on Decompress See https://github.com/DataDog/zstd/issues/60 --- zstd_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zstd_test.go b/zstd_test.go index 399b69a..b7299cc 100644 --- a/zstd_test.go +++ b/zstd_test.go @@ -2,6 +2,7 @@ package zstd import ( "bytes" + b64 "encoding/base64" "errors" "fmt" "io/ioutil" @@ -284,6 +285,14 @@ func TestLegacy(t *testing.T) { } } +func TestBadPayloadZipBomb(t *testing.T) { + payload, _ := b64.StdEncoding.DecodeString("KLUv/dcwMDAwMDAwMDAwMAAA") + _, err := Decompress(nil, payload) + if err.Error() != "Src size is incorrect" { + t.Fatal("zstd should detect that the size is incorrect") + } +} + func BenchmarkCompression(b *testing.B) { if raw == nil { b.Fatal(ErrNoPayloadEnv)