From: Yann Collet Date: Sun, 24 Jul 2016 16:02:04 +0000 (+0200) Subject: fixes oob read X-Git-Tag: v0.8.0^2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbc5e9dc197e5d673f61fefe34d749fcbe44e276;p=thirdparty%2Fzstd.git fixes oob read --- diff --git a/lib/common/entropy_common.c b/lib/common/entropy_common.c index 4b79324bc..acd966999 100644 --- a/lib/common/entropy_common.c +++ b/lib/common/entropy_common.c @@ -93,18 +93,18 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t if (previous0) { unsigned n0 = charnum; while ((bitStream & 0xFFFF) == 0xFFFF) { - n0+=24; + n0 += 24; if (ip < iend-5) { - ip+=2; + ip += 2; bitStream = MEM_readLE32(ip) >> bitCount; } else { bitStream >>= 16; - bitCount+=16; + bitCount += 16; } } while ((bitStream & 3) == 3) { - n0+=3; - bitStream>>=2; - bitCount+=2; + n0 += 3; + bitStream >>= 2; + bitCount += 2; } n0 += bitStream & 3; bitCount += 2; @@ -148,6 +148,7 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t bitStream = MEM_readLE32(ip) >> (bitCount & 31); } } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */ if (remaining != 1) return ERROR(corruption_detected); + if (bitCount > 32) return ERROR(corruption_detected); *maxSVPtr = charnum-1; ip += (bitCount+7)>>3; diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 05ee19b76..cc61627f2 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -536,14 +536,12 @@ size_t ZSTD_decodeSeqHeaders(int* nbSeqPtr, } /* FSE table descriptors */ + if (ip+4 > iend) return ERROR(srcSize_wrong); /* minimum possible size */ { symbolEncodingType_e const LLtype = (symbolEncodingType_e)(*ip >> 6); symbolEncodingType_e const OFtype = (symbolEncodingType_e)((*ip >> 4) & 3); symbolEncodingType_e const MLtype = (symbolEncodingType_e)((*ip >> 2) & 3); ip++; - /* check */ - if (ip > iend-3) return ERROR(srcSize_wrong); /* min : all 3 are "raw", hence no header, but at least xxLog bits per type */ - /* Build DTables */ { size_t const llhSize = ZSTD_buildSeqTable(DTableLL, LLtype, MaxLL, LLFSELog, ip, iend-ip, LL_defaultNorm, LL_defaultNormLog, flagRepeatTable); if (ZSTD_isError(llhSize)) return ERROR(corruption_detected);