Minimal fix for CVE-2020-8927 diff --git a/c/dec/bit_reader.h b/c/dec/bit_reader.h index c06e914..4eff695 100644 --- a/c/dec/bit_reader.h +++ b/c/dec/bit_reader.h @@ -87,8 +87,11 @@ static BROTLI_INLINE uint32_t BrotliGetAvailableBits( } /* Returns amount of unread bytes the bit reader still has buffered from the - BrotliInput, including whole bytes in br->val_. */ + BrotliInput, including whole bytes in br->val_. Result is capped with + maximal ring-buffer size (larger number won't be utilized anyway). */ static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) { + static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS; + if (br->avail_in > kCap) return kCap; return br->avail_in + (BrotliGetAvailableBits(br) >> 3); }