Skip to content

Commit dbac3b4

Browse files
committed
[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.
1 parent 0c0981a commit dbac3b4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/utils.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,16 @@ def __exit__(self, exc_type, exc_val, exc_tb):
659659

660660

661661
def _import(name, globals={}, locals={}, fromlist=[], level=None):
662-
""" wrapper around builtin import that keeps track of loaded plugin modules """
662+
"""
663+
Wrapper around builtin import that keeps track of loaded plugin modules and blocks
664+
certain unsafe imports
665+
"""
663666
if level is None:
664667
level = 0
668+
669+
if 'PyQt4' in name:
670+
raise ImportError('Cannot import PyQt4 classes - this would cause a crash!')
671+
665672
mod = _builtin_import(name, globals, locals, fromlist, level)
666673

667674
if mod and '__file__' in mod.__dict__:

0 commit comments

Comments
 (0)