add simple test for maxBlockSize expected functionality
This commit is contained in:
@@ -288,7 +288,7 @@ static int ZSTD_resolveExternalSequenceValidation(int mode) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets the default maximum block size. */
|
/* Resolves maxBlockSize to the default if no value is present. */
|
||||||
static size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize) {
|
static size_t ZSTD_resolveMaxBlockSize(size_t maxBlockSize) {
|
||||||
if (maxBlockSize == 0) {
|
if (maxBlockSize == 0) {
|
||||||
return ZSTD_BLOCKSIZE_MAX;
|
return ZSTD_BLOCKSIZE_MAX;
|
||||||
|
|||||||
+1
-1
@@ -141,7 +141,7 @@ ZSTDLIB_API const char* ZSTD_versionString(void);
|
|||||||
|
|
||||||
#define ZSTD_BLOCKSIZELOG_MAX 17
|
#define ZSTD_BLOCKSIZELOG_MAX 17
|
||||||
#define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
|
#define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX)
|
||||||
#define ZSTD_BLOCKSIZE_MAX_MIN 1 << 10 /* The minimum valid max blocksize. Maximum blocksizes smaller than this make compressBound() inaccurate. */
|
#define ZSTD_BLOCKSIZE_MAX_MIN (1 << 10) /* The minimum valid max blocksize. Maximum blocksizes smaller than this make compressBound() inaccurate. */
|
||||||
|
|
||||||
|
|
||||||
/***************************************
|
/***************************************
|
||||||
|
|||||||
@@ -1925,6 +1925,49 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
|
|||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
|
||||||
|
/* Test maxBlockSize cctx param functionality */
|
||||||
|
DISPLAYLEVEL(3, "test%3i : Testing maxBlockSize PR#3418: ", testNb++);
|
||||||
|
{
|
||||||
|
ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
||||||
|
size_t const srcSize = 2 << 10;
|
||||||
|
void* const src = CNBuffer;
|
||||||
|
size_t const dstSize = ZSTD_compressBound(srcSize);
|
||||||
|
void* const dst1 = compressedBuffer;
|
||||||
|
void* const dst2 = (BYTE*)compressedBuffer + dstSize;
|
||||||
|
size_t size1, size2;
|
||||||
|
void* const checkBuf = malloc(srcSize);
|
||||||
|
|
||||||
|
memset(src, 'x', srcSize);
|
||||||
|
|
||||||
|
/* Quick test to make sure maxBlockSize bounds are enforced */
|
||||||
|
assert(ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_maxBlockSize, ZSTD_BLOCKSIZE_MAX_MIN - 1)));
|
||||||
|
assert(ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_maxBlockSize, ZSTD_BLOCKSIZE_MAX + 1)));
|
||||||
|
|
||||||
|
/* maxBlockSize = 1KB */
|
||||||
|
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_maxBlockSize, 1 << 10));
|
||||||
|
size1 = ZSTD_compress2(cctx, dst1, dstSize, src, srcSize);
|
||||||
|
|
||||||
|
if (ZSTD_isError(size1)) goto _output_error;
|
||||||
|
CHECK_Z(ZSTD_decompress(checkBuf, srcSize, dst1, size1));
|
||||||
|
CHECK(memcmp(src, checkBuf, srcSize) != 0, "Corruption!");
|
||||||
|
|
||||||
|
/* maxBlockSize = 3KB */
|
||||||
|
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_maxBlockSize, 3 << 10));
|
||||||
|
size2 = ZSTD_compress2(cctx, dst2, dstSize, src, srcSize);
|
||||||
|
|
||||||
|
if (ZSTD_isError(size2)) goto _output_error;
|
||||||
|
CHECK_Z(ZSTD_decompress(checkBuf, srcSize, dst2, size2));
|
||||||
|
CHECK(memcmp(src, checkBuf, srcSize) != 0, "Corruption!");
|
||||||
|
|
||||||
|
/* Compressed output should not be equal */
|
||||||
|
assert(memcmp(dst1, dst2, dstSize) != 0);
|
||||||
|
assert(size1 - size2 == 4); /* We add another RLE block with header + character */
|
||||||
|
ZSTD_freeCCtx(cctx);
|
||||||
|
free(checkBuf);
|
||||||
|
}
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
FUZ_freeDictionary(dictionary);
|
FUZ_freeDictionary(dictionary);
|
||||||
ZSTD_freeCStream(zc);
|
ZSTD_freeCStream(zc);
|
||||||
|
|||||||
Reference in New Issue
Block a user