summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image/qimage/tst_qimage.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-03-04 13:50:18 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-03-31 08:54:03 +0000
commita4e2f2e687ca7aec88ecf82f72d42ac61e17a5b9 (patch)
treef71706ec07e38ddbc47f996dfed199c4235bdb25 /tests/auto/gui/image/qimage/tst_qimage.cpp
parentf5b5e1f76dc1d317ac235007eb81d0cc01fa66d1 (diff)
Fix possible crash in QImage::pixel()
QImage::pixel() assumed that the color table was valid for the values in the bitmap. This was always wrong for indexed images with explicit no color table set and was wrong for mono images that were constructed from preexisting data. For mono images, we default to a black/white color table, like we do when constructing with uninitialized data. For indexed image, we always default to no color table, but instead of crashing in pixel(), we warn and return an undefined value. [ChangeLog][QtGui][Image] Fixed possible crash in QImage::pixel() for mono or indexed images. Change-Id: Ieaf19c03984badddfd06e1855a7e287b862adc70 Task-number: QTBUG-50745 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 23ddfbdd58..e8e1cd1896 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -197,6 +197,7 @@ private slots:
void metadataPassthrough();
void pixelColor();
+ void pixel();
private:
const QString m_prefix;
@@ -3038,5 +3039,33 @@ void tst_QImage::pixelColor()
QCOMPARE(t.pixel(0,0), argb32pm.pixel(0,0));
}
+void tst_QImage::pixel()
+{
+ {
+ QImage mono(1, 1, QImage::Format_Mono);
+ QImage monolsb(1, 1, QImage::Format_MonoLSB);
+ QImage indexed(1, 1, QImage::Format_Indexed8);
+
+ mono.fill(0);
+ monolsb.fill(0);
+ indexed.fill(0);
+
+ QCOMPARE(QColor(mono.pixel(0, 0)), QColor(Qt::black));
+ QCOMPARE(QColor(monolsb.pixel(0, 0)), QColor(Qt::black));
+ indexed.pixel(0, 0); // Don't crash
+ }
+
+ {
+ uchar a = 0;
+ QImage mono(&a, 1, 1, QImage::Format_Mono);
+ QImage monolsb(&a, 1, 1, QImage::Format_MonoLSB);
+ QImage indexed(&a, 1, 1, QImage::Format_Indexed8);
+
+ QCOMPARE(QColor(mono.pixel(0, 0)), QColor(Qt::black));
+ QCOMPARE(QColor(monolsb.pixel(0, 0)), QColor(Qt::black));
+ indexed.pixel(0, 0); // Don't crash
+ }
+}
+
QTEST_GUILESS_MAIN(tst_QImage)
#include "tst_qimage.moc"