From 978886fba95292d70bcfd0f297c19cec4c0a9511 Mon Sep 17 00:00:00 2001 From: Frederic Langlet Date: Mon, 15 Jul 2024 20:42:28 -0700 Subject: [PATCH] Protect against corrupted bitstream --- v2/entropy/ANSRangeCodec.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v2/entropy/ANSRangeCodec.go b/v2/entropy/ANSRangeCodec.go index 5e93294e..7d5e65a9 100644 --- a/v2/entropy/ANSRangeCodec.go +++ b/v2/entropy/ANSRangeCodec.go @@ -874,11 +874,11 @@ func (this *ANSRangeDecoder) decodeChunkV2(block []byte) bool { st2 := int(this.bitstream.ReadBits(32)) st3 := int(this.bitstream.ReadBits(32)) - if sz == 0 { - return len(block) == 0 + if len(block) == 0 { + return true } - minBufSize := max(int(sz+(sz>>3)), len(block)) + minBufSize := max(2*len(block), 256) // protect against corrupted bitstream // Add some padding if len(this.buffer) < minBufSize {