From 06b07e175e397bca54c808780251fe0d7a56deae Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 7 Jan 2021 10:21:48 +0100 Subject: [PATCH] Don't trigger UBSan warning in LZ4_resetStreamHC_fast if LZ4_streamHCPtr->internal_donotuse.end is NULL. --- lib/lz4hc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index feee612..e2e4f00 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -1031,7 +1031,11 @@ void LZ4_resetStreamHC_fast (LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLev LZ4_initStreamHC(LZ4_streamHCPtr, sizeof(*LZ4_streamHCPtr)); } else { /* preserve end - base : can trigger clearTable's threshold */ - LZ4_streamHCPtr->internal_donotuse.end -= (uptrval)LZ4_streamHCPtr->internal_donotuse.base; + if (LZ4_streamHCPtr->internal_donotuse.end != NULL) { + LZ4_streamHCPtr->internal_donotuse.end -= (uptrval)LZ4_streamHCPtr->internal_donotuse.base; + } else { + assert(LZ4_streamHCPtr->internal_donotuse.base == NULL); + } LZ4_streamHCPtr->internal_donotuse.base = NULL; LZ4_streamHCPtr->internal_donotuse.dictCtx = NULL; }