mirror of
https://github.com/google/brotli.git
synced 2026-09-23 07:05:31 +00:00
Undefined behavior detected by ubsan #7
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @nemequ on GitHub (Apr 13, 2015).
ubsan detects a lot of unaligned stores/loads, as well as a signed integer overflow, and a left shift of a negative value:
@nemequ commented on GitHub (Jun 13, 2015):
Probably related (warnings from clang):
@eustas commented on GitHub (Sep 1, 2015):
Unaligned loads/stores in bit_reader are intentional. We carefully profiled and decided to use them for better performance.
I'm going to take a look at overflow/shifting issues soon.
@nemequ commented on GitHub (Sep 1, 2015):
FWIW at least clang and, to a lesser extent, gcc are pretty good about generating fast code for memcpy with fixed sizes. Newer versions of GCC are better, but still not optimal. It might be worth it to keep an eye on that GCC bug and revisit the issue once it is resolved… unaligned accesses can cause problems down the road when the CC starts optimizing things better (this happened to LZ4 recently).
@rygorous commented on GitHub (Sep 22, 2015):
Unaligned loads/stores: the "official"/safe way to do an unaligned 32-bit load from "p" is:
Store likewise via memcpy. I know this is really gross, but I've run into several compilers that get really aggressive about assuming that loads/stores are aligned, and all major C/C++ compilers actually detect this type of use of memcpy and turn it into the unaligned loads/stores you want. I would prefer not to have to do this kind of thing, but compilers tend to get more pedantic about spec-lawyering all the time, and especially ARM compilers like to combine adjacent LDRs (which do not require alignment on ARMv6+) into LDRDs (which do), which has caused "fun" portability problems for me in the past.
@eustas commented on GitHub (Sep 23, 2015):
We're going to make unaligned safer and more portable soon. So, stay tuned.
@eustas commented on GitHub (Sep 28, 2015):
Fixed with PR 183.
Compiling with -DBROTLI_BUILD_PORTABLE avoids overlapping memcpy and unaligned reads.