Skip to content

Commit 5d85051

Browse files
Kriechipgjones
authored andcommitted
PUSH_PROMISE: fix body parsing with padding
1 parent a1df8a8 commit 5d85051

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Release History
88

99
- Deprecate ``total_padding`` - use `pad_length` instead.
1010

11+
**Bugfixes**
12+
13+
- Fixed padding parsing for ``PushPromiseFrame``.
14+
1115
**Other Changes**
1216

1317
- Drop support for Python 2.7, 3.4, 3.5, pypy and support 3.8.

hyperframe/frame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ def parse_body(self, data):
474474
except struct.error:
475475
raise InvalidFrameError("Invalid PUSH_PROMISE body")
476476

477-
self.data = data[padding_data_length + 4:].tobytes()
477+
self.data = (
478+
data[padding_data_length + 4:len(data)-self.pad_length].tobytes()
479+
)
478480
self.body_len = len(data)
479481

480482
if self.pad_length and self.pad_length >= self.body_len:

test/test_frames.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,21 @@ def test_push_promise_frame_parses_properly(self):
406406
assert f.data == b'hello world'
407407
assert f.body_len == 15
408408

409+
def test_push_promise_frame_with_padding(self):
410+
s = (
411+
b'\x00\x00\x17\x05\x0C\x00\x00\x00\x01' +
412+
b'\x07\x00\x00\x00\x04' +
413+
b'hello world' +
414+
b'padding'
415+
)
416+
f = decode_frame(s)
417+
418+
assert isinstance(f, PushPromiseFrame)
419+
assert f.flags == set(['END_HEADERS', 'PADDED'])
420+
assert f.promised_stream_id == 4
421+
assert f.data == b'hello world'
422+
assert f.body_len == 23
423+
409424
def test_push_promise_frame_with_invalid_padding_fails_to_parse(self):
410425
# This frame has a padding length of 6 bytes, but a total length of
411426
# only 5.

0 commit comments

Comments
 (0)