]> git.kaiwu.me - haproxy.git/commit
IMPORT: slz: do not read past the end of the input around the match loop
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 11 Aug 2026 15:48:50 +0000 (17:48 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 12 Aug 2026 07:14:07 +0000 (09:14 +0200)
commitd8a934f903650e9a4f55eac5c6996d5c94025a64
tree645dc080f2bb0b535d308e8b172a95982df4cb9d
parent44699731d206ba2d39f1ffd950cbc67ddf925dfe
IMPORT: slz: do not read past the end of the input around the match loop

slz_rfc1951_encode() pre-loads the first 3 bytes of the input into <word>
before entering the main loop on architectures which do not define
UNALIGNED_FASTER (e.g. i386, or big endian ones). This was done
unconditionally, thus inputs shorter than 3 bytes (including empty ones)
caused up to 3 bytes to be read past the end of the input buffer, which
may segfault if the buffer ends on the last page of a mapping. This is
easily reproduced on i386 by placing a zero-length input right before an
unmapped page.

The pre-loaded word is only ever used if the main loop is entered, which
requires at least 4 remaining bytes, so let's simply condition the load
on this.

The exact same case exists at the end of the loop where we can go beyond
end-3 and try to read 3 or 4 bytes before getting back to the beggining
of the loop, so we're using the same condition here, which helps the
compiler perform the test only once and use unconditional branches from
there.

The code is unchanged on x86_64 and armv8 (out of ifdef) and no
measurable change is observed on other archs.

This is libslz upstream commit 4ff4b66c804629089c0bb16f141a6320f92eba10
src/slz.c