summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2022-07-05 23:31:54 (GMT)
committerGitHub <noreply@github.com>2022-07-05 23:31:54 (GMT)
commit9d20cd519ae62c8864ab237068e4c11490cbd0a9 (patch)
tree1dd7334041d3410b30b4c52892cacdb52866f0ae /tests
parentd3d3fad70c1409bbfafb663dcb5da53de8b757e2 (diff)
parent6e242d1915df794d2f5c337f3bc29146efa98588 (diff)
downloadlz4-9d20cd519ae62c8864ab237068e4c11490cbd0a9.zip
lz4-9d20cd519ae62c8864ab237068e4c11490cbd0a9.tar.gz
lz4-9d20cd519ae62c8864ab237068e4c11490cbd0a9.tar.bz2
Merge pull request #1099 from lz4/pr1094_frametest
Add a fuzzer test for LZ4F_uncompressedUpdate() within frametest
Diffstat (limited to 'tests')
-rw-r--r--tests/frametest.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/tests/frametest.c b/tests/frametest.c
index 09def51..a496c3c 100644
--- a/tests/frametest.c
+++ b/tests/frametest.c
@@ -54,7 +54,7 @@
/* unoptimized version; solves endianness & alignment issues */
static void FUZ_writeLE32 (void* dstVoidPtr, U32 value32)
{
- BYTE* dstPtr = (BYTE*)dstVoidPtr;
+ BYTE* const dstPtr = (BYTE*)dstVoidPtr;
dstPtr[0] = (BYTE) value32;
dstPtr[1] = (BYTE)(value32 >> 8);
dstPtr[2] = (BYTE)(value32 >> 16);
@@ -1015,18 +1015,35 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
while (ip < iend) {
unsigned const nbBitsSeg = FUZ_rand(&randState) % maxBits;
size_t const sampleMax = (FUZ_rand(&randState) & ((1<<nbBitsSeg)-1)) + 1;
- size_t const iSize = MIN(sampleMax, (size_t)(iend-ip));
+ size_t iSize = MIN(sampleMax, (size_t)(iend-ip));
size_t const oSize = LZ4F_compressBound(iSize, prefsPtr);
- size_t flushedSize;
cOptions.stableSrc = ((FUZ_rand(&randState) & 3) == 1);
DISPLAYLEVEL(6, "Sending %u bytes to compress (stableSrc:%u) \n",
(unsigned)iSize, cOptions.stableSrc);
- flushedSize = LZ4F_compressUpdate(cCtx, op, oSize, ip, iSize, &cOptions);
- CHECK(LZ4F_isError(flushedSize), "Compression failed (error %i : %s)",
+#if 1
+ /* insert uncompressed segment */
+ if ( (iSize>0)
+ && !neverFlush /* do not mess with compressBound when neverFlush is set */
+ && prefsPtr != NULL /* prefs are set */
+ && prefs.frameInfo.blockMode == LZ4F_blockIndependent /* uncompressedUpdate is only valid with blockMode==independent */
+ && (FUZ_rand(&randState) & 15) == 1 ) {
+ size_t const uSize = FUZ_rand(&randState) % iSize;
+ size_t const flushedSize = LZ4F_uncompressedUpdate(cCtx, op, (size_t)(oend-op), ip, uSize, &cOptions);
+ CHECK(LZ4F_isError(flushedSize), "Insert uncompressed data failed (error %i : %s)",
(int)flushedSize, LZ4F_getErrorName(flushedSize));
- op += flushedSize;
- ip += iSize;
+ op += flushedSize;
+ ip += uSize;
+ iSize -= uSize;
+ }
+#endif
+
+ { size_t const flushedSize = LZ4F_compressUpdate(cCtx, op, oSize, ip, iSize, &cOptions);
+ CHECK(LZ4F_isError(flushedSize), "Compression failed (error %i : %s)",
+ (int)flushedSize, LZ4F_getErrorName(flushedSize));
+ op += flushedSize;
+ ip += iSize;
+ }
{ unsigned const forceFlush = neverFlush ? 0 : ((FUZ_rand(&randState) & 3) == 1);
if (forceFlush) {
@@ -1040,11 +1057,8 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
op[3] = 0x80; /* 0x80000000U in little-endian format */
op += 4;
if ((prefsPtr!= NULL) && prefsPtr->frameInfo.blockChecksumFlag) {
- U32 const bc32 = XXH32(op, 0, 0);
- op[0] = (BYTE)bc32; /* little endian format */
- op[1] = (BYTE)(bc32>>8);
- op[2] = (BYTE)(bc32>>16);
- op[3] = (BYTE)(bc32>>24);
+ /* add block checksum (even for empty blocks) */
+ FUZ_writeLE32(op, XXH32(op, 0, 0));
op += 4;
} } } }
} /* while (ip<iend) */