From dbac3b492232e8b2c2d541a1d154d6f537f6b195 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 28 Jun 2018 16:01:39 +1000 Subject: [PATCH] [python] Block imports of PyQt4 modules Prevents crashes when PyQt4 modules are imported in QGIS 3.x. This instantly segfaults QGIS. Throwing an exception makes it easier to identify the cause as a faulty plugin, and shows exactly where the bad import is located. --- python/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/utils.py b/python/utils.py index 33371d8580ce..2832fd0df81b 100644 --- a/python/utils.py +++ b/python/utils.py @@ -659,9 +659,16 @@ def __exit__(self, exc_type, exc_val, exc_tb): def _import(name, globals={}, locals={}, fromlist=[], level=None): - """ wrapper around builtin import that keeps track of loaded plugin modules """ + """ + Wrapper around builtin import that keeps track of loaded plugin modules and blocks + certain unsafe imports + """ if level is None: level = 0 + + if 'PyQt4' in name: + raise ImportError('Cannot import PyQt4 classes - this would cause a crash!') + mod = _builtin_import(name, globals, locals, fromlist, level) if mod and '__file__' in mod.__dict__: