diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-10-05 15:45:55 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-10-12 18:02:30 +0000 |
commit | f3ce959de6c682bdb7e71f7b82742f28a5be1e9c (patch) | |
tree | cad2496f8a0eb2786213441b635ff6bdf98fafa2 | |
parent | e732e432ab3b6741917cafa93117b8a9a04d6387 (diff) |
Fix illegal memory access on simple image rotates
Clip the transformed and rounded sourceClip to the source rectangle,
so we don't try to rotate pixels outside the source.
Task-number: QTBUG-56252
Change-Id: Ib9cb80f9856724118867aea37ead0b02a6c71495
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index f87b052df2..83370be33f 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -2273,6 +2273,8 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe = QRectF(sr.x() + clippedTargetRect.x() - r.x(), sr.y() + clippedTargetRect.y() - r.y(), clippedTargetRect.width(), clippedTargetRect.height()).toRect(); + clippedSourceRect = clippedSourceRect.intersected(img.rect()); + uint dbpl = d->rasterBuffer->bytesPerLine(); uint sbpl = img.bytesPerLine(); diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8c72532122..2c0012497d 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -307,6 +307,8 @@ private slots: void QTBUG50153_drawImage_assert(); + void QTBUG56252(); + private: void fillData(); void setPenColor(QPainter& p); @@ -5078,6 +5080,23 @@ void tst_QPainter::QTBUG50153_drawImage_assert() } } +void tst_QPainter::QTBUG56252() +{ + QImage sourceImage(1770, 1477, QImage::Format_RGB32); + QImage rotatedImage(1478, 1771, QImage::Format_RGB32); + QTransform transformCenter; + transformCenter.translate(739.0, 885.5); + transformCenter.rotate(270.0); + transformCenter.translate(-885.0, -738.5); + QPainter painter; + painter.begin(&rotatedImage); + painter.setTransform(transformCenter); + painter.drawImage(QPoint(0, 0),sourceImage); + painter.end(); + + // If no crash or illegal memory read, all is fine +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" |