mirror of
https://github.com/facebook/zstd.git
synced 2025-12-07 00:02:39 -05:00
adapt v0.3 fix to v0.1
slightly different constraints on end of buffer conditions
This commit is contained in:
parent
cfec005efd
commit
7eb4471fec
@ -1720,20 +1720,25 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|||||||
static const int dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; /* added */
|
static const int dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; /* added */
|
||||||
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /* subtracted */
|
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /* subtracted */
|
||||||
const BYTE* const ostart = op;
|
const BYTE* const ostart = op;
|
||||||
|
BYTE* const oLitEnd = op + sequence.litLength;
|
||||||
const size_t litLength = sequence.litLength;
|
const size_t litLength = sequence.litLength;
|
||||||
BYTE* const endMatch = op + litLength + sequence.matchLength; /* risk : address space overflow (32-bits) */
|
BYTE* const endMatch = op + litLength + sequence.matchLength; /* risk : address space overflow (32-bits) */
|
||||||
const BYTE* const litEnd = *litPtr + litLength;
|
const BYTE* const litEnd = *litPtr + litLength;
|
||||||
|
|
||||||
/* check */
|
/* checks */
|
||||||
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
||||||
|
if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
|
||||||
|
|
||||||
if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected);
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
if (sequence.matchLength > (size_t)(*litPtr-op)) return ERROR(dstSize_tooSmall); /* overwrite literal segment */
|
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
if (((size_t)(*litPtr - op) < 8) || ((size_t)(oend-litEnd) < 8) || (op+litLength > oend-8))
|
ZSTD_memmove(op, *litPtr, sequence.litLength); /* note : v0.1 seems to allow scenarios where output or input are close to end of buffer */
|
||||||
memmove(op, *litPtr, litLength); /* overwrite risk */
|
|
||||||
else
|
|
||||||
ZSTD_wildcopy(op, *litPtr, litLength);
|
|
||||||
op += litLength;
|
op += litLength;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user