QWebEngineCertificateError::defer() segfaults

Florian Bruhin me at the-compiler.org
Fri Apr 22 10:21:09 BST 2022


Hi,

The attached examples use QWebEngineCertificateError::defer() (added in
Qt 5.14) to accept/reject certificates asynchronously:

https://doc.qt.io/qt-5/qwebenginecertificateerror.html#defer
https://doc.qt.io/qt-6/qwebenginecertificateerror.html#defer

With PySide6, this seems to work properly: The page pauses loading, and
after 1s, it gets shown.

With PyQt6 and PyQt5 (and PySide2), it segfaults.

PyQt5:

    Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
    QWebEngineCertificateError::ignoreCertificateError (this=0x7fffffffb3f0) at /usr/src/debug/qtwebengine/src/webenginewidgets/api/qwebenginecertificateerror.cpp:231
    231	   d->ignoreCertificateError();
    (gdb) bt
    #0  QWebEngineCertificateError::ignoreCertificateError() (this=0x7fffffffb3f0) at /usr/src/debug/qtwebengine/src/webenginewidgets/api/qwebenginecertificateerror.cpp:231
    #1  0x00007ffff726fc63 in meth_QWebEngineCertificateError_ignoreCertificateError(PyObject*, PyObject*) (sipSelf=<optimized out>, sipArgs=<optimized out>)
        at /usr/src/debug/PyQtWebEngine-5.15.5/build/QtWebEngineWidgets/sipQtWebEngineWidgetsQWebEngineCertificateError.cpp:236
    [...]
    #4  0x00007fffdb53ed31 in PyQtSlot::call(_object*, _object*) const (this=0x5555566debe0, args=0x7ffff7490070, callable=0x7fff805b4270) at ../../qpy/QtCore/qpycore_pyqtslot.cpp:247
    [...]
    #11 0x00007ffff62343d4 in QSingleShotTimer::timeout() (this=0x5555560691d0) at .moc/qtimer.moc:130

PyQt6 (strangely I seem to be missing some debugging symbols):

    #0  0x00007fffecca9050 in QtWebEngineCore::CertificateErrorController::answered() const () at /usr/lib/libQt6WebEngineCore.so.6
    #1  0x00007fffecca9075 in QtWebEngineCore::CertificateErrorController::accept(bool) () at /usr/lib/libQt6WebEngineCore.so.6
    [...]
    #4  0x00007ffff7d1d83b in PyObject_Call () at /usr/lib/libpython3.10.so.1.0
    [...]
    #9  0x00007fffeb4dc676 in QObject::event(QEvent*) () at /usr/lib/libQt6Core.so.60

Florian

-- 
            me at the-compiler.org | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
             I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl, QTimer


class Page(QWebEnginePage):

    def certificateError(self, err):
        err.defer()
        QTimer.singleShot(1000, err.ignoreCertificateError)
        return False  # ignored


app = QApplication([])
view = QWebEngineView()
page = Page()
view.setPage(page)
view.load(QUrl("https://expired.badssl.com"))
view.show()
app.exec_()
-------------- next part --------------
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QUrl, QTimer


def _handle_certificate_error(err):
    err.defer()
    QTimer.singleShot(1000, err.acceptCertificate)


app = QApplication([])
view = QWebEngineView()
view.page().certificateError.connect(_handle_certificate_error)
view.load(QUrl("https://expired.badssl.com"))
view.show()
app.exec()
-------------- next part --------------
from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QUrl, QTimer


class Page(QWebEnginePage):

    def certificateError(self, err):
        err.defer()
        QTimer.singleShot(1000, err.ignoreCertificateError)
        return False  # ignored


app = QApplication([])
view = QWebEngineView()
page = Page()
view.setPage(page)
view.load(QUrl("https://expired.badssl.com"))
view.show()
app.exec_()
-------------- next part --------------
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QUrl, QTimer


def _handle_certificate_error(err):
    err.defer()
    QTimer.singleShot(1000, err.acceptCertificate)


app = QApplication([])
view = QWebEngineView()
view.page().certificateError.connect(_handle_certificate_error)
view.load(QUrl("https://expired.badssl.com"))
view.show()
app.exec()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220422/49b7f065/attachment.sig>


More information about the PyQt mailing list