From: Christopher Faulet Date: Wed, 18 Nov 2026 07:55:45 +0000 (+0100) Subject: REGTEST: spoe: fix the SPOP varint encoding in the mock agent X-Git-Url: https://git.kaiwu.me/http/control.html?a=commitdiff_plain;h=dd6e14eabc37e05e7c820b8fd9304a34a3e2dd03;p=haproxy.git REGTEST: spoe: fix the SPOP varint encoding in the mock agent The mock agent implemented a LEB128-style variable-length integer instead of the SPOP one: the continuation shift was off by 16 on encode and the decode masked the continuation bytes where the reference implementation adds their full value. The echoed max-frame-size was thus wrong (14076 instead of 16380 with the default tune.bufsize) and only passed the negotiation because it stayed within the accepted range. With a smaller tune.bufsize the test would fail. Mirror encode_varint()/decode_varint() from include/haproxy/intops.h. Validated against the C implementation for all values below 2000 plus larger boundaries. --- diff --git a/reg-tests/spoe/spoa_mock.py b/reg-tests/spoe/spoa_mock.py index a4020e74d..011dd19a7 100644 --- a/reg-tests/spoe/spoa_mock.py +++ b/reg-tests/spoe/spoa_mock.py @@ -21,26 +21,32 @@ import socket, struct, sys, threading def enc_varint(v): + # SPOP variable-length integer, mirroring encode_varint() in + # include/haproxy/intops.h: values below 240 fit on one byte, otherwise + # the low 4 bits ride on the first byte and each continuation byte + # carries the next 7 bits, most-significant first. if v < 240: return bytes([v]) out = bytearray() out.append(0xF0 | (v & 0x0F)) - v = (v >> 4) - 16 + v = (v - 240) >> 4 while v >= 128: out.append(0x80 | (v & 0x7F)) - v = (v >> 7) - 1 - out.append(v & 0x7F) + v = (v - 128) >> 7 + out.append(v) return bytes(out) def dec_varint(buf, off): - b = buf[off]; off += 1 - if b < 240: - return b, off - val = b & 0x0F + # SPOP variable-length integer, mirroring decode_varint() in + # include/haproxy/intops.h. + v = buf[off]; off += 1 + if v < 240: + return v, off + val = v shift = 4 while True: b = buf[off]; off += 1 - val |= (b & 0x7F) << shift + val += b << shift shift += 7 if b < 128: break