diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index b306a2a13..9147bbea6 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -405,6 +405,16 @@ void Image::actuallyLoad() QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); QImageReader reader(&buffer); + + if (reader.size().width() * reader.size().height() * + reader.imageCount() * 4 > + Image::maxBytesRam) + { + qCDebug(chatterinoImage) << "image too large in RAM"; + + return Failure; + } + auto parsed = detail::readFrames(reader, shared->url()); postToThread(makeConvertCallback(parsed, [weak](auto frames) { diff --git a/src/messages/Image.hpp b/src/messages/Image.hpp index 193ba5787..a4ad674fe 100644 --- a/src/messages/Image.hpp +++ b/src/messages/Image.hpp @@ -50,6 +50,9 @@ using ImagePtr = std::shared_ptr; class Image : public std::enable_shared_from_this, boost::noncopyable { public: + // Maximum amount of RAM used by the image in bytes. + static constexpr int maxBytesRam = 20 * 1024 * 1024; + ~Image(); static ImagePtr fromUrl(const Url &url, qreal scale = 1);