Skip to content

Commit 72ceae7

Browse files
dr-mgrooverdan
authored andcommitted
MDEV-34510: UBSAN: overflow on adding an unsigned offset
crc32_avx512(): Explicitly cast ssize_t(size) to make it clear that we are indeed applying a negative offset to a pointer.
1 parent 3396498 commit 72ceae7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mysys/crc32/crc32c_x86.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ static unsigned crc32_avx512(unsigned crc, const char *buf, size_t size,
264264
c4 = xor3_512(c4, _mm512_clmulepi64_epi128(l1, b384, 0x10),
265265
extract512_128<3>(l1));
266266

267-
__m256i c2 = _mm512_castsi512_si256(_mm512_shuffle_i64x2(c4, c4, 0b01001110));
267+
__m256i c2 =
268+
_mm512_castsi512_si256(_mm512_shuffle_i64x2(c4, c4, 0b01001110));
268269
c2 = xor256(c2, _mm512_castsi512_si256(c4));
269270
crc_out = xor128(_mm256_extracti64x2_epi64(c2, 1),
270271
_mm256_castsi256_si128(c2));
@@ -289,7 +290,8 @@ static unsigned crc32_avx512(unsigned crc, const char *buf, size_t size,
289290
xor3_512(_mm512_clmulepi64_epi128(lo, b384, 1),
290291
_mm512_clmulepi64_epi128(lo, b384, 0x10),
291292
extract512_128<3>(lo));
292-
crc512 = xor512(crc512, _mm512_shuffle_i64x2(crc512, crc512, 0b01001110));
293+
crc512 =
294+
xor512(crc512, _mm512_shuffle_i64x2(crc512, crc512, 0b01001110));
293295
const __m256i crc256 = _mm512_castsi512_si256(crc512);
294296
crc_out = xor128(_mm256_extracti64x2_epi64(crc256, 1),
295297
_mm256_castsi256_si128(crc256));
@@ -318,7 +320,7 @@ static unsigned crc32_avx512(unsigned crc, const char *buf, size_t size,
318320
size += 16;
319321
if (size) {
320322
get_last_two_xmms:
321-
const __m128i crc2 = crc_out, d = load128(buf + (size - 16));
323+
const __m128i crc2 = crc_out, d = load128(buf + ssize_t(size) - 16);
322324
__m128i S = load128(reinterpret_cast<const char*>(shuffle128) + size);
323325
crc_out = _mm_shuffle_epi8(crc_out, S);
324326
S = xor128(S, _mm_set1_epi32(0x80808080));

0 commit comments

Comments
 (0)