Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
None
-
5.9.6, 5.11.2
-
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".