diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-12-12 10:46:32 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-12-12 16:08:10 +0000 |
commit | d1cafa3ebac00f60cab3ca2beed6ebf2e6579a94 (patch) | |
tree | ab324285e68defa3c1641337ca21dd741e01e890 /tests | |
parent | ceebad9bd2c5ca35c09a17b0adc5e8ee140bdad2 (diff) |
qt_imageFromWinHBITMAP(): Fix memory corruption when converting from bitmaps with low depths
Insufficient memory was allocated when asking GetDIBits() to convert to 32bit.
Fix allocation size and use a QScopedArrayPointer.
Fixes: QTBUG-72343
Change-Id: I45f79c913a243316e01bc6efed08e50ccc7d25f4
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 5ffd75f931..eded206d37 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -233,6 +233,7 @@ private slots: #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void toWinHBITMAP_data(); void toWinHBITMAP(); + void fromMonoHBITMAP(); #endif // Q_OS_WIN && !Q_OS_WINRT private: @@ -3635,6 +3636,19 @@ void tst_QImage::toWinHBITMAP() DeleteDC(bitmapDc); ReleaseDC(0, displayDc); } + +void tst_QImage::fromMonoHBITMAP() // QTBUG-72343, corruption for mono bitmaps +{ + enum : int { width = 32, height = 32, size = width * height / 8 }; // 32x32 mono bitmap + char bitmapData[size]; + memset(bitmapData, 0, size); + const HBITMAP hbitmap = CreateBitmap(width, height, /* planes */ 1, /* bitcount */ 1, bitmapData); + const QImage image = qt_imageFromWinHBITMAP(hbitmap); + QCOMPARE(image.size(), QSize(width, height)); + QCOMPARE(image.scanLine(0)[0], 0u); + DeleteObject(hbitmap); +} + #endif // Q_OS_WIN && !Q_OS_WINRT QTEST_GUILESS_MAIN(tst_QImage) |