[codec,clear] fix integer overflow

reorder check to prevent possible integer overflow
This commit is contained in:
akallabeth 2024-04-16 08:35:05 +02:00 committed by Martin Fleisz
parent d58cbc96ac
commit 1208f23bc9
2 changed files with 10 additions and 6 deletions

View File

@ -409,7 +409,7 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, wStream* s,
}
}
if ((pixelIndex + runLengthFactor) > pixelCount)
if ((pixelIndex >= pixelCount) || (runLengthFactor > (pixelCount - pixelIndex)))
{
WLog_ERR(TAG,
"pixelIndex %" PRIu32 " + runLengthFactor %" PRIu32 " > pixelCount %" PRIu32

View File

@ -227,7 +227,10 @@ static BOOL zgfx_decompress_segment(ZGFX_CONTEXT* zgfx, wStream* stream, size_t
BYTE* pbSegment = NULL;
size_t cbSegment = 0;
if (!zgfx || !stream || (segmentSize < 2))
WINPR_ASSERT(zgfx);
WINPR_ASSERT(stream);
if (segmentSize < 2)
return FALSE;
cbSegment = segmentSize - 1;
@ -346,8 +349,9 @@ static BOOL zgfx_decompress_segment(ZGFX_CONTEXT* zgfx, wStream* stream, size_t
if (count > sizeof(zgfx->OutputBuffer) - zgfx->OutputCount)
return FALSE;
if (count > zgfx->cBitsRemaining / 8)
else if (count > zgfx->cBitsRemaining / 8)
return FALSE;
else if (zgfx->pbInputCurrent + count > zgfx->pbInputEnd)
return FALSE;
CopyMemory(&(zgfx->OutputBuffer[zgfx->OutputCount]), zgfx->pbInputCurrent,
@ -386,8 +390,8 @@ int zgfx_decompress(ZGFX_CONTEXT* zgfx, const BYTE* pSrcData, UINT32 SrcSize, BY
wStream sbuffer = { 0 };
wStream* stream = Stream_StaticConstInit(&sbuffer, pSrcData, SrcSize);
if (!stream)
return -1;
WINPR_ASSERT(zgfx);
WINPR_ASSERT(stream);
if (!Stream_CheckAndLogRequiredLength(TAG, stream, 1))
goto fail;