From 4be48a5a27315559b0d2ffa66765c9172ace2c14 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 1 Feb 2016 12:33:00 +0000 Subject: [PATCH 1/2] Don't let ALT_SVC fail without InvalidFrameError --- hyperframe/frame.py | 2 +- test/test_frames.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hyperframe/frame.py b/hyperframe/frame.py index 1c54d18..52225aa 100644 --- a/hyperframe/frame.py +++ b/hyperframe/frame.py @@ -721,7 +721,7 @@ def parse_body(self, data): self.host = data[pos:pos+host_length].tobytes() pos += host_length self.parse_origin(data[pos:]) - except struct.error: + except (struct.error, ValueError): raise InvalidFrameError("Invalid ALTSVC frame body.") diff --git a/test/test_frames.py b/test/test_frames.py index f031675..8c41b1c 100644 --- a/test/test_frames.py +++ b/test/test_frames.py @@ -625,6 +625,11 @@ class TestAltSvcFrame(object): b'\x00\x00\x00\x1D\x00\x50\x00\x02' b'h2\x0Agoogle.com' ) + payload_with_bad_origin = ( + b'\x00\x00\x2B\x0A\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x1D\x00\x50\x00\x02' + b'h2\x0Agoogle.comyahoo.com:8080' + ) def test_altsvc_frame_flags(self): f = AltSvcFrame() @@ -689,6 +694,10 @@ def test_short_altsvc_frame_errors(self): with pytest.raises(InvalidFrameError): decode_frame(self.payload_without_origin[:12]) + def test_altsvc_with_bad_origin_fails(self): + with pytest.raises(InvalidFrameError): + decode_frame(self.payload_with_bad_origin) + class TestBlockedFrame(object): def test_blocked_has_no_flags(self): From 8c643d9b7a1237f5070537347671f637df7b86d4 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 1 Feb 2016 12:34:14 +0000 Subject: [PATCH 2/2] Changelog for #34. --- HISTORY.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 7695a20..15c78a8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,12 @@ dev - Invalid RST_STREAM frame bodies now raise ``InvalidFramError``, not ``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass. +**Bugfixes** + +- The change in ``3.1.0`` that ensured that ``InvalidFrameError`` would be + thrown did not affect certain invalid values in ALT_SVC frames. This has been + fixed: ``ValueError`` will no longer be thrown from invalid ALT_SVC bodies. + 3.1.1 (2016-01-18) ------------------