fixed a few remaining ubsan warnings in lz4hc #1160
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
that were previously hidden due to the
-fsanitize-recover=pointer-overflow
flag.The 2 minor instances involve pointer arithmetic with
NULL
ptr.For the record, I also tried to fix a few remaining
ubsan
warnings inlz4.c
,related to pointer overflow arithmetic.
Unfortunately, the fix resulted in a massive drop in performance,
so it's not bundled here.
The issue (in
lz4.c
) is that the code uses a virtual pointer addressbase
as a reference point for its indexing scheme.The
base
pointer itself is never dereferenced, it's always combined with anindex
, in order to reference a valid address.Nevertheless, from a
ubsan
perspective, it's an invalid operation.Fixing that requires changing one variable (
base
) by 2 variables (prefixStart
andprefixIndex
) and an arithmetic operation (currentIndex - prefixIndex
). It's a small difference (one more register, one more addition), but at the speed oflz4
fast mode, it's enough to make a sensible impact on performance.Therefore, removing these last
ubsan
warnings will require finding a good replacement strategy, which doesn't involve a significant speed loss.No such problem in
lz4hc
, which compression speed is much lower, and algorithm is more complex. Consequently, this issue has already been fixed (in previous release) without any noticeable drop in performance.