summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-11-07 19:38:07 -0800
committerYann Collet <cyan@fb.com>2020-11-07 19:42:57 -0800
commite251a840253c5564364bf5c8c662a6fe623dc3e9 (patch)
tree4c1cf21414f1feff4f309a2e9fad74fe8b0dff28
parentb16b9fcdbc110876c9cd82ac1c3392abc0c2e1b3 (diff)
downloadlz4-e251a840253c5564364bf5c8c662a6fe623dc3e9.tar.gz
lz4-e251a840253c5564364bf5c8c662a6fe623dc3e9.tar.bz2
lz4-e251a840253c5564364bf5c8c662a6fe623dc3e9.zip
fix minor UBs
- check alignment before casting a pointer - saveDict : don't memmove() on NULL dst
-rw-r--r--lib/lz4.c4
-rw-r--r--lib/lz4hc.c4
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index c41a084..427673e 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1661,7 +1661,9 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize)
if ((U32)dictSize > 64 KB) { dictSize = 64 KB; } /* useless to define a dictionary > 64 KB */
if ((U32)dictSize > dict->dictSize) { dictSize = (int)dict->dictSize; }
- memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
+ if (safeBuffer == NULL) assert(dictSize == 0);
+ if (safeBuffer != NULL)
+ memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
dict->dictionary = (const BYTE*)safeBuffer;
dict->dictSize = (U32)dictSize;
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index a74144a..8875f1a 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -1003,7 +1003,6 @@ int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr)
LZ4_streamHC_t* LZ4_initStreamHC (void* buffer, size_t size)
{
LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)buffer;
- LZ4HC_CCtx_internal* const hcstate = &(LZ4_streamHCPtr->internal_donotuse);
/* if compilation fails here, LZ4_STREAMHCSIZE must be increased */
LZ4_STATIC_ASSERT(sizeof(LZ4HC_CCtx_internal) <= LZ4_STREAMHCSIZE);
DEBUGLOG(4, "LZ4_initStreamHC(%p, %u)", buffer, (unsigned)size);
@@ -1012,7 +1011,8 @@ LZ4_streamHC_t* LZ4_initStreamHC (void* buffer, size_t size)
if (size < sizeof(LZ4_streamHC_t)) return NULL;
if (!LZ4_isAligned(buffer, LZ4_streamHC_t_alignment())) return NULL;
/* init */
- MEM_INIT(hcstate, 0, sizeof(*hcstate));
+ { LZ4HC_CCtx_internal* const hcstate = &(LZ4_streamHCPtr->internal_donotuse);
+ MEM_INIT(hcstate, 0, sizeof(*hcstate)); }
LZ4_setCompressionLevel(LZ4_streamHCPtr, LZ4HC_CLEVEL_DEFAULT);
return LZ4_streamHCPtr;
}