Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.

(cherry-picked from dbac3b4)
  • Loading branch information
nyalldawson committed Jun 29, 2018
1 parent 703a6be commit eed42b1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/utils.py
Expand Up @@ -659,9 +659,18 @@ 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:
msg = 'PyQt4 classes cannot be imported in QGIS 3.x.\n' \
'Use {} or the version independent {} import instead.'.format(name.replace('PyQt4', 'PyQt5'), name.replace('PyQt4', 'qgis.PyQt'))
raise ImportError(msg)

mod = _builtin_import(name, globals, locals, fromlist, level)

if mod and '__file__' in mod.__dict__:
Expand Down

0 comments on commit eed42b1

Please sign in to comment.