From d429058e56536fc714a7370d41b6035a71b0c6d3 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 6 Mar 2018 20:44:26 +0000 Subject: dmarcpipe.py: Fix potential for RecursionError in octet_stream If an attachment of mime type 'application/octet-stream' is recognised as 'application/octet-stream' then the program would enter into an infinite loop and throw a RecursionError which likely wouldn't be too bad but it's probably clearer to give a KeyError and mark the report as invalid instead. --- dmarcpipe.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dmarcpipe.py b/dmarcpipe.py index bbcc914..0178a1e 100755 --- a/dmarcpipe.py +++ b/dmarcpipe.py @@ -47,7 +47,12 @@ def zip2xml(data): return z.open(n[0]).read() gzip2xml = lambda data: gz_decompress(data) -octet_stream = lambda data: decode(data, magic(data).mime_type) + +def octet_stream(data): + mime = magic(data).mime_type + if mime == 'application/octet-stream': + raise KeyError + return decode(data, mime) decoders = { 'application/gzip': gzip2xml, -- cgit v1.2.3-54-g00ecf