[PyQt] Easy Segfault using (or misusing) QTextStream

Phil Thompson phil at riverbankcomputing.com
Sun Aug 11 21:57:25 BST 2013


On Sun, 11 Aug 2013 12:50:33 -0700, David Cortesi <davecortesi at gmail.com>
wrote:
> I was experimenting to see if I could make an in-memory QTextStream and
> discovered instead an easy way to make Python 2.7.3 segfault:
> 
> [08:23] python
> Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from PyQt4.QtCore import (Qt, QString, QTextStream)
>>>> ts = QTextStream(QString())
>>>> ts << u'x'
> Segmentation fault

You need to keep a reference to the QString.

> The above is on OSX 10.6, but exactly the same result happens in Ubuntu
12.
> 
> It's probably mis-use of the QTextStream (*can* one build a text stream
in
> memory, rewind it and read it back?) but cratering the interpreter seems
a
> bit harsh...

PyQt can't do anything about segfaults in Qt.

Phil


More information about the PyQt mailing list