]> git.kaiwu.me - haproxy.git/commit
IMPORT: slz: avoid undefined shifts when building the word byte by byte
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 11 Aug 2026 16:11:44 +0000 (18:11 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 12 Aug 2026 07:14:07 +0000 (09:14 +0200)
commit52255282e0f26001f6e4befe39973e2f0f680e44
treebd745275ea147f4ea8c765929b032d662729b552
parent1fd60f11581222fc0be13b9d9e38f41c9062ca3d
IMPORT: slz: avoid undefined shifts when building the word byte by byte

On the architectures that do not define UNALIGNED_FASTER, the 32-bit word
compared against the reference table is assembled one byte at a time:

    word = ((unsigned char)in[pos] << 8) +
           ((unsigned char)in[pos + 1] << 16) +
           ((unsigned char)in[pos + 2] << 24);

Unexpectedly, an unsigned char is promoted to a *signed* int when
shifting, so shifting a value >= 128 by 24 places can overflow it, which
is undefined behaviour depending on build options. It happens to produce
the expected result with the usual compilers, but ubsan on an i386 build
reports it for about half of input bytes:

  src/slz.c:482:107: runtime error: left shift of 220 by 24 places cannot
                     be represented in type 'int'

Let's just properly cast the uchars to u32 before shifting (this does
not change the produced code at all).

This is libslz upstream commit fbbb46aa54a4d330c6037f72693e0f79c7853354
src/slz.c