Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-209

QImage.bits returns buffer which does not retain QImage (potential segfault)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 1.1.2
    • PySide
    • None

    Description

      QImage.bits() returns a buffer object (yay!) which I would like to use for qimage2ndarray. However, the lifetime of the QImage is not bound to the buffer, i.e. the buffer does not hold a reference to it.

      That means that it is easy to produce a crash, e.g. like this:

      In [1]: filename = ...

      In [2]: from PySide import QtGui

      In [3]: image = QtGui.QImage(filename)

      In [4]: isinstance(image.bits(), buffer)
      Out[4]: True

      In [5]: import numpy

      In [6]: a = numpy.ndarray((image.height(), image.width()), numpy.uint32, image.bits(), 0, (image.bytesPerLine(), image.depth() / 8), 'C')

      In [7]: numpy.all(a[:] > 0)
      Out[7]: True

      In [8]: del image

      In [9]: a[:]
      zsh: segmentation fault (core dumped) python =ipython

      (I am attaching the input lines as .py file, too.)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            hans_meine Hans Meine
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes