ensure lz4f_cctx internal buffer size remain valid in case of malloc error

This commit is contained in:
Yann Collet 2017-04-09 01:11:39 -07:00
parent e169edac05
commit 7eecd32c07

View File

@ -445,10 +445,11 @@ size_t LZ4F_compressBegin(LZ4F_cctx* cctxPtr, void* dstBuffer, size_t dstCapacit
requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB; /* just needs dict */ requiredBuffSize = (cctxPtr->prefs.frameInfo.blockMode == LZ4F_blockLinked) * 64 KB; /* just needs dict */
if (cctxPtr->maxBufferSize < requiredBuffSize) { if (cctxPtr->maxBufferSize < requiredBuffSize) {
cctxPtr->maxBufferSize = requiredBuffSize; cctxPtr->maxBufferSize = 0;
FREEMEM(cctxPtr->tmpBuff); FREEMEM(cctxPtr->tmpBuff);
cctxPtr->tmpBuff = (BYTE*)ALLOCATOR(requiredBuffSize); cctxPtr->tmpBuff = (BYTE*)ALLOCATOR(requiredBuffSize);
if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed); if (cctxPtr->tmpBuff == NULL) return err0r(LZ4F_ERROR_allocation_failed);
cctxPtr->maxBufferSize = requiredBuffSize;
} }
cctxPtr->tmpIn = cctxPtr->tmpBuff; cctxPtr->tmpIn = cctxPtr->tmpBuff;
cctxPtr->tmpInSize = 0; cctxPtr->tmpInSize = 0;