Skip to content

Commit b1d982f

Browse files
bysiberKriechi
authored andcommitted
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 33b7d06 commit b1d982f

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
@@ -639,6 +639,7 @@ def parse_body(self, data: memoryview) -> None:
639639
msg = "Invalid GOAWAY body."
640640
raise InvalidFrameError(msg) from err
641641

642+
self.last_stream_id = self.last_stream_id & 0x7FFFFFFF
642643
self.body_len = len(data)
643644

644645
if len(data) > 8:
@@ -690,6 +691,8 @@ def parse_body(self, data: memoryview) -> None:
690691
msg = "Invalid WINDOW_UPDATE body"
691692
raise InvalidFrameError(msg) from err
692693

694+
self.window_increment = self.window_increment & 0x7FFFFFFF
695+
693696
if not 1 <= self.window_increment <= 2**31-1:
694697
msg = "WINDOW_UPDATE increment must be between 1 to 2^31-1"
695698
raise InvalidDataError(msg)

0 commit comments

Comments
 (0)