From fcec63eebc7d0364c23ba90af41e8d760641c810 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 8 Aug 2021 16:12:37 +0200 Subject: [PATCH] fix tnetstread crash found via fuzzing --- mitmproxy/io/io.py | 2 +- test/mitmproxy/io/test_io.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mitmproxy/io/io.py b/mitmproxy/io/io.py index cfa3fe965..1ac6a8ad3 100644 --- a/mitmproxy/io/io.py +++ b/mitmproxy/io/io.py @@ -46,7 +46,7 @@ class FlowReader: if mdata["type"] not in FLOW_TYPES: raise exceptions.FlowReadException("Unknown flow type: {}".format(mdata["type"])) yield FLOW_TYPES[mdata["type"]].from_state(mdata) - except (ValueError, TypeError) as e: + except (ValueError, TypeError, IndexError) as e: if str(e) == "not a tnetstring: empty file": return # Error is due to EOF raise exceptions.FlowReadException("Invalid data format.") diff --git a/test/mitmproxy/io/test_io.py b/test/mitmproxy/io/test_io.py index ea67cbbe0..8d37dc8f7 100644 --- a/test/mitmproxy/io/test_io.py +++ b/test/mitmproxy/io/test_io.py @@ -11,6 +11,7 @@ from mitmproxy.io import FlowReader, tnetstring class TestFlowReader: @given(binary()) @example(b'51:11:12345678901#4:this,8:true!0:~,4:true!0:]4:\\x00,~}') + @example(b'0:') def test_fuzz(self, data): f = io.BytesIO(data) reader = FlowReader(f)