mirror of https://github.com/status-im/qzxing.git
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:
parent
2083f7a805
commit
557a52b17d
|
@ -126,6 +126,11 @@ QVideoFrame QZXingFilterRunnable::run(QVideoFrame * input, const QVideoSurfaceFo
|
||||||
return * input;
|
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,
|
static QImage rgbDataToGrayscale(const uchar* data, const int width, const int height,
|
||||||
const int alpha, const int red,
|
const int alpha, const int red,
|
||||||
const int green, const int blue,
|
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 stride = (alpha < 0) ? 3 : 4;
|
||||||
|
|
||||||
const int startX = captureRect.x();
|
const int startX = isRectValid(captureRect) ? captureRect.x() : 0;
|
||||||
const int startY = captureRect.y();
|
const int startY = isRectValid(captureRect) ? captureRect.y() : 0;
|
||||||
const int targetWidth = captureRect.isNull() ? width : captureRect.width();
|
const int targetWidth = isRectValid(captureRect) ? captureRect.width() : width;
|
||||||
const int targetHeight = captureRect.isNull() ? height : captureRect.height();
|
const int targetHeight = isRectValid(captureRect) ? captureRect.height() : height;
|
||||||
const int endX = width - startX - targetWidth;
|
const int endX = width - startX - targetWidth;
|
||||||
const int skipX = (endX + startX) * stride;
|
const int skipX = (endX + startX) * stride;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue