mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
add a maximum RAM usage for images
This commit is contained in:
parent
97b9bfb2bd
commit
ed6ef0b98e
|
@ -405,6 +405,16 @@ void Image::actuallyLoad()
|
|||
QBuffer buffer(const_cast<QByteArray *>(&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) {
|
||||
|
|
|
@ -50,6 +50,9 @@ using ImagePtr = std::shared_ptr<Image>;
|
|||
class Image : public std::enable_shared_from_this<Image>, 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);
|
||||
|
|
Loading…
Reference in a new issue