diff options
author | Yann Collet <cyan@fb.com> | 2017-03-29 00:10:01 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2017-03-29 00:10:01 (GMT) |
commit | f0a7651fce53f5e85da6140f9d075b730ae6eac7 (patch) | |
tree | 2ed5556ca004b617683260baad52fac2ff2e2ec6 /tests/frametest.c | |
parent | ab547a0ef8e78a5930936b0440020bb779f1d53c (diff) | |
download | lz4-f0a7651fce53f5e85da6140f9d075b730ae6eac7.zip lz4-f0a7651fce53f5e85da6140f9d075b730ae6eac7.tar.gz lz4-f0a7651fce53f5e85da6140f9d075b730ae6eac7.tar.bz2 |
Safer LZ4_getFrameInfo()
LZ4_getFrameInfo() is now guaranteed to keep dctx state clean,
even in case of failure.
Diffstat (limited to 'tests/frametest.c')
-rw-r--r-- | tests/frametest.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/tests/frametest.c b/tests/frametest.c index e2e0f86..f7e3abf 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -276,17 +276,25 @@ int basicTests(U32 seed, double compressibility) if (LZ4F_isError(errorCode)) goto _output_error; DISPLAYLEVEL(3, " %u \n", (unsigned)errorCode); - DISPLAYLEVEL(3, "get FrameInfo on null input : "); - errorCode = LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize); - if (errorCode != (size_t)-LZ4F_ERROR_frameHeader_incomplete) goto _output_error; - DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(errorCode)); + DISPLAYLEVEL(3, "LZ4F_getFrameInfo on zero-size input : "); + { size_t nullSize = 0; + size_t const fiError = LZ4F_getFrameInfo(dCtx, &fi, ip, &nullSize); + if (LZ4F_getErrorCode(fiError) != LZ4F_ERROR_frameHeader_incomplete) { + DISPLAYLEVEL(3, "incorrect error : %s != ERROR_frameHeader_incomplete \n", LZ4F_getErrorName(fiError)); + goto _output_error; + } + DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(fiError)); + } DISPLAYLEVEL(3, "get FrameInfo on not enough input : "); - iSize = 6; - errorCode = LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize); - if (errorCode != (size_t)-LZ4F_ERROR_frameHeader_incomplete) goto _output_error; - DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(errorCode)); - ip += iSize; + { size_t inputSize = 6; + size_t const fiError = LZ4F_getFrameInfo(dCtx, &fi, ip, &inputSize); + if (LZ4F_getErrorCode(fiError) != LZ4F_ERROR_frameHeader_incomplete) { + DISPLAYLEVEL(3, "incorrect error : %s != ERROR_frameHeader_incomplete \n", LZ4F_getErrorName(fiError)); + goto _output_error; + } + DISPLAYLEVEL(3, " correctly failed : %s \n", LZ4F_getErrorName(fiError)); + } DISPLAYLEVEL(3, "get FrameInfo on enough input : "); iSize = 15 - iSize; |