Skip to content

Fix setting identifier truncation in SettingsFrame.serialize_body - #167

Merged
Kriechi merged 2 commits into
python-hyper:masterfrom
bysiber:fix-settings-identifier-mask
Apr 10, 2026
Merged

Fix setting identifier truncation in SettingsFrame.serialize_body#167
Kriechi merged 2 commits into
python-hyper:masterfrom
bysiber:fix-settings-identifier-mask

Conversation

@bysiber

@bysiber bysiber commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

SettingsFrame.serialize_body masks the setting identifier with & 0xFF, which truncates it to 8 bits. The identifier field in HTTP/2 SETTINGS frames is 16 bits wide (RFC 9113, Section 6.5.1), and _STRUCT_HL already packs it as an unsigned short (H, 16 bits).

Standard settings (0x01–0x08) fit in a single byte, so this has gone unnoticed. But any setting identifier above 255 — for example GREASE values from RFC 8701 (0x0a0a, 0x1a1a, …) or future extensions — gets silently corrupted:

>>> _STRUCT_HL.pack(0x0a0a & 0xFF, 1)   # current: packs 0x000a
>>> _STRUCT_HL.pack(0x0a0a & 0xFFFF, 1)  # fixed: packs 0x0a0a

parse_body already reads the full 16-bit identifier correctly (_STRUCT_HL.unpack), so this also breaks the serialize→parse round-trip for those values.

This changes the mask from 0xFF to 0xFFFF.

bysiber and others added 2 commits February 20, 2026 18:42
The bitmask `setting & 0xFF` truncates the 16-bit setting identifier
to only 8 bits. This silently corrupts any setting ID above 255 during
serialization.

The identifier field in SETTINGS frames is 16 bits wide (RFC 9113,
Section 6.5.1), and `_STRUCT_HL` already uses the `H` format
(unsigned short, 16 bits) for it. However, `& 0xFF` discards the
upper byte.

For the standard settings (0x01 through 0x08) this has no visible
effect since they all fit in 8 bits. But RFC 8701 GREASE values like
0x0a0a or 0x1a1a, as well as any future extension settings > 0xFF,
would be silently mangled on a serialize round-trip.

Change the mask to `& 0xFFFF` to match the actual field width.
@Kriechi

Kriechi commented Apr 3, 2026

Copy link
Copy Markdown
Member

@bysiber thanks for your contribution! I added some changes to improve the code comments and added new tests to cover the correct masking behaviour. Please review them before I merge this! Thanks!

@Kriechi
Kriechi merged commit 33b7d06 into python-hyper:master Apr 10, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants