Bug Report: Crash when reading application/gzip encoded file

So, I’m trying to intercept a POST request with a content-encoding of application/gzip. Here’s the steps I made:

  1. Setup Android with an SSL certificate and hook it up as a client on port 3223
  2. mitmproxy -p 3223
  3. Send a POST request with an application/gzip encoded body from the client (Android device) to a server
  4. The POST request appears on mitmproxy. If I press enter on it, it crashes. Here’s the crash log:
~/Desktop/test » mitmproxy -p 3223                                                                                                 ab@391232
Traceback (most recent call last):
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 225, in run
    self.loop.run()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 286, in run
    self._run()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 384, in _run
    self.event_loop.run()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 788, in run
    self._loop()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 816, in _loop
    self._entering_idle()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 777, in _entering_idle
    callback()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 572, in entering_idle
    self.draw_screen()
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 586, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/container.py", line 1086, in render
    focus and self.focus_part == 'body')
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/decoration.py", line 226, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/container.py", line 1086, in render
    focus and self.focus_part == 'body')
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/container.py", line 1086, in render
    focus and self.focus_part == 'body')
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 1765, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/container.py", line 1086, in render
    focus and self.focus_part == 'body')
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/listbox.py", line 501, in render
    canvas = widget.render((maxcol,))
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 144, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/widget.py", line 1004, in render
    return apply_text_layout(text, attr, trans, maxcol)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/canvas.py", line 1315, in apply_text_layout
    return TextCanvas(t, a, c, maxcol=maxcol)
  File "/usr/local/Cellar/mitmproxy/3.0.3_2/libexec/lib/python3.6/site-packages/urwid/canvas.py", line 358, in __init__
    raise CanvasError("Canvas text is wider than the maxcol specified \n%r\n%r\n%r"%(maxcol,widths,text))
urwid.canvas.CanvasError: Canvas text is wider than the maxcol specified
146
[146, 147, 146, 94, 146, 140]
[b'an: .?........?Vm??8.?+(??Mj;/.?S?????e+]_.9?.?u??q?r???N??.?3?..?=?g?g????Fh?z?/????EE?\t??Z{s?.???.????xs0.m??;?m?cB?8?)?,??HC??.?..???<$?', b"?9?..gq??L.hD???Y?<.?H?..Q?'??,??t?R@?T^m??G?.b?R??4?/A)KPJ.?b?c<?.??.Fs<??.?0jEY??.?jmM?N^.=Y?5?m..??????CO????`... ??.???V?.;?BD?./f?I??o7???zzlL", b"]H%??h?..?;??X?{.7Tu??w.??F?..8@?.?JA?.?Ga?#???.g#/?B??x????@?>????<N?h?????gd|.T)..?.Yn'???.??A/?4w??.5F?sur????R#V??3?O??.?.,(A?Ae?=???B????N*>?", b"?.??.O??Ar!?=?k??h)?*zG?F>|}E..??/???N?o'?57??$@.??..?.?.}?\\?!??.?{.?q??cT??.f????v=?.??)T?`.?", b'??.?Y???u?.}?>1??y??\t??w?.??..tl?B??.?.8J9?k%?~?*E?u.h??8!?;?.?r]Q{\\I?`9???^qG.<C8qfX???DwJ?B.\\?V??x`..%(?^Y?.??B1??X.Y??Q??.DC?.t?i_??l?EPm?.~q??', b'???n???w?B?[?3u??r5??!r?]?u?DFyfd.?f\\?4W??,J?T{y.?7?$?.0Q?????k?.}.???W?(..:n?..Eu?A]G8?/.?<??bbO1?.?d.?..??u9?W?A??/v?.n??66?f?????.A?8<|..']

mitmproxy has crashed!
Please lodge a bug report at:
        https://github.com/mitmproxy/mitmproxy
Shutting down...

I tried to export the flow but the output had the gzip file and it did not encrypt it.

Mitm proxy output is this

Mitmproxy: 3.0.3
Python:    3.6.5
OpenSSL:   OpenSSL 1.0.2o  27 Mar 2018
Platform:  Darwin-17.4.0-x86_64-i386-64bit

Thanks - this definitely is a bug. Can you please lodge this issue in our GitHub issue tracker? :smiley:

Done!: https://github.com/mitmproxy/mitmproxy/issues/3040