diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2020-06-05 13:35:03 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2020-06-26 15:23:58 +0200 |
commit | 5dea4fe956c452be5aae2c61dd0777fdf1efe5d0 (patch) | |
tree | e898d84182f7c3f55c93908b7fec63dfa1712607 /src/gui/image/qimagereader.cpp | |
parent | cc857a3c716729610ef61fa075f8d360684dae09 (diff) |
Introduce a settable allocation limit on image loading
[ChangeLog][QtGui][QImageReader] Introduced a settable allocation
limit on image loading to limit resource usage from corrupt image
files.
Change-Id: Ibed7b0cac32798125a060e6db80b17ebc5e70759
Task-number: QTBUG-85037
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/image/qimagereader.cpp')
-rw-r--r-- | src/gui/image/qimagereader.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 684442eb8f..a3ff898222 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -492,8 +492,12 @@ public: QString errorString; QImageReader *q; + + static int maxAlloc; }; +int QImageReaderPrivate::maxAlloc = 128; // 128 MB is enough for an 8K 32bpp image + /*! \internal */ @@ -1575,4 +1579,34 @@ QList<QByteArray> QImageReader::imageFormatsForMimeType(const QByteArray &mimeTy QImageReaderWriterHelpers::CanRead); } +/*! + \since 6.0 + + Returns the current allocation limit, in megabytes. + + \sa setAllocationLimit() +*/ +int QImageReader::allocationLimit() +{ + return QImageReaderPrivate::maxAlloc; +} + +/*! + \since 6.0 + + Sets the allocation limit to \a mbLimit megabytes. Images that would + require a QImage memory allocation above this limit will be rejected. + + This limit helps applications avoid unexpectedly large memory usage from + loading corrupt image files. It is normally not needed to change it. The + default limit is large enough for all commonly used image sizes. + + \sa allocationLimit() +*/ +void QImageReader::setAllocationLimit(int mbLimit) +{ + if (mbLimit >= 0) + QImageReaderPrivate::maxAlloc = mbLimit; +} + QT_END_NAMESPACE |