diff options
author | Yann Collet <cyan@fb.com> | 2021-05-28 08:07:18 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2021-05-28 08:08:18 (GMT) |
commit | 539c783c98f1c9c6ad8db0a97da4295c36701ca7 (patch) | |
tree | 58d4f0dc25b6660fcbd6f1f28cf7d02f6a4b96a5 /lib | |
parent | e73c318a79ddbb93461d22c5101dcf82c83411c9 (diff) | |
download | lz4-539c783c98f1c9c6ad8db0a97da4295c36701ca7.zip lz4-539c783c98f1c9c6ad8db0a97da4295c36701ca7.tar.gz lz4-539c783c98f1c9c6ad8db0a97da4295c36701ca7.tar.bz2 |
fix NULL ptr arithmetic in lz4:1680
only do arithmetic if offset > 0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -1677,15 +1677,18 @@ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) { LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; - const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; - DEBUGLOG(5, "LZ4_saveDict : dictSize=%i, safeBuffer=%p, prevDictEnd=%p", dictSize, safeBuffer, previousDictEnd); + DEBUGLOG(5, "LZ4_saveDict : dictSize=%i, safeBuffer=%p", dictSize, safeBuffer); if ((U32)dictSize > 64 KB) { dictSize = 64 KB; } /* useless to define a dictionary > 64 KB */ if ((U32)dictSize > dict->dictSize) { dictSize = (int)dict->dictSize; } if (safeBuffer == NULL) assert(dictSize == 0); - if (dictSize > 0) memmove(safeBuffer, previousDictEnd - dictSize, dictSize); + if (dictSize > 0) { + const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; + assert(dict->dictionary); + memmove(safeBuffer, previousDictEnd - dictSize, dictSize); + } dict->dictionary = (const BYTE*)safeBuffer; dict->dictSize = (U32)dictSize; |