summary refs log tree commit diff
path: root/src/ui/MxcAnimatedImage.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-05-04 08:26:03 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-05-04 08:26:24 +0200
commite4f8d32a7276cb0b0de735d35abdaa3227f9c2bc (patch)
treee06e9a7d2c68ad3d2fa72ea5037d764977736d03 /src/ui/MxcAnimatedImage.cpp
parentMerge pull request #1068 from Nheko-Reborn/fullLinter (diff)
downloadnheko-e4f8d32a7276cb0b0de735d35abdaa3227f9c2bc.tar.xz
Don't crash on corrupt animated images
Diffstat (limited to '')
-rw-r--r--src/ui/MxcAnimatedImage.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/ui/MxcAnimatedImage.cpp b/src/ui/MxcAnimatedImage.cpp
index 2f3af137..4af527b4 100644
--- a/src/ui/MxcAnimatedImage.cpp
+++ b/src/ui/MxcAnimatedImage.cpp
@@ -70,23 +70,28 @@ MxcAnimatedImage::startDownload()
         if (!self)
             return;
 
-        if (buffer.isOpen()) {
-            movie.stop();
-            movie.setDevice(nullptr);
-            buffer.close();
+        try {
+            if (buffer.isOpen()) {
+                movie.stop();
+                movie.setDevice(nullptr);
+                buffer.close();
+            }
+
+            if (encryptionInfo) {
+                QByteArray ba = device.readAll();
+                std::string temp(ba.constData(), ba.size());
+                temp =
+                  mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
+                buffer.setData(temp.data(), temp.size());
+            } else {
+                buffer.setData(device.readAll());
+            }
+            buffer.open(QIODevice::ReadOnly);
+            buffer.reset();
+        } catch (const std::exception &e) {
+            nhlog::net()->error("Failed to setup animated image buffer: {}", e.what());
         }
 
-        if (encryptionInfo) {
-            QByteArray ba = device.readAll();
-            std::string temp(ba.constData(), ba.size());
-            temp = mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
-            buffer.setData(temp.data(), temp.size());
-        } else {
-            buffer.setData(device.readAll());
-        }
-        buffer.open(QIODevice::ReadOnly);
-        buffer.reset();
-
         QTimer::singleShot(0, this, [this, mimeType] {
             nhlog::ui()->info(
               "Playing movie with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());