From acc81a28c526d31ad553663f068664bfa0f9e99e Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 10 Mar 2022 11:42:26 +0100 Subject: [PATCH] zstd: Revert "Disallow 0 sized compressed blocks" Fixes #526 Bonus, use `ignorecrc` for disabling crc checks in while fuzzing. --- zstd/blockdec.go | 6 +++--- zstd/fuzz.go | 4 ++-- zstd/fuzz_none.go | 4 ++-- zstd/testdata/bad.zip | Bin 9418 -> 9243 bytes zstd/testdata/good.zip | Bin 2848 -> 3023 bytes 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zstd/blockdec.go b/zstd/blockdec.go index 50abf56569..7d567a54a0 100644 --- a/zstd/blockdec.go +++ b/zstd/blockdec.go @@ -167,9 +167,9 @@ func (b *blockDec) reset(br byteBuffer, windowSize uint64) error { } return ErrCompressedSizeTooBig } - // Empty compressed blocks not valid in practice, - // see https://github.com/facebook/zstd/issues/3090 - if cSize < 3 { + // Empty compressed blocks must at least be 2 bytes + // for Literals_Block_Type and one for Sequences_Section_Header. + if cSize < 2 { return ErrBlockTooSmall } case blockTypeRaw: diff --git a/zstd/fuzz.go b/zstd/fuzz.go index fda8a74228..7f2210e053 100644 --- a/zstd/fuzz.go +++ b/zstd/fuzz.go @@ -1,5 +1,5 @@ -//go:build gofuzz -// +build gofuzz +//go:build ignorecrc +// +build ignorecrc // Copyright 2019+ Klaus Post. All rights reserved. // License information can be found in the LICENSE file. diff --git a/zstd/fuzz_none.go b/zstd/fuzz_none.go index 0515b201cc..6811c68a89 100644 --- a/zstd/fuzz_none.go +++ b/zstd/fuzz_none.go @@ -1,5 +1,5 @@ -//go:build !gofuzz -// +build !gofuzz +//go:build !ignorecrc +// +build !ignorecrc // Copyright 2019+ Klaus Post. All rights reserved. // License information can be found in the LICENSE file. diff --git a/zstd/testdata/bad.zip b/zstd/testdata/bad.zip index 15be3cd510a159ed6d4ca9618c9c43fd837bf744..28f061286759aa4f08da1e947fd8d1b990ea1d3d 100644 GIT binary patch delta 41 ucmX@*Ioo4{p7`W66_L%;#Y=gB3^_)X$*n5pd^!v|4D~z=3~k~JKmY(34hmoZ delta 205 zcmbR3amsUpp18kfUS^0_o)a540|NsH>j1Hlk-15Vv0ELv0+kbO0r3s zWm-x~ie<88nxUadvQe5|RdLDX8>{|bZ*ZK#$iWcc&CD`+qq5XyC-G7qFKh+_%?1Jm pAXX74-kQnFmGzh^#V0$6>xl(;v$BEA&;`PqJPZuCf#xtU003wqF}45z diff --git a/zstd/testdata/good.zip b/zstd/testdata/good.zip index f6c230bc5d5b3e9d2d4ff61de33f30f411c2bc1a..e38a0f275c89970328d62780225caccd865a97d5 100644 GIT binary patch delta 207 zcmZ1=c3ynLI@Vxj77+#}1`Y<#yvz`lw^}M%e0h~6w74GG($s^WTP~_s^XH%H&*?>-rzWek%M9L8rB5XJVquF2HZvi dO$P!6AYQ{tnneNLtZX2?;y}0qsFxAU0|3WmE#LqE delta 33 kcmX>vzCdilI@Zn1Y;mk2tZWQGAO?hStPBimfS7>+0E4^*egFUf