diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2018-10-09 22:37:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-09 22:37:55 (GMT) |
commit | df6d00ede56ef97af3461cdc94721a2706ba73c3 (patch) | |
tree | 6d8871d3adb6625b78d9846b627730d7169dd239 /tests | |
parent | 637245958f44fe9f2e45eb80eb68a627c34ab638 (diff) | |
parent | 6902fa48925ed22cd37bb4262205437feb8d2420 (diff) | |
download | lz4-df6d00ede56ef97af3461cdc94721a2706ba73c3.zip lz4-df6d00ede56ef97af3461cdc94721a2706ba73c3.tar.gz lz4-df6d00ede56ef97af3461cdc94721a2706ba73c3.tar.bz2 |
Merge pull request #592 from lz4/compressEnd
fix LZ4F_compressEnd()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/frametest.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/frametest.c b/tests/frametest.c index f8498b7..6d2cdd0 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -857,8 +857,18 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi } } } CHECK(op>=oend, "LZ4F_compressFrameBound overflow"); - result = LZ4F_compressEnd(cCtx, op, oend-op, &cOptions); - CHECK(LZ4F_isError(result), "Compression completion failed (error %i : %s)", (int)result, LZ4F_getErrorName(result)); + { size_t const dstEndSafeSize = LZ4F_compressBound(0, prefsPtr); + int const tooSmallDstEnd = ((FUZ_rand(&randState) & 31) == 3); + size_t const dstEndTooSmallSize = (FUZ_rand(&randState) % dstEndSafeSize) + 1; + size_t const dstEndSize = tooSmallDstEnd ? dstEndTooSmallSize : dstEndSafeSize; + BYTE const canaryByte = (BYTE)(FUZ_rand(&randState) & 255); + op[dstEndSize] = canaryByte; + result = LZ4F_compressEnd(cCtx, op, dstEndSize, &cOptions); + CHECK(op[dstEndSize] != canaryByte, "LZ4F_compressEnd writes beyond dstCapacity !"); + if (LZ4F_isError(result)) { + if (tooSmallDstEnd) /* failure is allowed */ continue; + CHECK(1, "Compression completion failed (error %i : %s)", (int)result, LZ4F_getErrorName(result)); + } } op += result; cSize = op-(BYTE*)compressedBuffer; DISPLAYLEVEL(5, "\nCompressed %u bytes into %u \n", (U32)srcSize, (U32)cSize); |