Skip to content

Commit

Permalink
Fuzzing: Don't try to load huge valid images
Browse files Browse the repository at this point in the history
They are justified in using huge memory.

Change-Id: Id16d2ea67cfac0e031d05258173391e222b41097
Reviewed-by: Albert Astals Cid <[email protected]>
Reviewed-by: Eirik Aavitsland <[email protected]>
(cherry picked from commit 927a82f)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
rlohning authored and Qt Cherry-pick Bot committed Jun 15, 2020
1 parent c6e4235 commit a7e45f1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/libfuzzer/gui/image/qimage/loadfromdata/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
**
****************************************************************************/

#include <QBuffer>
#include <QGuiApplication>
#include <QImage>
#include <QImageReader>
#include <QSize>
#include <QtGlobal>

// silence warnings
Expand All @@ -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;
}

0 comments on commit a7e45f1

Please sign in to comment.