Don't crash on corrupt animated images

This commit is contained in:
Nicolas Werner 2022-05-04 08:26:03 +02:00
parent d839204640
commit e4f8d32a72
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 19 additions and 14 deletions

View File

@ -70,22 +70,27 @@ MxcAnimatedImage::startDownload()
if (!self) if (!self)
return; return;
if (buffer.isOpen()) { try {
movie.stop(); if (buffer.isOpen()) {
movie.setDevice(nullptr); movie.stop();
buffer.close(); movie.setDevice(nullptr);
} buffer.close();
}
if (encryptionInfo) { if (encryptionInfo) {
QByteArray ba = device.readAll(); QByteArray ba = device.readAll();
std::string temp(ba.constData(), ba.size()); std::string temp(ba.constData(), ba.size());
temp = mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value())); temp =
buffer.setData(temp.data(), temp.size()); mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
} else { buffer.setData(temp.data(), temp.size());
buffer.setData(device.readAll()); } 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());
} }
buffer.open(QIODevice::ReadOnly);
buffer.reset();
QTimer::singleShot(0, this, [this, mimeType] { QTimer::singleShot(0, this, [this, mimeType] {
nhlog::ui()->info( nhlog::ui()->info(