QZXingFilter: Enforce captureRect validation

captureRect is accessible and modifyable via QML, so that
it can take arbitrary values, what can make QZXingFilter to crash
the application.

This issue was experienced when running code similar to QZXingLive
example on an android device, where captureRect is bound based on
VideoOutput's contentRect and sourceRect, when QML Engine is
calculating layout for the pages it sets temp values to width/height
of elements (including VideoOutput) what causes captureRect to be
set to invalid values for the QZXingFilter's perspective, such
as negative values for x and y.

Signed-off-by: Nick Diego Yamane <nick.diego@gmail.com>
This commit is contained in:
Nick Diego Yamane 2017-01-18 19:12:45 -04:00
parent 2083f7a805
commit 557a52b17d
1 changed files with 9 additions and 4 deletions

View File

@ -126,6 +126,11 @@ QVideoFrame QZXingFilterRunnable::run(QVideoFrame * input, const QVideoSurfaceFo
return * input;
}
static bool isRectValid(const QRect& rect)
{
return rect.x() > 0 && rect.y() > 0 && rect.isValid();
}
static QImage rgbDataToGrayscale(const uchar* data, const int width, const int height,
const int alpha, const int red,
const int green, const int blue,
@ -134,10 +139,10 @@ static QImage rgbDataToGrayscale(const uchar* data, const int width, const int h
{
const int stride = (alpha < 0) ? 3 : 4;
const int startX = captureRect.x();
const int startY = captureRect.y();
const int targetWidth = captureRect.isNull() ? width : captureRect.width();
const int targetHeight = captureRect.isNull() ? height : captureRect.height();
const int startX = isRectValid(captureRect) ? captureRect.x() : 0;
const int startY = isRectValid(captureRect) ? captureRect.y() : 0;
const int targetWidth = isRectValid(captureRect) ? captureRect.width() : width;
const int targetHeight = isRectValid(captureRect) ? captureRect.height() : height;
const int endX = width - startX - targetWidth;
const int skipX = (endX + startX) * stride;