From c7b0d2967acf2430aabfda4910e77f4cf4827f55 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 17 Jun 2024 23:47:28 +0200 Subject: Fix crash when trying to read an invalid image Helper::picSize assumed that all data passed to it is a valid image and thus crashed with an exception. Wrap it into try - catch and return QVariant() when the pic is invalid. --- helper.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index 32dc11c..9398a06 100644 --- a/helper.cpp +++ b/helper.cpp @@ -304,9 +304,13 @@ namespace Helper { QVariant picSize(const QString &path){ Magick::Image img; - img.ping(qPrintable(path)); - QString retval = QString("%1x%2").arg(QString::number(img.columns()), QString::number(img.rows())); - return retval; + try { + img.ping(qPrintable(path)); + QString retval = QString("%1x%2").arg(QString::number(img.columns()), QString::number(img.rows())); + return retval; + } catch(...) { + return QVariant(); + } } PicData convertArchivefileToPng(PicData data){ -- cgit v1.2.3-70-g09d2