mirror of
https://github.com/facebook/zstd.git
synced 2025-12-03 00:03:20 -05:00
fixed address space overflow (32-bits mode)
This commit is contained in:
parent
52732b505d
commit
7fe531e7ec
@ -1898,40 +1898,12 @@ typedef size_t (*ZSTD_blockCompressor) (ZSTD_CCtx* ctx, void* dst, size_t maxDst
|
||||
|
||||
static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict)
|
||||
{
|
||||
if (extDict)
|
||||
{
|
||||
switch(strat)
|
||||
{
|
||||
default :
|
||||
case ZSTD_fast:
|
||||
return ZSTD_compressBlock_fast_extDict;
|
||||
case ZSTD_greedy:
|
||||
return ZSTD_compressBlock_greedy_extDict;
|
||||
case ZSTD_lazy:
|
||||
return ZSTD_compressBlock_lazy_extDict;
|
||||
case ZSTD_lazy2:
|
||||
return ZSTD_compressBlock_lazy2_extDict;
|
||||
case ZSTD_btlazy2:
|
||||
return ZSTD_compressBlock_btlazy2_extDict;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(strat)
|
||||
{
|
||||
default :
|
||||
case ZSTD_fast:
|
||||
return ZSTD_compressBlock_fast;
|
||||
case ZSTD_greedy:
|
||||
return ZSTD_compressBlock_greedy;
|
||||
case ZSTD_lazy:
|
||||
return ZSTD_compressBlock_lazy;
|
||||
case ZSTD_lazy2:
|
||||
return ZSTD_compressBlock_lazy2;
|
||||
case ZSTD_btlazy2:
|
||||
return ZSTD_compressBlock_btlazy2;
|
||||
}
|
||||
}
|
||||
static const ZSTD_blockCompressor blockCompressor[2][5] = {
|
||||
{ ZSTD_compressBlock_fast, ZSTD_compressBlock_greedy, ZSTD_compressBlock_lazy,ZSTD_compressBlock_lazy2, ZSTD_compressBlock_btlazy2 },
|
||||
{ ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_greedy_extDict, ZSTD_compressBlock_lazy_extDict,ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict }
|
||||
};
|
||||
|
||||
return blockCompressor[extDict][(U32)strat];
|
||||
}
|
||||
|
||||
|
||||
@ -1953,7 +1925,6 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* ctxPtr,
|
||||
BYTE* const ostart = (BYTE*)dst;
|
||||
BYTE* op = ostart;
|
||||
const U32 maxDist = 1 << ctxPtr->params.windowLog;
|
||||
//const ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(ctxPtr->params.strategy, ctxPtr->lowLimit < ctxPtr->dictLimit);
|
||||
|
||||
while (remaining)
|
||||
{
|
||||
@ -1969,7 +1940,6 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* ctxPtr,
|
||||
if (ctxPtr->dictLimit < ctxPtr->lowLimit) ctxPtr->dictLimit = ctxPtr->lowLimit;
|
||||
}
|
||||
|
||||
//cSize = blockCompressor(ctxPtr, op+3, maxDstSize-3, ip, blockSize);
|
||||
cSize = ZSTD_compressBlock(ctxPtr, op+3, maxDstSize-3, ip, blockSize);
|
||||
if (ZSTD_isError(cSize)) return cSize;
|
||||
|
||||
@ -2003,9 +1973,9 @@ size_t ZSTD_compressContinue (ZSTD_CCtx* zc,
|
||||
const BYTE* const ip = (const BYTE*) src;
|
||||
|
||||
/* preemptive overflow correction */
|
||||
if (zc->lowLimit > (1<<30) )
|
||||
if ((zc->base > (const BYTE*)dst) || (zc->lowLimit > (1<<30) ))
|
||||
{
|
||||
U32 correction = zc->lowLimit;
|
||||
U32 correction = zc->lowLimit-1;
|
||||
ZSTD_reduceIndex(zc, correction);
|
||||
zc->base += correction;
|
||||
zc->dictBase += correction;
|
||||
|
||||
@ -903,7 +903,7 @@ int optimizeForSize(char* inFileName)
|
||||
ZSTD_parameters params;
|
||||
winnerInfo_t winner;
|
||||
BMK_result_t candidate;
|
||||
const size_t blockSize = g_blockSize ? g_blockSize : inFileSize;
|
||||
const size_t blockSize = g_blockSize ? g_blockSize : benchedSize;
|
||||
int i;
|
||||
|
||||
/* init */
|
||||
@ -916,17 +916,17 @@ int optimizeForSize(char* inFileName)
|
||||
for (i=1; i<=maxSeeds; i++)
|
||||
{
|
||||
params = ZSTD_getParams(i, blockSize);
|
||||
BMK_benchParam(&candidate, origBuff, inFileSize, ctx, params);
|
||||
BMK_benchParam(&candidate, origBuff, benchedSize, ctx, params);
|
||||
if ( (candidate.cSize < winner.result.cSize)
|
||||
||((candidate.cSize == winner.result.cSize) && (candidate.cSpeed > winner.result.cSpeed)) )
|
||||
{
|
||||
winner.params = params;
|
||||
winner.result = candidate;
|
||||
BMK_printWinner(stdout, i, winner.result, winner.params, inFileSize);
|
||||
BMK_printWinner(stdout, i, winner.result, winner.params, benchedSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, inFileSize);
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize);
|
||||
|
||||
/* start tests */
|
||||
{
|
||||
@ -942,7 +942,7 @@ int optimizeForSize(char* inFileName)
|
||||
|
||||
/* test */
|
||||
NB_TESTS_PLAYED(params)++;
|
||||
BMK_benchParam(&candidate, origBuff, inFileSize, ctx, params);
|
||||
BMK_benchParam(&candidate, origBuff, benchedSize, ctx, params);
|
||||
|
||||
/* improvement found => new winner */
|
||||
if ( (candidate.cSize < winner.result.cSize)
|
||||
@ -950,14 +950,14 @@ int optimizeForSize(char* inFileName)
|
||||
{
|
||||
winner.params = params;
|
||||
winner.result = candidate;
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, inFileSize);
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize);
|
||||
}
|
||||
|
||||
} while (BMK_GetMilliSpan(milliStart) < g_grillDuration);
|
||||
}
|
||||
|
||||
/* end summary */
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, inFileSize);
|
||||
BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize);
|
||||
DISPLAY("grillParams size - optimizer completed \n");
|
||||
|
||||
/* clean up*/
|
||||
@ -1163,7 +1163,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (filenamesStart==0)
|
||||
result = benchSample();
|
||||
else
|
||||
else
|
||||
{
|
||||
if (optimizer)
|
||||
result = optimizeForSize(input_filename);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user