Skip to content

Commit dd71c3b

Browse files
committed
Fix setting identifier truncation in SettingsFrame.serialize_body
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.
1 parent b57beaf commit dd71c3b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/hyperframe/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def _body_repr(self) -> str:
457457
return f"settings={self.settings}"
458458

459459
def serialize_body(self) -> bytes:
460-
return b"".join([_STRUCT_HL.pack(setting & 0xFF, value)
460+
return b"".join([_STRUCT_HL.pack(setting & 0xFFFF, value)
461461
for setting, value in self.settings.items()])
462462

463463
def parse_body(self, data: memoryview) -> None:

0 commit comments

Comments
 (0)