From 927a82f5e0d0e8a174cbb027c58412e13f7067c5 Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Mon, 8 Jun 2020 14:42:55 +0200 Subject: [PATCH] Fuzzing: Don't try to load huge valid images They are justified in using huge memory. Pick-to: 5.15 Change-Id: Id16d2ea67cfac0e031d05258173391e222b41097 Reviewed-by: Albert Astals Cid Reviewed-by: Eirik Aavitsland --- .../libfuzzer/gui/image/qimage/loadfromdata/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/libfuzzer/gui/image/qimage/loadfromdata/main.cpp b/tests/libfuzzer/gui/image/qimage/loadfromdata/main.cpp index 46d48ebf8cc..54d1ed0ee67 100644 --- a/tests/libfuzzer/gui/image/qimage/loadfromdata/main.cpp +++ b/tests/libfuzzer/gui/image/qimage/loadfromdata/main.cpp @@ -26,8 +26,11 @@ ** ****************************************************************************/ +#include #include #include +#include +#include #include // silence warnings @@ -41,6 +44,12 @@ extern "C" int LLVMFuzzerTestOneInput(const char *Data, size_t Size) { static char arg3[] = "minimal"; static char *argv[] = {arg1, arg2, arg3, nullptr}; static QGuiApplication qga(argc, argv); - QImage().loadFromData(QByteArray::fromRawData(Data, Size)); + QByteArray input(QByteArray::fromRawData(Data, Size)); + QBuffer buf(&input); + const QSize size = QImageReader(&buf).size(); + // Don't try to load huge valid images. + // They are justified in using huge memory. + if (!size.isValid() || uint64_t(size.width()) * size.height() < 64 * 1024 * 1024) + QImage().loadFromData(input); return 0; }