From 91b21e155cea14449757abdb51c619957975bbe1 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 14 May 2018 14:15:04 +0200 Subject: SVG image handler: catch and warn about QImage allocation failure QImage allocation failure, typically because of out-of-range dimensions, was not immediately caught and reported. This could lead confusing error messages as QPainter would render on a null image. Task-number: QTBUG-68229 Change-Id: If99033244728f1cea635691c6a93564976962f09 Reviewed-by: Andy Shaw Reviewed-by: Shawn Rutledge --- src/plugins/imageformats/svg/qsvgiohandler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp index 457c79e..a999d47 100644 --- a/src/plugins/imageformats/svg/qsvgiohandler.cpp +++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp @@ -176,8 +176,13 @@ bool QSvgIOHandler::read(QImage *image) t.translate(tr1.x(), tr1.y()); bounds = t.mapRect(bounds); } - if (image->size() != finalSize || !image->reinterpretAsFormat(QImage::Format_ARGB32_Premultiplied)) + if (image->size() != finalSize || !image->reinterpretAsFormat(QImage::Format_ARGB32_Premultiplied)) { *image = QImage(finalSize, QImage::Format_ARGB32_Premultiplied); + if (!finalSize.isEmpty() && image->isNull()) { + qWarning("QSvgIOHandler: QImage allocation failed (size %i x %i)", finalSize.width(), finalSize.height()); + return false; + } + } if (!finalSize.isEmpty()) { image->fill(d->backColor.rgba()); QPainter p(image); -- cgit v1.2.1