Skip to content
Permalink
Browse files

[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.
  • Loading branch information
nyalldawson committed Jun 28, 2018
1 parent 0c0981a commit dbac3b492232e8b2c2d541a1d154d6f537f6b195
Showing with 8 additions and 1 deletion.
  1. +8 −1 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__:

0 comments on commit dbac3b4

Please sign in to comment.
You can’t perform that action at this time.