diff options
author | Chris Forbes <chrisf@ijw.co.nz> | 2014-11-21 18:45:05 +1300 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-11-21 09:50:39 +0000 |
commit | 0870da2b5a71b6f48be8222e3f056498fea66e10 (patch) | |
tree | 341baf31a91f86521015e023ccc1e0a17610b3b2 /gui | |
parent | 6ce96da28ea23c3d6804d13dc00d886cdb797134 (diff) |
qapitrace: Don't crash when dragging outside image in viewer
When the mouse is down, movement events continue to be delivered
to the PixelWidget even when outside the widget.
In these cases, we reference memory outside the image buffer. This
usually worked out OK, as the nearby addresses were usually mapped.
However, the x value gets converted to unsigned before being added, so
very small negative x values end up offsetting the pixel pointer by many
gigabytes, which is almost certainly not accessible, and explodes.
Instead, if the position is outside the image, safely return a fixed
(out of bounds) message.
Fixes #269.
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Diffstat (limited to 'gui')
-rw-r--r-- | gui/imageviewer.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/gui/imageviewer.cpp b/gui/imageviewer.cpp index 4c3f2bdc..4f47bc02 100644 --- a/gui/imageviewer.cpp +++ b/gui/imageviewer.cpp @@ -126,6 +126,10 @@ QString createPixelLabel(image::Image *img, int x, int y) unsigned char *pixelLocation = 0; T *pixel; + if (x < 0 || y < 0 || x >= img->width || y >= img->height) { + return QString::fromLatin1("(Out of bounds)"); + } + pixelLocation = img->pixels + img->stride() * y; pixelLocation += x * img->bytesPerPixel; pixel = ((T*)pixelLocation); |