]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: intops: reject varints that do not fit in 64 bits in decode_varint()
authorWilly Tarreau <w@1wt.eu>
Thu, 19 Nov 2026 14:57:15 +0000 (15:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Nov 2026 11:36:58 +0000 (12:36 +0100)
commit20bb44a841f88cb9fdd802abfe6cc79decfadc3d
treef925acc28ab679a700e9747daf09e6d3a530cda0
parentf4afc32785409b2e68a7e9aed6cc62b4c53d45ee
BUG/MINOR: intops: reject varints that do not fit in 64 bits in decode_varint()

decode_varint() accepts any number of continuation bytes. From the 11th
byte on, the shift count exceeds 63, which is undefined behaviour (UBSan:
"shift exponent 67 is too large for 64-bit type"), and a 10-byte varint
whose last byte is above 15 silently wraps: a value >= 2^64 is decoded
modulo 2^64. For example an SPOP agent sending the AGENT-HELLO
max-frame-size as f0 ff ff ff ff ff ff ff ff 7f has it decoded as
2314921131297212640 instead of being rejected.

In order to avoid adding costly checks in the inner loop, let's only
process the first 9 bytes as usual in the current loop and make a
special case of the 10th byte where we add an overflow check if ever
met.

This should be backported to all stable versions.

Reported-by: Martin Mirchev <mirchevmartin2203@gmail.com>
Co-authored-by: Martin Mirchev <mirchevmartin2203@gmail.com>
include/haproxy/intops.h