From 46468647fbd6e0eb9f3fe1f8b867fbfcc2ddf969 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 5 Oct 2018 07:18:23 -0700 Subject: [PATCH] Backport PR #12408: Don't crash on invalid registry font entries on Windows. --- lib/matplotlib/font_manager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index bd21538f4f03..37a0c7fc1e3d 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -199,7 +199,12 @@ def win32InstalledFonts(directory=None, fontext='ttf'): # Work around for https://bugs.python.org/issue25778, which # is fixed in Py>=3.6.1. direc = direc.split("\0", 1)[0] - path = Path(directory, direc).resolve() + try: + path = Path(directory, direc).resolve() + except (FileNotFoundError, RuntimeError): + # Don't fail with invalid entries (FileNotFoundError is + # only necessary on Py3.5). + continue if path.suffix.lower() in fontext: items.add(str(path)) except (OSError, MemoryError):