summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2020-11-06 20:27:42 -0800
committerGitHub <noreply@github.com>2020-11-06 20:27:42 -0800
commitb5e2a4acd953fd21fef2c372d9750992d454e76f (patch)
treea877dc0ba0603cae293d241a4362675c62f668a3
parent1008b8929e43175b8d772729f4045f7272aad6dc (diff)
parent67e661a2ad39258bcb5c6fcc31c9239ff3aabc71 (diff)
downloadlz4-b5e2a4acd953fd21fef2c372d9750992d454e76f.tar.gz
lz4-b5e2a4acd953fd21fef2c372d9750992d454e76f.tar.bz2
lz4-b5e2a4acd953fd21fef2c372d9750992d454e76f.zip
Merge pull request #936 from lz4/alignTest
More alignment tests
-rw-r--r--.travis.yml7
-rw-r--r--appveyor.yml12
-rw-r--r--lib/README.md4
-rw-r--r--lib/lz4.c31
-rw-r--r--lib/lz4.h60
-rw-r--r--lib/lz4hc.c35
-rw-r--r--lib/lz4hc.h55
-rw-r--r--tests/fuzzer.c94
8 files changed, 155 insertions, 143 deletions
diff --git a/.travis.yml b/.travis.yml
index 6074f08..2281394 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -47,18 +47,15 @@ matrix:
- make clean travis-install
- make clean clangtest
-
- # 14.04 LTS Server Edition 64 bit
- - name: (Trusty) i386 gcc test
- dist: trusty
+ - name: x32 compatibility test
addons:
apt:
packages:
- - libc6-dev-i386
- gcc-multilib
script:
- make -C tests test MOREFLAGS=-mx32
+ # 14.04 LTS Server Edition 64 bit
# presume clang >= v3.9.0
- name: (Trusty) USan test
dist: trusty
diff --git a/appveyor.yml b/appveyor.yml
index 57b6dda..31894d3 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -47,10 +47,14 @@ build_script:
make -v &&
echo ----- &&
if not [%PLATFORM%]==[clang] (
- make -C programs lz4 && make -C tests fullbench && make -C lib lib
+ make -C programs lz4 &&
+ make -C tests fullbench &&
+ make -C tests fuzzer &&
+ make -C lib lib
) ELSE (
make -C programs lz4 CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" &&
make -C tests fullbench CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" &&
+ make -C tests fuzzer CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion" &&
make -C lib lib CC=clang MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wconversion -Wno-sign-conversion"
)
)
@@ -77,7 +81,7 @@ build_script:
7z.exe a bin\lz4_x86.zip NEWS .\bin\lz4.exe .\bin\README.md .\bin\example .\bin\dll .\bin\static .\bin\include &&
appveyor PushArtifact bin\lz4_x86.zip
)
- - if [%COMPILER%]==[gcc] (COPY tests\fullbench.exe programs\)
+ - if [%COMPILER%]==[gcc] (COPY tests\*.exe programs\)
- if [%COMPILER%]==[visual] (
ECHO *** &&
ECHO *** Building Visual Studio 2010 %PLATFORM%\%CONFIGURATION% &&
@@ -110,7 +114,9 @@ test_script:
lz4 -i1b10 lz4.exe &&
lz4 -i1b15 lz4.exe &&
echo ------- lz4 tested ------- &&
- fullbench.exe -i1 fullbench.exe
+ fullbench.exe -i1 fullbench.exe &&
+ echo trying to launch fuzzer.exe &&
+ fuzzer.exe -v -T30s
)
artifacts:
diff --git a/lib/README.md b/lib/README.md
index 3653c81..ee5d3ba 100644
--- a/lib/README.md
+++ b/lib/README.md
@@ -77,6 +77,10 @@ The following build macro can be selected to adjust source code behavior at comp
In most cases, it's not expected to be necessary,
but it can be legitimately considered for less common platforms.
+- `LZ4_ALIGN_TEST` : alignment test ensures that the memory area
+ passed as argument to become a compression state is suitable aligned.
+ This test can be disabled, if it proves flaky, by setting this value to 0.
+
#### Amalgamation
diff --git a/lib/lz4.c b/lib/lz4.c
index 6adfafd..9d547e5 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -178,6 +178,12 @@
#define unlikely(expr) expect((expr) != 0, 0)
#endif
+/* Should the alignment test prove unreliable, for some reason,
+ * it can be disabled by setting LZ4_ALIGN_TEST to 0 */
+#ifndef LZ4_ALIGN_TEST /* can be externally provided */
+# define LZ4_ALIGN_TEST 1
+#endif
+
/*-************************************
* Memory routines
@@ -243,6 +249,11 @@ static const int LZ4_minLength = (MFLIMIT+1);
# define DEBUGLOG(l, ...) {} /* disabled */
#endif
+static int LZ4_isAligned(const void* ptr, size_t alignment)
+{
+ return ((size_t)ptr & (alignment -1)) == 0;
+}
+
/*-************************************
* Types
@@ -457,7 +468,7 @@ LZ4_memcpy_using_offset(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const si
switch(offset) {
case 1:
- memset(v, *srcPtr, 8);
+ MEM_INIT(v, *srcPtr, 8);
break;
case 2:
LZ4_memcpy(v, srcPtr, 2);
@@ -1406,27 +1417,23 @@ LZ4_stream_t* LZ4_createStream(void)
return lz4s;
}
-#ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 :
- it reports an aligment of 8-bytes,
- while actually aligning LZ4_stream_t on 4 bytes. */
static size_t LZ4_stream_t_alignment(void)
{
+#if LZ4_ALIGN_TEST
typedef struct { char c; LZ4_stream_t t; } t_a;
return sizeof(t_a) - sizeof(LZ4_stream_t);
-}
+#else
+ return 1; /* effectively disabled */
#endif
+}
LZ4_stream_t* LZ4_initStream (void* buffer, size_t size)
{
DEBUGLOG(5, "LZ4_initStream");
if (buffer == NULL) { return NULL; }
if (size < sizeof(LZ4_stream_t)) { return NULL; }
-#ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 :
- it reports an aligment of 8-bytes,
- while actually aligning LZ4_stream_t on 4 bytes. */
- if (((size_t)buffer) & (LZ4_stream_t_alignment() - 1)) { return NULL; } /* alignment check */
-#endif
- MEM_INIT(buffer, 0, sizeof(LZ4_stream_t));
+ if (!LZ4_isAligned(buffer, LZ4_stream_t_alignment())) return NULL;
+ MEM_INIT(buffer, 0, sizeof(LZ4_stream_t_internal));
return (LZ4_stream_t*)buffer;
}
@@ -1435,7 +1442,7 @@ LZ4_stream_t* LZ4_initStream (void* buffer, size_t size)
void LZ4_resetStream (LZ4_stream_t* LZ4_stream)
{
DEBUGLOG(5, "LZ4_resetStream (ctx:%p)", LZ4_stream);
- MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
+ MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t_internal));
}
void LZ4_resetStream_fast(LZ4_stream_t* ctx) {
diff --git a/lib/lz4.h b/lib/lz4.h
index b11275e..c4324af 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -573,68 +573,60 @@ LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const
**************************************************************
* Do not use these definitions directly.
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
- * Accessing members will expose code to API and/or ABI break in future versions of the library.
+ * Accessing members will expose user code to API and/or ABI break in future versions of the library.
**************************************************************/
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
-#include <stdint.h>
-
-typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
-struct LZ4_stream_t_internal {
- uint32_t hashTable[LZ4_HASH_SIZE_U32];
- uint32_t currentOffset;
- uint32_t tableType;
- const uint8_t* dictionary;
- const LZ4_stream_t_internal* dictCtx;
- uint32_t dictSize;
-};
-
-typedef struct {
- const uint8_t* externalDict;
- size_t extDictSize;
- const uint8_t* prefixEnd;
- size_t prefixSize;
-} LZ4_streamDecode_t_internal;
-
+# include <stdint.h>
+ typedef int8_t LZ4_i8;
+ typedef uint8_t LZ4_byte;
+ typedef uint16_t LZ4_u16;
+ typedef uint32_t LZ4_u32;
#else
+ typedef signed char LZ4_i8;
+ typedef unsigned char LZ4_byte;
+ typedef unsigned short LZ4_u16;
+ typedef unsigned int LZ4_u32;
+#endif
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
struct LZ4_stream_t_internal {
- unsigned int hashTable[LZ4_HASH_SIZE_U32];
- unsigned int currentOffset;
- unsigned int tableType;
- const unsigned char* dictionary;
+ LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
+ LZ4_u32 currentOffset;
+ LZ4_u32 tableType;
+ const LZ4_byte* dictionary;
const LZ4_stream_t_internal* dictCtx;
- unsigned int dictSize;
+ LZ4_u32 dictSize;
};
typedef struct {
- const unsigned char* externalDict;
- const unsigned char* prefixEnd;
+ const LZ4_byte* externalDict;
size_t extDictSize;
+ const LZ4_byte* prefixEnd;
size_t prefixSize;
} LZ4_streamDecode_t_internal;
-#endif
/*! LZ4_stream_t :
- * information structure to track an LZ4 stream.
+ * Do not use below internal definitions directly !
+ * Declare or allocate an LZ4_stream_t instead.
* LZ4_stream_t can also be created using LZ4_createStream(), which is recommended.
* The structure definition can be convenient for static allocation
* (on stack, or as part of larger structure).
* Init this structure with LZ4_initStream() before first use.
* note : only use this definition in association with static linking !
- * this definition is not API/ABI safe, and may change in a future version.
+ * this definition is not API/ABI safe, and may change in future versions.
*/
-#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4 + ((sizeof(void*)==16) ? 4 : 0) /*AS-400*/ )
-#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
+#define LZ4_STREAMSIZE 16416 /* static size, for inter-version compatibility */
+#define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*))
union LZ4_stream_u {
- unsigned long long table[LZ4_STREAMSIZE_U64];
+ void* table[LZ4_STREAMSIZE_VOIDP];
LZ4_stream_t_internal internal_donotuse;
-} ; /* previously typedef'd to LZ4_stream_t */
+}; /* previously typedef'd to LZ4_stream_t */
+
/*! LZ4_initStream() : v1.9.0+
* An LZ4_stream_t structure must be initialized at least once.
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index a126c83..15bedec 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -53,7 +53,7 @@
#include "lz4hc.h"
-/*=== Common LZ4 definitions ===*/
+/*=== Common definitions ===*/
#if defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wunused-function"
#endif
@@ -61,15 +61,16 @@
# pragma clang diagnostic ignored "-Wunused-function"
#endif
-/*=== Enums ===*/
-typedef enum { noDictCtx, usingDictCtxHc } dictCtx_directive;
-
-
#define LZ4_COMMONDEFS_ONLY
#ifndef LZ4_SRC_INCLUDED
#include "lz4.c" /* LZ4_count, constants, mem */
#endif
+
+/*=== Enums ===*/
+typedef enum { noDictCtx, usingDictCtxHc } dictCtx_directive;
+
+
/*=== Constants ===*/
#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)
#define LZ4_OPT_NUM (1<<12)
@@ -161,8 +162,7 @@ int LZ4HC_countBack(const BYTE* const ip, const BYTE* const match,
LZ4_FORCE_INLINE U32 LZ4HC_rotatePattern(size_t const rotate, U32 const pattern)
{
size_t const bitsToRotate = (rotate & (sizeof(pattern) - 1)) << 3;
- if (bitsToRotate == 0)
- return pattern;
+ if (bitsToRotate == 0) return pattern;
return LZ4HC_rotl32(pattern, (int)bitsToRotate);
}
@@ -919,27 +919,22 @@ LZ4HC_compress_generic (
int LZ4_sizeofStateHC(void) { return (int)sizeof(LZ4_streamHC_t); }
-#ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 :
- * it reports an aligment of 8-bytes,
- * while actually aligning LZ4_streamHC_t on 4 bytes. */
static size_t LZ4_streamHC_t_alignment(void)
{
+#if LZ4_ALIGN_TEST
typedef struct { char c; LZ4_streamHC_t t; } t_a;
return sizeof(t_a) - sizeof(LZ4_streamHC_t);
-}
+#else
+ return 1; /* effectively disabled */
#endif
+}
/* state is presumed correctly initialized,
* in which case its size and alignment have already been validate */
int LZ4_compress_HC_extStateHC_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel)
{
LZ4HC_CCtx_internal* const ctx = &((LZ4_streamHC_t*)state)->internal_donotuse;
-#ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 :
- * it reports an aligment of 8-bytes,
- * while actually aligning LZ4_streamHC_t on 4 bytes. */
- assert(((size_t)state & (LZ4_streamHC_t_alignment() - 1)) == 0); /* check alignment */
-#endif
- if (((size_t)(state)&(sizeof(void*)-1)) != 0) return 0; /* Error : state is not aligned for pointers (32 or 64 bits) */
+ if (!LZ4_isAligned(state, LZ4_streamHC_t_alignment())) return 0;
LZ4_resetStreamHC_fast((LZ4_streamHC_t*)state, compressionLevel);
LZ4HC_init_internal (ctx, (const BYTE*)src);
if (dstCapacity < LZ4_compressBound(srcSize))
@@ -1010,11 +1005,7 @@ LZ4_streamHC_t* LZ4_initStreamHC (void* buffer, size_t size)
LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)buffer;
if (buffer == NULL) return NULL;
if (size < sizeof(LZ4_streamHC_t)) return NULL;
-#ifndef _MSC_VER /* for some reason, Visual fails the aligment test on 32-bit x86 :
- * it reports an aligment of 8-bytes,
- * while actually aligning LZ4_streamHC_t on 4 bytes. */
- if (((size_t)buffer) & (LZ4_streamHC_t_alignment() - 1)) return NULL; /* alignment check */
-#endif
+ if (!LZ4_isAligned(buffer, LZ4_streamHC_t_alignment())) return NULL;
/* if compilation fails here, LZ4_STREAMHCSIZE must be increased */
LZ4_STATIC_ASSERT(sizeof(LZ4HC_CCtx_internal) <= LZ4_STREAMHCSIZE);
DEBUGLOG(4, "LZ4_initStreamHC(%p, %u)", LZ4_streamHCPtr, (unsigned)size);
diff --git a/lib/lz4hc.h b/lib/lz4hc.h
index 44e35bb..3d441fb 100644
--- a/lib/lz4hc.h
+++ b/lib/lz4hc.h
@@ -198,57 +198,32 @@ LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, in
#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
-#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
-#include <stdint.h>
-
-typedef struct LZ4HC_CCtx_internal LZ4HC_CCtx_internal;
-struct LZ4HC_CCtx_internal
-{
- uint32_t hashTable[LZ4HC_HASHTABLESIZE];
- uint16_t chainTable[LZ4HC_MAXD];
- const uint8_t* end; /* next block here to continue on current prefix */
- const uint8_t* base; /* All index relative to this position */
- const uint8_t* dictBase; /* alternate base for extDict */
- uint32_t dictLimit; /* below that point, need extDict */
- uint32_t lowLimit; /* below that point, no more dict */
- uint32_t nextToUpdate; /* index from which to continue dictionary update */
- short compressionLevel;
- int8_t favorDecSpeed; /* favor decompression speed if this flag set,
- otherwise, favor compression ratio */
- int8_t dirty; /* stream has to be fully reset if this flag is set */
- const LZ4HC_CCtx_internal* dictCtx;
-};
-
-#else
-
typedef struct LZ4HC_CCtx_internal LZ4HC_CCtx_internal;
struct LZ4HC_CCtx_internal
{
- unsigned int hashTable[LZ4HC_HASHTABLESIZE];
- unsigned short chainTable[LZ4HC_MAXD];
- const unsigned char* end; /* next block here to continue on current prefix */
- const unsigned char* base; /* All index relative to this position */
- const unsigned char* dictBase; /* alternate base for extDict */
- unsigned int dictLimit; /* below that point, need extDict */
- unsigned int lowLimit; /* below that point, no more dict */
- unsigned int nextToUpdate; /* index from which to continue dictionary update */
- short compressionLevel;
- char favorDecSpeed; /* favor decompression speed if this flag set,
- otherwise, favor compression ratio */
- char dirty; /* stream has to be fully reset if this flag is set */
+ LZ4_u32 hashTable[LZ4HC_HASHTABLESIZE];
+ LZ4_u16 chainTable[LZ4HC_MAXD];
+ const LZ4_byte* end; /* next block here to continue on current prefix */
+ const LZ4_byte* base; /* All index relative to this position */
+ const LZ4_byte* dictBase; /* alternate base for extDict */
+ LZ4_u32 dictLimit; /* below that point, need extDict */
+ LZ4_u32 lowLimit; /* below that point, no more dict */
+ LZ4_u32 nextToUpdate; /* index from which to continue dictionary update */
+ short compressionLevel;
+ LZ4_i8 favorDecSpeed; /* favor decompression speed if this flag set,
+ otherwise, favor compression ratio */
+ LZ4_i8 dirty; /* stream has to be fully reset if this flag is set */
const LZ4HC_CCtx_internal* dictCtx;
};
-#endif
-
/* Do not use these definitions directly !
* Declare or allocate an LZ4_streamHC_t instead.
*/
-#define LZ4_STREAMHCSIZE (4*LZ4HC_HASHTABLESIZE + 2*LZ4HC_MAXD + 56 + ((sizeof(void*)==16) ? 56 : 0) /* AS400*/ ) /* 262200 or 262256*/
-#define LZ4_STREAMHCSIZE_SIZET (LZ4_STREAMHCSIZE / sizeof(size_t))
+#define LZ4_STREAMHCSIZE 262200 /* static size, for inter-version compatibility */
+#define LZ4_STREAMHCSIZE_VOIDP (LZ4_STREAMHCSIZE / sizeof(void*))
union LZ4_streamHC_u {
- size_t table[LZ4_STREAMHCSIZE_SIZET];
+ void* table[LZ4_STREAMHCSIZE_VOIDP];
LZ4HC_CCtx_internal internal_donotuse;
}; /* previously typedef'd to LZ4_streamHC_t */
diff --git a/tests/fuzzer.c b/tests/fuzzer.c
index 6c2ccb7..29c6a8a 100644
--- a/tests/fuzzer.c
+++ b/tests/fuzzer.c
@@ -1125,27 +1125,47 @@ static void FUZ_unitTests(int compressionLevel)
} } } } }
DISPLAYLEVEL(3, " OK \n");
- /* LZ4 streaming tests */
- { LZ4_stream_t streamingState;
- U64 crcOrig;
- int result;
+ DISPLAYLEVEL(3, "LZ4_initStream with multiple valid alignments : ");
+ { typedef struct {
+ LZ4_stream_t state1;
+ LZ4_stream_t state2;
+ char c;
+ LZ4_stream_t state3;
+ } shct;
+ shct* const shc = (shct*)malloc(sizeof(*shc));
+ assert(shc != NULL);
+ memset(shc, 0, sizeof(*shc));
+ DISPLAYLEVEL(3, "state1(%p) state2(%p) state3(%p) size(0x%x): ",
+ &(shc->state1), &(shc->state2), &(shc->state3), (unsigned)sizeof(LZ4_stream_t));
+ FUZ_CHECKTEST( LZ4_initStream(&(shc->state1), sizeof(shc->state1)) == NULL, "state1 (%p) failed init", &(shc->state1) );
+ FUZ_CHECKTEST( LZ4_initStream(&(shc->state2), sizeof(shc->state2)) == NULL, "state2 (%p) failed init", &(shc->state2) );
+ FUZ_CHECKTEST( LZ4_initStream(&(shc->state3), sizeof(shc->state3)) == NULL, "state3 (%p) failed init", &(shc->state3) );
+ FUZ_CHECKTEST( LZ4_initStream((char*)&(shc->state1) + 1, sizeof(shc->state1)) != NULL,
+ "hc1+1 (%p) init must fail, due to bad alignment", (char*)&(shc->state1) + 1 );
+ free(shc);
+ }
+ DISPLAYLEVEL(3, "all inits OK \n");
- /* Allocation test */
- { LZ4_stream_t* const statePtr = LZ4_createStream();
- FUZ_CHECKTEST(statePtr==NULL, "LZ4_createStream() allocation failed");
- LZ4_freeStream(statePtr);
- }
+ /* Allocation test */
+ { LZ4_stream_t* const statePtr = LZ4_createStream();
+ FUZ_CHECKTEST(statePtr==NULL, "LZ4_createStream() allocation failed");
+ LZ4_freeStream(statePtr);
+ }
- /* simple compression test */
- crcOrig = XXH64(testInput, testCompressedSize, 0);
- LZ4_initStream(&streamingState, sizeof(streamingState));
- result = LZ4_compress_fast_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1, 1);
- FUZ_CHECKTEST(result==0, "LZ4_compress_fast_continue() compression failed!");
+ /* LZ4 streaming tests */
+ { LZ4_stream_t streamingState;
- result = LZ4_decompress_safe(testCompressed, testVerify, result, testCompressedSize);
- FUZ_CHECKTEST(result!=(int)testCompressedSize, "LZ4_decompress_safe() decompression failed");
- { U64 const crcNew = XXH64(testVerify, testCompressedSize, 0);
- FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption"); }
+ /* simple compression test */
+ { U64 const crcOrig = XXH64(testInput, testCompressedSize, 0);
+ LZ4_initStream(&streamingState, sizeof(streamingState));
+ { int const cs = LZ4_compress_fast_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1, 1);
+ FUZ_CHECKTEST(cs==0, "LZ4_compress_fast_continue() compression failed!");
+ { int const r = LZ4_decompress_safe(testCompressed, testVerify, cs, testCompressedSize);
+ FUZ_CHECKTEST(r!=(int)testCompressedSize, "LZ4_decompress_safe() decompression failed");
+ } }
+ { U64 const crcNew = XXH64(testVerify, testCompressedSize, 0);
+ FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe() decompression corruption");
+ } }
/* ring buffer test */
{ XXH64_state_t xxhOrig;
@@ -1167,7 +1187,7 @@ static void FUZ_unitTests(int compressionLevel)
LZ4_setStreamDecode(&decodeStateFast, NULL, 0);
while (iNext + messageSize < testCompressedSize) {
- int compressedSize;
+ int compressedSize; U64 crcOrig;
XXH64_update(&xxhOrig, testInput + iNext, messageSize);
crcOrig = XXH64_digest(&xxhOrig);
@@ -1175,15 +1195,15 @@ static void FUZ_unitTests(int compressionLevel)
compressedSize = LZ4_compress_fast_continue(&streamingState, ringBuffer + rNext, testCompressed, (int)messageSize, testCompressedSize-ringBufferSize, 1);
FUZ_CHECKTEST(compressedSize==0, "LZ4_compress_fast_continue() compression failed");
- result = LZ4_decompress_safe_continue(&decodeStateSafe, testCompressed, testVerify + dNext, compressedSize, (int)messageSize);
- FUZ_CHECKTEST(result!=(int)messageSize, "ringBuffer : LZ4_decompress_safe_continue() test failed");
+ { int const r = LZ4_decompress_safe_continue(&decodeStateSafe, testCompressed, testVerify + dNext, compressedSize, (int)messageSize);
+ FUZ_CHECKTEST(r!=(int)messageSize, "ringBuffer : LZ4_decompress_safe_continue() test failed"); }
XXH64_update(&xxhNewSafe, testVerify + dNext, messageSize);
{ U64 const crcNew = XXH64_digest(&xxhNewSafe);
FUZ_CHECKTEST(crcOrig!=crcNew, "LZ4_decompress_safe_continue() decompression corruption"); }
- result = LZ4_decompress_fast_continue(&decodeStateFast, testCompressed, testVerify + dNext, (int)messageSize);
- FUZ_CHECKTEST(result!=compressedSize, "ringBuffer : LZ4_decompress_fast_continue() test failed");
+ { int const r = LZ4_decompress_fast_continue(&decodeStateFast, testCompressed, testVerify + dNext, (int)messageSize);
+ FUZ_CHECKTEST(r!=compressedSize, "ringBuffer : LZ4_decompress_fast_continue() test failed"); }
XXH64_update(&xxhNewFast, testVerify + dNext, messageSize);
{ U64 const crcNew = XXH64_digest(&xxhNewFast);
@@ -1196,9 +1216,29 @@ static void FUZ_unitTests(int compressionLevel)
messageSize = (FUZ_rand(&randState) & maxMessageSizeMask) + 1;
if (rNext + messageSize > ringBufferSize) rNext = 0;
if (dNext + messageSize > dBufferSize) dNext = 0;
- }
- }
+ } }
+ }
+
+ DISPLAYLEVEL(3, "LZ4_initStreamHC with multiple valid alignments : ");
+ { typedef struct {
+ LZ4_streamHC_t hc1;
+ LZ4_streamHC_t hc2;
+ char c;
+ LZ4_streamHC_t hc3;
+ } shct;
+ shct* const shc = (shct*)malloc(sizeof(*shc));
+ assert(shc != NULL);
+ memset(shc, 0, sizeof(*shc));
+ DISPLAYLEVEL(3, "hc1(%p) hc2(%p) hc3(%p) size(0x%x): ",
+ &(shc->hc1), &(shc->hc2), &(shc->hc3), (unsigned)sizeof(LZ4_streamHC_t));
+ FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc1), sizeof(shc->hc1)) == NULL, "hc1 (%p) failed init", &(shc->hc1) );
+ FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc2), sizeof(shc->hc2)) == NULL, "hc2 (%p) failed init", &(shc->hc2) );
+ FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc3), sizeof(shc->hc3)) == NULL, "hc3 (%p) failed init", &(shc->hc3) );
+ FUZ_CHECKTEST( LZ4_initStreamHC((char*)&(shc->hc1) + 1, sizeof(shc->hc1)) != NULL,
+ "hc1+1 (%p) init must fail, due to bad alignment", (char*)&(shc->hc1) + 1 );
+ free(shc);
}
+ DISPLAYLEVEL(3, "all inits OK \n");
/* LZ4 HC streaming tests */
{ LZ4_streamHC_t sHC; /* statically allocated */
@@ -1211,7 +1251,7 @@ static void FUZ_unitTests(int compressionLevel)
FUZ_CHECKTEST(sp==NULL, "LZ4_createStreamHC() allocation failed");
LZ4_freeStreamHC(sp);
}
- DISPLAYLEVEL(3, " OK \n");
+ DISPLAYLEVEL(3, "OK \n");
/* simple HC compression test */
DISPLAYLEVEL(3, "Simple HC round-trip : ");
@@ -1226,7 +1266,7 @@ static void FUZ_unitTests(int compressionLevel)
{ U64 const crcNew = XXH64(testVerify, testCompressedSize, 0);
FUZ_CHECKTEST(crc64!=crcNew, "LZ4_decompress_safe() decompression corruption");
} }
- DISPLAYLEVEL(3, " OK \n");
+ DISPLAYLEVEL(3, "OK \n");
/* long sequence test */
DISPLAYLEVEL(3, "Long sequence HC_destSize test : ");