summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qblendfunctions_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-03-25 15:55:34 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-03 12:47:43 +0200
commit343df131f7207d65932c6505769aa2fb7fc04713 (patch)
treeeb21e990c881d79f39a5bc85a5366df8190d5f7a /src/gui/painting/qblendfunctions_p.h
parent565f5236c6c72effa914ae0537a1fb2b0de1027c (diff)
Avoid out of bounds memory reads when scaling imagesv4.8.6
The calculation of the width/height required for the scaling algorithm was prone to floating point rounding issues, where the lower value got rounded down, the higher one rounded up. This could lead to a situation where we iterated over one more line/pixel in the line than we have in the source image. Correct this by passing the dimension of the source image into the function and bounds checking the values before iterating. Backport of If44b2235a479224660d508a0504fec40d724763a from Qt 5 Task-number: QTBUG-35927 Change-Id: If145ee715a143b889538243f45227d8d78a0050f Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src/gui/painting/qblendfunctions_p.h')
-rw-r--r--src/gui/painting/qblendfunctions_p.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/gui/painting/qblendfunctions_p.h b/src/gui/painting/qblendfunctions_p.h
index ef5aca08d2..5d20ceaa81 100644
--- a/src/gui/painting/qblendfunctions_p.h
+++ b/src/gui/painting/qblendfunctions_p.h
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
template <typename SRC, typename T>
void qt_scale_image_16bit(uchar *destPixels, int dbpl,
- const uchar *srcPixels, int sbpl,
+ const uchar *srcPixels, int sbpl, int sh,
const QRectF &targetRect,
const QRectF &srcRect,
const QRect &clip,
@@ -136,6 +136,15 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl,
quint16 *dst = ((quint16 *) (destPixels + ty1 * dbpl)) + tx1;
+ // this bounds check here is required as floating point rounding above might in some cases lead to
+ // w/h values that are one pixel too large, falling outside of the valid image area.
+ int yend = (srcy + iy * (h - 1)) >> 16;
+ if (yend < 0 || yend >= sh)
+ --h;
+ int xend = (basex + ix * (w - 1)) >> 16;
+ if (xend < 0 || xend >= (int)(sbpl/sizeof(quint32)))
+ --w;
+
while (h--) {
const SRC *src = (const SRC *) (srcPixels + (srcy >> 16) * sbpl);
int srcx = basex;
@@ -161,7 +170,7 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl,
}
template <typename T> void qt_scale_image_32bit(uchar *destPixels, int dbpl,
- const uchar *srcPixels, int sbpl,
+ const uchar *srcPixels, int sbpl, int sh,
const QRectF &targetRect,
const QRectF &srcRect,
const QRect &clip,
@@ -236,6 +245,15 @@ template <typename T> void qt_scale_image_32bit(uchar *destPixels, int dbpl,
quint32 *dst = ((quint32 *) (destPixels + ty1 * dbpl)) + tx1;
+ // this bounds check here is required as floating point rounding above might in some cases lead to
+ // w/h values that are one pixel too large, falling outside of the valid image area.
+ int yend = (srcy + iy * (h - 1)) >> 16;
+ if (yend < 0 || yend >= sh)
+ --h;
+ int xend = (basex + ix * (w - 1)) >> 16;
+ if (xend < 0 || xend >= (int)(sbpl/sizeof(quint32)))
+ --w;
+
while (h--) {
const uint *src = (const quint32 *) (srcPixels + (srcy >> 16) * sbpl);
int srcx = basex;