summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-10-05 23:48:45 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-10-05 23:48:45 (GMT)
commitc14a342cc2ed5c963213571ab412657bdcf2b899 (patch)
tree6403950605d634092a3e204c1c6473f6d8a902ed
parentaac3c9ea219e5ecf1fb99e54bccd5a2ae9133613 (diff)
downloadlz4-c14a342cc2ed5c963213571ab412657bdcf2b899.zip
lz4-c14a342cc2ed5c963213571ab412657bdcf2b899.tar.gz
lz4-c14a342cc2ed5c963213571ab412657bdcf2b899.tar.bz2
Fixed : LZ4F_compressBound() using null preferencesPtr
Updated : frametest, to check LZ4F_compressBound() using null preferencesPtr
-rw-r--r--lz4frame.c21
-rw-r--r--programs/frametest.c17
2 files changed, 19 insertions, 19 deletions
diff --git a/lz4frame.c b/lz4frame.c
index 3a750c0..93069e0 100644
--- a/lz4frame.c
+++ b/lz4frame.c
@@ -122,7 +122,7 @@ typedef struct
BYTE* tmpBuff;
BYTE* tmpIn;
size_t tmpInSize;
- XXH32_stateSpace_t xxh;
+ XXH32_state_t xxh;
LZ4_stream_t lz4ctx;
} LZ4F_cctx_internal_t;
@@ -143,7 +143,7 @@ typedef struct
BYTE* tmpOut;
size_t tmpOutSize;
size_t tmpOutStart;
- XXH32_stateSpace_t xxh;
+ XXH32_state_t xxh;
BYTE header[8];
} LZ4F_dctx_internal_t;
@@ -383,7 +383,7 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
}
cctxPtr->tmpIn = cctxPtr->tmpBuff;
cctxPtr->tmpInSize = 0;
- XXH32_resetState(&(cctxPtr->xxh), 0);
+ XXH32_reset(&(cctxPtr->xxh), 0);
LZ4_resetStream(&(cctxPtr->lz4ctx));
/* Magic Number */
@@ -413,13 +413,14 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
* */
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{
- LZ4F_frameInfo_t* frameInfoPtr = (LZ4F_frameInfo_t*)preferencesPtr; /* works because prefs starts with frameInfo */
- blockSizeID_t bid = (frameInfoPtr==NULL) ? LZ4F_BLOCKSIZEID_DEFAULT : frameInfoPtr->blockSizeID;
+ const LZ4F_preferences_t prefsNull = { 0 };
+ const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
+ blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID;
size_t blockSize = LZ4F_getBlockSize(bid);
unsigned nbBlocks = (unsigned)(srcSize / blockSize) + 1;
- size_t lastBlockSize = preferencesPtr->autoFlush ? srcSize % blockSize : blockSize;
+ size_t lastBlockSize = prefsPtr->autoFlush ? srcSize % blockSize : blockSize;
size_t blockInfo = 4; /* default, without block CRC option */
- size_t frameEnd = 4 + (frameInfoPtr->contentChecksumFlag*4);
+ size_t frameEnd = 4 + (prefsPtr->frameInfo.contentChecksumFlag*4);
size_t result = (blockInfo * nbBlocks) + (blockSize * (nbBlocks-1)) + lastBlockSize + frameEnd;
return result;
@@ -628,7 +629,7 @@ size_t LZ4F_compressEnd(LZ4F_compressionContext_t compressionContext, void* dstB
if (cctxPtr->prefs.frameInfo.contentChecksumFlag == contentChecksumEnabled)
{
- U32 xxh = XXH32_intermediateDigest(&(cctxPtr->xxh));
+ U32 xxh = XXH32_digest(&(cctxPtr->xxh));
LZ4F_writeLE32(dstPtr, xxh);
dstPtr+=4; /* content Checksum */
}
@@ -721,7 +722,7 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx_internal_t* dctxPtr, const BYTE* srcPt
dctxPtr->maxBlockSize = LZ4F_getBlockSize(blockSizeID);
/* init */
- if (contentChecksumFlag) XXH32_resetState(&(dctxPtr->xxh), 0);
+ if (contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0);
/* alloc */
bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==blockLinked) * 128 KB);
@@ -1220,7 +1221,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext,
case dstage_checkSuffix:
{
U32 readCRC = LZ4F_readLE32(selectedIn);
- U32 resultCRC = XXH32_intermediateDigest(&(dctxPtr->xxh));
+ U32 resultCRC = XXH32_digest(&(dctxPtr->xxh));
if (readCRC != resultCRC) return (size_t)-ERROR_checksum_invalid;
nextSrcSizeHint = 0;
dctxPtr->dStage = dstage_getHeader;
diff --git a/programs/frametest.c b/programs/frametest.c
index 3d19ef4..343a8ab 100644
--- a/programs/frametest.c
+++ b/programs/frametest.c
@@ -131,7 +131,6 @@ static U32 FUZ_GetMilliSpan(U32 nTimeStart)
}
-
# define FUZ_rotl32(x,r) ((x << r) | (x >> (32 - r)))
unsigned int FUZ_rand(unsigned int* src)
{
@@ -388,7 +387,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
LZ4F_decompressionContext_t dCtx = NULL;
LZ4F_compressionContext_t cCtx = NULL;
size_t result;
- XXH64_stateSpace_t xxh64;
+ XXH64_state_t xxh64;
# define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
DISPLAY(" (seed %u, test nb %u) \n", seed, testNb); goto _output_error; }
@@ -424,21 +423,21 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
size_t srcStart = FUZ_rand(&randState) % (srcDataLength - srcSize);
size_t cSize;
U64 crcOrig, crcDecoded;
+ LZ4F_preferences_t* prefsPtr = &prefs;
(void)FUZ_rand(&coreRand); // update rand seed
prefs.frameInfo.blockMode = BMId;
prefs.frameInfo.blockSizeID = BSId;
prefs.frameInfo.contentChecksumFlag = CCflag;
prefs.autoFlush = autoflush;
+ if ((FUZ_rand(&randState)&0xF) == 1) prefsPtr = NULL;
DISPLAYUPDATE(2, "\r%5u ", testNb);
crcOrig = XXH64((BYTE*)srcBuffer+srcStart, (U32)srcSize, 1);
if ((FUZ_rand(&randState)&0xF) == 2)
{
- LZ4F_preferences_t* framePrefs = &prefs;
- if ((FUZ_rand(&randState)&7) == 1) framePrefs = NULL;
- cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(srcSize, framePrefs), (char*)srcBuffer + srcStart, srcSize, framePrefs);
+ cSize = LZ4F_compressFrame(compressedBuffer, LZ4F_compressFrameBound(srcSize, prefsPtr), (char*)srcBuffer + srcStart, srcSize, prefsPtr);
CHECK(LZ4F_isError(cSize), "LZ4F_compressFrame failed : error %i (%s)", (int)cSize, LZ4F_getErrorName(cSize));
}
else
@@ -448,14 +447,14 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
BYTE* op = compressedBuffer;
BYTE* const oend = op + LZ4F_compressFrameBound(srcDataLength, NULL);
unsigned maxBits = FUZ_highbit((U32)srcSize);
- result = LZ4F_compressBegin(cCtx, op, oend-op, &prefs);
+ result = LZ4F_compressBegin(cCtx, op, oend-op, prefsPtr);
CHECK(LZ4F_isError(result), "Compression header failed (error %i)", (int)result);
op += result;
while (ip < iend)
{
unsigned nbBitsSeg = FUZ_rand(&randState) % maxBits;
size_t iSize = (FUZ_rand(&randState) & ((1<<nbBitsSeg)-1)) + 1;
- size_t oSize = oend-op;
+ size_t oSize = LZ4F_compressBound(iSize, prefsPtr);
unsigned forceFlush = ((FUZ_rand(&randState) & 3) == 1);
if (iSize > (size_t)(iend-ip)) iSize = iend-ip;
cOptions.stableSrc = ((FUZ_rand(&randState) & 3) == 1);
@@ -486,7 +485,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
unsigned maxBits = FUZ_highbit((U32)cSize);
unsigned nonContiguousDst = (FUZ_rand(&randState) & 3) == 1;
nonContiguousDst += FUZ_rand(&randState) & nonContiguousDst; /* 0=>0; 1=>1,2 */
- XXH64_resetState(&xxh64, 1);
+ XXH64_reset(&xxh64, 1);
while (ip < iend)
{
unsigned nbBitsI = (FUZ_rand(&randState) % (maxBits-1)) + 1;
@@ -510,7 +509,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
if (nonContiguousDst==2) op = decodedBuffer; // overwritten destination
}
CHECK(result != 0, "Frame decompression failed (error %i)", (int)result);
- crcDecoded = XXH64_intermediateDigest(&xxh64);
+ crcDecoded = XXH64_digest(&xxh64);
if (crcDecoded != crcOrig) locateBuffDiff((BYTE*)srcBuffer+srcStart, decodedBuffer, srcSize, nonContiguousDst);
CHECK(crcDecoded != crcOrig, "Decompression corruption");
}