Skip to content

Commit af84643

Browse files
committed
Mask reserved bit when parsing GoAway and WindowUpdate frames
GoAwayFrame.serialize_body already masks last_stream_id with & 0x7FFFFFFF, but parse_body reads the raw 32-bit value without stripping the reserved top bit. If a peer happens to set that bit, last_stream_id would be read as a value >= 2^31 instead of the actual stream ID. Similarly, WindowUpdateFrame.serialize_body masks window_increment with & 0x7FFFFFFF, but parse_body doesn't. If the reserved bit is set, the unmasked value exceeds 2^31-1 and the frame is rejected with InvalidDataError — even though RFC 9113 Section 6.9 says the reserved bit "MUST be ignored when receiving." The rest of the codebase already follows this pattern: - Frame.parse_frame_header masks stream_id & 0x7FFFFFFF - Priority.parse_priority_data masks depends_on & 0x7FFFFFFF Add the same mask to GoAwayFrame.parse_body and WindowUpdateFrame.parse_body for consistency.
1 parent b57beaf commit af84643

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/hyperframe/frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ def parse_body(self, data: memoryview) -> None:
636636
msg = "Invalid GOAWAY body."
637637
raise InvalidFrameError(msg) from err
638638

639+
self.last_stream_id = self.last_stream_id & 0x7FFFFFFF
639640
self.body_len = len(data)
640641

641642
if len(data) > 8:
@@ -687,6 +688,8 @@ def parse_body(self, data: memoryview) -> None:
687688
msg = "Invalid WINDOW_UPDATE body"
688689
raise InvalidFrameError(msg) from err
689690

691+
self.window_increment = self.window_increment & 0x7FFFFFFF
692+
690693
if not 1 <= self.window_increment <= 2**31-1:
691694
msg = "WINDOW_UPDATE increment must be between 1 to 2^31-1"
692695
raise InvalidDataError(msg)

0 commit comments

Comments
 (0)