Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 34dfc25

Browse files
committed
Respect EOS when decoding HPACK.
1 parent e355908 commit 34dfc25

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

hyper/http20/huffman.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def decode(self, encoded_string):
6666
for digit in number:
6767
cur_node = cur_node.mapping[digit]
6868
if cur_node.data is not None:
69+
# If we get EOS, everything else is padding.
70+
if cur_node.data > 255:
71+
break
72+
6973
decoded_message.append(cur_node.data)
7074
cur_node = self.root
7175
except KeyError:

hyper/http20/huffman_constants.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@
263263
0x3ffffd8,
264264
0x3ffffd9,
265265
0x3ffffda,
266-
0x3ffffdb
266+
0x3ffffdb,
267+
0x3ffffdc,
267268
]
268269

269270
REQUEST_CODES_LENGTH = [
@@ -282,7 +283,8 @@
282283
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
283284
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
284285
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
285-
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26
286+
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
287+
26,
286288
]
287289

288290
RESPONSE_CODES = [
@@ -541,7 +543,8 @@
541543
0xffffd9,
542544
0xffffda,
543545
0xffffdb,
544-
0xffffdc
546+
0xffffdc,
547+
0xffffdd,
545548
]
546549

547550
RESPONSE_CODES_LENGTH = [
@@ -560,6 +563,6 @@
560563
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
561564
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
562565
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
563-
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
566+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
567+
24,
564568
]
565-

test/test_huffman.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ def test_response_huffman_encode():
3232
assert encoder.encode(b"https://www.example.com") == (b'\xe3\x9e\x78\x64\xdd\x7a\xfd\x3d\x3d\x24\x87\x47\xdb\x87\x28\x49\x55\xf6\xff')
3333
assert encoder.encode(b"foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1") == (b'\xdf\x7d\xfb\x36\xd3\xd9\xe1\xfc\xfc\x3f\xaf\xe7\xab\xfc\xfe\xfc\xbf\xaf\x3e\xdf\x2f\x97\x7f\xd3\x6f\xf7\xfd\x79\xf6\xf9\x77\xfd\x3d\xe1\x6b\xfa\x46\xfe\x10\xd8\x89\x44\x7d\xe1\xce\x18\xe5\x65\xf7\x6c\x2f')
3434

35+
def test_eos_terminates_decode_response():
36+
decoder = HuffmanDecoder(RESPONSE_CODES,RESPONSE_CODES_LENGTH)
37+
assert decoder.decode(b'\xff\xff\xdd\xff\xff\xff') == b''
38+
39+
def test_eos_terminates_decode_request():
40+
decoder = HuffmanDecoder(REQUEST_CODES,REQUEST_CODES_LENGTH)
41+
assert decoder.decode(b'\xff\xff\xf7\x00') == b''

0 commit comments

Comments
 (0)