Fix UBSan error (ptr + offset overflow)
As `i + offset` is promoted to a "negative" size_t,
UBSan would complain when adding the resulting offset to `dst`:
```
/tmp/RtmptDX1SS/file584e37df4e/snappy_ep-prefix/src/snappy_ep/snappy.cc:343:43: runtime error: addition of unsigned offset to 0x6120003c5ec1 overflowed to 0x6120003c5ec0
#0 0x7f9ebd21769c in snappy::(anonymous namespace)::Copy64BytesWithPatternExtension(char*, unsigned long) /tmp/RtmptDX1SS/file584e37df4e/snappy_ep-prefix/src/snappy_ep/snappy.cc:343:43
#1 0x7f9ebd21769c in std::__1::pair<unsigned char const*, long> snappy::DecompressBranchless<char*>(unsigned char const*, unsigned char const*, long, char*, long) /tmp/RtmptDX1SS/file584e37df4e/snappy_ep-prefix/src/snappy_ep/snappy.cc:1160:15
```
This commit is contained in:
@@ -340,7 +340,7 @@ static inline bool Copy64BytesWithPatternExtension(char* dst, size_t offset) {
|
|||||||
if (SNAPPY_PREDICT_TRUE(offset < 16)) {
|
if (SNAPPY_PREDICT_TRUE(offset < 16)) {
|
||||||
if (SNAPPY_PREDICT_FALSE(offset == 0)) return false;
|
if (SNAPPY_PREDICT_FALSE(offset == 0)) return false;
|
||||||
// Extend the pattern to the first 16 bytes.
|
// Extend the pattern to the first 16 bytes.
|
||||||
for (int i = 0; i < 16; i++) dst[i] = dst[i - offset];
|
for (int i = 0; i < 16; i++) dst[i] = (dst - offset)[i];
|
||||||
// Find a multiple of pattern >= 16.
|
// Find a multiple of pattern >= 16.
|
||||||
static std::array<uint8_t, 16> pattern_sizes = []() {
|
static std::array<uint8_t, 16> pattern_sizes = []() {
|
||||||
std::array<uint8_t, 16> res;
|
std::array<uint8_t, 16> res;
|
||||||
|
|||||||
Reference in New Issue
Block a user