Skip to content

Commit

Permalink
[python] Block imports of PyQt4 modules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Jun 29, 2018
1 parent 0c0981a commit dbac3b4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/utils.py
Expand Up @@ -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__:
Expand Down

0 comments on commit dbac3b4

Please sign in to comment.