diff --git a/tools/chatgui/src/avatars/avatarcrop.cpp b/tools/chatgui/src/avatars/avatarcrop.cpp index 74cb8fb2..d9ef46cd 100644 --- a/tools/chatgui/src/avatars/avatarcrop.cpp +++ b/tools/chatgui/src/avatars/avatarcrop.cpp @@ -106,18 +106,22 @@ bool selectAvatarCrop(const QString& source, QRectF& crop, QWidget* parent) { pool.start(QRunnable::create([source, &completion, dialog, view, status, buttons] { QImageReader reader(source); reader.setAutoTransform(true); const QSize size = reader.size(); QImage image; QString error; + const qint64 sourceBytes = QFileInfo(source).size(); const QByteArray format = reader.format(); QSize orientedSize=size; if (reader.transformation() & QImageIOHandler::TransformationRotate90) orientedSize.transpose(); - if (QFileInfo(source).size() > 0 && QFileInfo(source).size() <= AvatarCache::OriginalMaxBytes && size.width() > 0 && size.height() > 0 && - qint64(size.width())*size.height() <= 16*1024*1024 && - (reader.format()=="jpeg" || reader.format()=="png" || reader.format()=="webp")) { + if (sourceBytes < 1 || sourceBytes > AvatarCache::OriginalMaxBytes) error = QStringLiteral("source must contain 1..33554432 bytes"); + else if (size.width() < 1 || size.height() < 1) error = reader.errorString(); + else if (qint64(size.width())*size.height() > 16*1024*1024) error = QStringLiteral("source exceeds 16 megapixels"); + else if (format != "jpeg" && format != "png" && format != "webp") error = QStringLiteral("unsupported image format"); + else { if (qMax(size.width(), size.height()) > 1600) { const QSize preview = size.scaled(1600, 1600, Qt::KeepAspectRatio); reader.setScaledSize({qMax(1, preview.width()), qMax(1, preview.height())}); } image = reader.read(); if (image.isNull()) error = reader.errorString(); - } else error = QStringLiteral("source is unreadable, exceeds 32 MiB/16 MP, or has an unsupported format"); - if (image.isNull()) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "avatar: editor decode failed source=%s reason=%s", qPrintable(source), qPrintable(error)); + } + if (image.isNull()) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "avatar: editor decode failed source=%s bytes=%lld original=%dx%d format=%s reason=%s", + qPrintable(source), (long long)sourceBytes, size.width(), size.height(), format.constData(), qPrintable(error)); if (!QMetaObject::invokeMethod(&completion, [dialog, view, image, orientedSize, status, buttons] { if (!dialog) return; if (image.isNull()) {