Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70875

QDataStream read transactions do not support QImage

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • None
    • 5.9.6, 5.11.2
    • GUI: Painting
    • None

      QDataStream's support for read transactions does not seem to cover QImage, which won't correctly report short reads and make the transaction fail.

      The easiest workaround I seeĀ  is falling back to sending the size first and checking it explicitly, before attempting deserialing the image. However, data serialized in the past is hard or impossible to deserialize correctly.

      Testcase:

      #include <QtGui>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication a(argc, argv);
      
          QImage i(100, 100, QImage::Format_RGB32);
          i.fill(Qt::black);
      
          QByteArray storage;
      
          {
              QDataStream ds(&storage, QIODevice::WriteOnly);
              ds << i;
          }
      
          // simulate a short read
          storage.resize( storage.size() / 3 );
      
          {
              QDataStream ds(&storage, QIODevice::ReadOnly);
              QImage result;
      
              ds.startTransaction();
              ds >> result;
              if (ds.commitTransaction()) {
                  // qFatal("Cannot happen");
                  if (i != result)
                      qFatal("Cannot happen");
              }
          }
      }
      

      Prints "cannot happen".

        For Gerrit Dashboard: QTBUG-70875
        # Subject Branch Project Status CR V

            vgt Eirik Aavitsland
            peppe Giuseppe D'Angelo
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes