Compare commits

...
3 Commits
Author SHA1 Message Date
Yann Collet 9e618350d4 Merge pull request #51 from Cyan4973/dev
Fixed issues reported by Hanno Böck (@hannob)
2015-10-24 15:06:42 +02:00
Yann Collet 3e8fbabfa8 fixed issue #50, reported by Hanno Böck (@hannob) 2015-10-23 14:30:30 +01:00
Yann Collet 40603ffb24 fixed issue #49, reported by Hanno Böck (@hannob) 2015-10-23 12:23:09 +01:00
2 changed files with 16 additions and 7 deletions
+1
View File
@@ -602,6 +602,7 @@ static size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
/* get last non-null symbol weight (implied, total must be 2^n) */ /* get last non-null symbol weight (implied, total must be 2^n) */
tableLog = BIT_highbit32(weightTotal) + 1; tableLog = BIT_highbit32(weightTotal) + 1;
if (tableLog > HUF_ABSOLUTEMAX_TABLELOG) return ERROR(corruption_detected);
{ {
U32 total = 1 << tableLog; U32 total = 1 << tableLog;
U32 rest = total - weightTotal; U32 rest = total - weightTotal;
+15 -7
View File
@@ -1031,7 +1031,7 @@ struct ZSTD_DCtx_s
const BYTE* litPtr; const BYTE* litPtr;
size_t litBufSize; size_t litBufSize;
size_t litSize; size_t litSize;
BYTE litBuffer[BLOCKSIZE]; BYTE litBuffer[BLOCKSIZE + 8 /* margin for wildcopy */];
}; /* typedef'd to ZSTD_Dctx within "zstd_static.h" */ }; /* typedef'd to ZSTD_Dctx within "zstd_static.h" */
@@ -1098,17 +1098,25 @@ size_t ZSTD_decodeLiteralsBlock(void* ctx,
default: default:
case 0: case 0:
{ {
size_t nbLiterals = BLOCKSIZE; size_t litSize = BLOCKSIZE;
const size_t readSize = ZSTD_decompressLiterals(dctx->litBuffer, &nbLiterals, src, srcSize); const size_t readSize = ZSTD_decompressLiterals(dctx->litBuffer, &litSize, src, srcSize);
dctx->litPtr = dctx->litBuffer; dctx->litPtr = dctx->litBuffer;
dctx->litBufSize = BLOCKSIZE; dctx->litBufSize = BLOCKSIZE;
dctx->litSize = nbLiterals; dctx->litSize = litSize;
return readSize; /* works if it's an error too */ return readSize; /* works if it's an error too */
} }
case IS_RAW: case IS_RAW:
{ {
const size_t litSize = (MEM_readLE32(istart) & 0xFFFFFF) >> 2; /* no buffer issue : srcSize >= MIN_CBLOCK_SIZE */ const size_t litSize = (MEM_readLE32(istart) & 0xFFFFFF) >> 2; /* no buffer issue : srcSize >= MIN_CBLOCK_SIZE */
if (litSize > srcSize-3) return ERROR(corruption_detected); if (litSize > srcSize-11) /* risk of reading too far with wildcopy */
{
if (litSize > srcSize-3) return ERROR(corruption_detected);
memcpy(dctx->litBuffer, istart, litSize);
dctx->litBufSize = BLOCKSIZE;
dctx->litSize = litSize;
return litSize+3;
}
/* direct reference into compressed stream */
dctx->litPtr = istart+3; dctx->litPtr = istart+3;
dctx->litBufSize = srcSize-3; dctx->litBufSize = srcSize-3;
dctx->litSize = litSize; dctx->litSize = litSize;
@@ -1328,10 +1336,10 @@ static size_t ZSTD_execSequence(BYTE* op,
BYTE* const oend_8 = oend-8; BYTE* const oend_8 = oend-8;
const BYTE* const litEnd = *litPtr + sequence.litLength; const BYTE* const litEnd = *litPtr + sequence.litLength;
/* check */ /* checks */
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */ if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */ if (litEnd > litLimit-8) return ERROR(corruption_detected); /* overRead beyond lit buffer */
/* copy Literals */ /* copy Literals */
ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */ ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */