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

QDataStream read transactions do not support QImage

    XMLWordPrintable

Details

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

    Description

      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".

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes