summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlexander Gallego <alex@vectorized.io>2020-07-08 15:21:45 (GMT)
committerAlexander Gallego <alex@vectorized.io>2020-07-08 15:30:07 (GMT)
commite68c7d38780ada518e6c43a09a2d92421ea8111b (patch)
treee6eef71097e78ffc37ed53a4ca689b27018f9603 /lib
parent49b3ad4bd41311e92fc3a18eda571800bde5aa42 (diff)
downloadlz4-e68c7d38780ada518e6c43a09a2d92421ea8111b.zip
lz4-e68c7d38780ada518e6c43a09a2d92421ea8111b.tar.gz
lz4-e68c7d38780ada518e6c43a09a2d92421ea8111b.tar.bz2
avoid computing 0 offsets from null pointers
Similar work in the kernel: https://patchwork.kernel.org/patch/11351499/ UBsan (+clang-10) complains about doing pointer arithmetic (adding 0) to a nullpointer. This patch is tested with clang-10+ubsan
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 82ab490..2f7880a 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -819,7 +819,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
int const maybe_extMem = (dictDirective == usingExtDict) || (dictDirective == usingDictCtx);
U32 const prefixIdxLimit = startIndex - dictSize; /* used when dictDirective == dictSmall */
- const BYTE* const dictEnd = dictionary + dictSize;
+ const BYTE* const dictEnd = dictionary ? dictionary + dictSize : dictionary;
const BYTE* anchor = (const BYTE*) source;
const BYTE* const iend = ip + inputSize;
const BYTE* const mflimitPlusOne = iend - MFLIMIT + 1;
@@ -827,7 +827,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
/* the dictCtx currentOffset is indexed on the start of the dictionary,
* while a dictionary in the current context precedes the currentOffset */
- const BYTE* dictBase = (dictDirective == usingDictCtx) ?
+ const BYTE* dictBase = !dictionary ? NULL : (dictDirective == usingDictCtx) ?
dictionary + dictSize - dictCtx->currentOffset :
dictionary + dictSize - startIndex;