Skip to content

Commit 1e14ced

Browse files
Kriechipgjones
authored andcommitted
PRIORITY: fix body length validation
1 parent 5d85051 commit 1e14ced

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release History
1111
**Bugfixes**
1212

1313
- Fixed padding parsing for ``PushPromiseFrame``.
14+
- Fixed unchecked frame length for ``PriorityFrame``. It now correctly raises ``InvalidFrameError``.
1415

1516
**Other Changes**
1617

hyperframe/frame.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,14 @@ def serialize_body(self):
323323
return self.serialize_priority_data()
324324

325325
def parse_body(self, data):
326+
if len(data) > 5:
327+
raise InvalidFrameError(
328+
"PRIORITY must have 5 byte body: actual length %s." %
329+
len(data)
330+
)
331+
326332
self.parse_priority_data(data)
327-
self.body_len = len(data)
333+
self.body_len = 5
328334

329335

330336
class RstStreamFrame(Frame):

test/test_frames.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ def test_priority_frame_with_all_data_parses_properly(self):
262262
assert f.exclusive is True
263263
assert f.body_len == 5
264264

265+
def test_priority_frame_invalid(self):
266+
with pytest.raises(ValueError):
267+
decode_frame(
268+
b'\x00\x00\x06\x02\x00\x00\x00\x00\x01\x80\x00\x00\x04\x40\xFF'
269+
)
270+
265271
def test_priority_frame_comes_on_a_stream(self):
266272
with pytest.raises(ValueError):
267273
PriorityFrame(0)

0 commit comments

Comments
 (0)