From 856ca7669dd6c6b4bb90d5f634c588585133a991 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 20 May 2020 22:44:04 -0400 Subject: [PATCH 1/2] FIX: add guardrails for too big tk figures on linux Depending on the version of xserver creating a too big tk window either corrupts xorg (!) or causes the process to exit. This adds a guard rail that will convert this into a python exception instead. closes #17460 --- lib/matplotlib/backends/_backend_tk.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 9132a859f90f..fcbae09db8dc 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -431,6 +431,17 @@ def _get_toolbar(self): return toolbar def resize(self, width, height): + max_size = 1_400_000 # the measured max on xorg 1.20.8 was 1_409_023 + + if (width > max_size or height > max_size) and sys.platform == 'linux': + raise ValueError( + 'You have requested to resize the ' + f'Tk window to ({width}, {height}), one of which ' + f'is bigger than {max_size}. At larger sizes xorg will ' + 'either exit with an error on never versions (~1.20) or ' + 'cause corruption on older version (~1.19). We ' + 'do not expect a window over a million pixel wide or tall ' + 'to be intended behavior.') self.canvas._tkcanvas.configure(width=width, height=height) def show(self): From 32b914f02cf55acf1a62669b43de0d1f09c4c127 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 3 Jun 2020 17:23:13 -0400 Subject: [PATCH 2/2] DOC: correct typo Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/backends/_backend_tk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index fcbae09db8dc..bc31d31e699b 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -438,7 +438,7 @@ def resize(self, width, height): 'You have requested to resize the ' f'Tk window to ({width}, {height}), one of which ' f'is bigger than {max_size}. At larger sizes xorg will ' - 'either exit with an error on never versions (~1.20) or ' + 'either exit with an error on newer versions (~1.20) or ' 'cause corruption on older version (~1.19). We ' 'do not expect a window over a million pixel wide or tall ' 'to be intended behavior.')