]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: qpack: fix 62-bit overflow and 1-byte OOB reads in decoding
authorFrederic Lecaille <flecaille@haproxy.com>
Fri, 20 Mar 2026 18:30:35 +0000 (19:30 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Fri, 20 Mar 2026 18:40:11 +0000 (19:40 +0100)
commit8f6cb8f45235d166ee35cc6df8750f4be759481e
tree604c42630f93da9b631654c6fddf54d0e378cb6e
parent60c9e2975bd77f26fee07e5f15fe24f2b99b60ed
BUG/MINOR: qpack: fix 62-bit overflow and 1-byte OOB reads in decoding

This patch improves the robustness of the QPACK varint decoder and fixes
potential 1-byte out-of-bounds reads in qpack_decode_fs().

In qpack_decode_fs(), two 1-byte OOB reads were possible on truncated
streams between two varint decoding. These occurred when trying to read
the byte containing the Huffman bit <h> and the Value Length prefix
immediately following an Index or a Name Length.

Note that these OOB are limited to a single byte because
qpack_get_varint() already ensures that its input length is non-zero
before consuming any data.

The fixes in qpack_decode_fs() are:
- When decoding an index, we now verify that at least one byte remains
  to safely access the following <h> bit and value length.
- When decoding a literal, we now check len < name_len + 1 to ensure
  the byte starting the header value is reachable.

In qpack_get_varint(), the maximum value is now strictly capped at 2^62-1
as per RFC. This is enforced using a budget-based check:

   (v & 127) > (limit - ret) >> shift

This prevents values from  overflowing into the 63rd or 64th bits, which
would otherwise break subsequent signed comparisons (e.g., if (len < name_len))
by interpreting the length as a negative value, leading to false positive
tests.

Thank you to @jming912 for having reported this issue in GH #3302.

Must be backported as far as 2.6
src/qpack-dec.c