From e442eb9e4c016d5ff1bb81e82e94a0d9687d8ba8 Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Fri, 5 May 2023 15:10:00 +0300 Subject: [PATCH] QmlDesigner: Fix crash in FileExtractor when compressed size is 0 Task-number: QDS-9832 Change-Id: Ia096b5770359ea16171cae0634fea340264194e1 Reviewed-by: Tim Jenssen (cherry picked from commit 86e4d171df3f4afc37a180974c1eb1330b0a1629) --- src/plugins/qmldesigner/utils/fileextractor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmldesigner/utils/fileextractor.cpp b/src/plugins/qmldesigner/utils/fileextractor.cpp index c6aa83fb7ae..7c32381b69c 100644 --- a/src/plugins/qmldesigner/utils/fileextractor.cpp +++ b/src/plugins/qmldesigner/utils/fileextractor.cpp @@ -51,7 +51,11 @@ FileExtractor::FileExtractor(QObject *parent) // We can not get the uncompressed size of the archive yet, that is why we use an // approximation. We assume a 50% compression rate. - int progress = std::min(100ll, currentSize * 100 / m_compressedSize * 2); + + int progress = 0; + if (m_compressedSize > 0) + progress = std::min(100ll, currentSize * 100 / m_compressedSize * 2); + if (progress >= 0) { m_progress = progress; emit progressChanged(); @@ -212,6 +216,8 @@ void FileExtractor::extract() m_timer.start(); m_bytesBefore = QStorageInfo(m_targetPath.toFileInfo().dir()).bytesAvailable(); m_compressedSize = QFileInfo(m_sourceFile.toString()).size(); + if (m_compressedSize <= 0) + qWarning() << "Compressed size for file '" << m_sourceFile << "' is zero or invalid: " << m_compressedSize; QObject::connect(archive, &Utils::Archive::outputReceived, this, [this](const QString &output) { m_detailedText += output;