QNetworkRequest: Rename (set)minimumArchiveBombSize

To (set)decompressedSafetyCheckThreshold, as suggested on the API review.

Task-number: QTBUG-94407
Change-Id: Iffc52691022939ae46703de8a0416355487b716f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2021-06-24 14:16:58 +02:00 committed by Timur Pocheptsov
parent f95d03b372
commit d33040548f
7 changed files with 22 additions and 21 deletions

View File

@ -329,7 +329,7 @@ bool QDecompressHelper::countInternal(const QByteArray &data)
if (countDecompressed) {
if (!countHelper) {
countHelper = std::make_unique<QDecompressHelper>();
countHelper->setMinimumArchiveBombSize(minimumArchiveBombSize);
countHelper->setDecompressedSafetyCheckThreshold(archiveBombCheckThreshold);
countHelper->setEncoding(contentEncoding);
}
countHelper->feed(data);
@ -347,7 +347,7 @@ bool QDecompressHelper::countInternal(const QByteDataBuffer &buffer)
if (countDecompressed) {
if (!countHelper) {
countHelper = std::make_unique<QDecompressHelper>();
countHelper->setMinimumArchiveBombSize(minimumArchiveBombSize);
countHelper->setDecompressedSafetyCheckThreshold(archiveBombCheckThreshold);
countHelper->setEncoding(contentEncoding);
}
countHelper->feed(buffer);
@ -398,11 +398,11 @@ qsizetype QDecompressHelper::read(char *data, qsizetype maxSize)
By default this is 10MB. Setting it to -1 is treated as disabling the
feature.
*/
void QDecompressHelper::setMinimumArchiveBombSize(qint64 threshold)
void QDecompressHelper::setDecompressedSafetyCheckThreshold(qint64 threshold)
{
if (threshold == -1)
threshold = std::numeric_limits<qint64>::max();
minimumArchiveBombSize = threshold;
archiveBombCheckThreshold = threshold;
}
bool QDecompressHelper::isPotentialArchiveBomb() const
@ -410,7 +410,7 @@ bool QDecompressHelper::isPotentialArchiveBomb() const
if (totalCompressedBytes == 0)
return false;
if (totalUncompressedBytes <= minimumArchiveBombSize)
if (totalUncompressedBytes <= archiveBombCheckThreshold)
return false;
// Some protection against malicious or corrupted compressed files that expand far more than

View File

@ -91,7 +91,7 @@ public:
void clear();
void setMinimumArchiveBombSize(qint64 threshold);
void setDecompressedSafetyCheckThreshold(qint64 threshold);
static bool isSupportedEncoding(const QByteArray &encoding);
static QByteArrayList acceptedEncoding();
@ -118,7 +118,7 @@ private:
qint64 uncompressedBytes = 0;
// Used for calculating the ratio
qint64 minimumArchiveBombSize = 10 * 1024 * 1024;
qint64 archiveBombCheckThreshold = 10 * 1024 * 1024;
qint64 totalUncompressedBytes = 0;
qint64 totalCompressedBytes = 0;

View File

@ -1366,7 +1366,8 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QList<QPair<QByte
error(QNetworkReplyImpl::NetworkError::ProtocolFailure,
QCoreApplication::translate("QHttp", "Data corrupted"));
}
decompressHelper.setMinimumArchiveBombSize(request.minimumArchiveBombSize());
decompressHelper.setDecompressedSafetyCheckThreshold(
request.decompressedSafetyCheckThreshold());
}
if (!value.isEmpty()) {

View File

@ -441,7 +441,7 @@ public:
peerVerifyName = other.peerVerifyName;
#if QT_CONFIG(http)
h2Configuration = other.h2Configuration;
minimumArchiveBombSize = other.minimumArchiveBombSize;
decompressedSafetyCheckThreshold = other.decompressedSafetyCheckThreshold;
#endif
transferTimeout = other.transferTimeout;
}
@ -456,7 +456,7 @@ public:
peerVerifyName == other.peerVerifyName
#if QT_CONFIG(http)
&& h2Configuration == other.h2Configuration
&& minimumArchiveBombSize == other.minimumArchiveBombSize
&& decompressedSafetyCheckThreshold == other.decompressedSafetyCheckThreshold
#endif
&& transferTimeout == other.transferTimeout
;
@ -472,7 +472,7 @@ public:
QString peerVerifyName;
#if QT_CONFIG(http)
QHttp2Configuration h2Configuration;
qint64 minimumArchiveBombSize = 10ll * 1024ll * 1024ll;
qint64 decompressedSafetyCheckThreshold = 10ll * 1024ll * 1024ll;
#endif
int transferTimeout;
};
@ -910,9 +910,9 @@ void QNetworkRequest::setHttp2Configuration(const QHttp2Configuration &configura
\sa setMinimumArchiveBombSize()
*/
qint64 QNetworkRequest::minimumArchiveBombSize() const
qint64 QNetworkRequest::decompressedSafetyCheckThreshold() const
{
return d->minimumArchiveBombSize;
return d->decompressedSafetyCheckThreshold;
}
/*!
@ -937,9 +937,9 @@ qint64 QNetworkRequest::minimumArchiveBombSize() const
\sa minimumArchiveBombSize()
*/
void QNetworkRequest::setMinimumArchiveBombSize(qint64 threshold)
void QNetworkRequest::setDecompressedSafetyCheckThreshold(qint64 threshold)
{
d->minimumArchiveBombSize = threshold;
d->decompressedSafetyCheckThreshold = threshold;
}
#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC)

View File

@ -180,8 +180,8 @@ public:
QHttp2Configuration http2Configuration() const;
void setHttp2Configuration(const QHttp2Configuration &configuration);
qint64 minimumArchiveBombSize() const;
void setMinimumArchiveBombSize(qint64 threshold);
qint64 decompressedSafetyCheckThreshold() const;
void setDecompressedSafetyCheckThreshold(qint64 threshold);
#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC)
#if QT_CONFIG(http) || defined(Q_CLANG_QDOC) || defined (Q_OS_WASM)

View File

@ -373,7 +373,7 @@ void tst_QDecompressHelper::decompressBigData()
const qint64 third = file.bytesAvailable() / 3;
QDecompressHelper helper;
helper.setMinimumArchiveBombSize(-1);
helper.setDecompressedSafetyCheckThreshold(-1);
QFETCH(QByteArray, encoding);
helper.setEncoding(encoding);
@ -442,7 +442,7 @@ void tst_QDecompressHelper::bigZlib()
QByteArray compressedData = file.readAll();
QDecompressHelper helper;
helper.setMinimumArchiveBombSize(-1);
helper.setDecompressedSafetyCheckThreshold(-1);
helper.setEncoding("deflate");
auto firstHalf = compressedData.left(compressedData.size() - 2);
helper.feed(firstHalf);

View File

@ -7064,7 +7064,7 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply()
QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
// QDecompressHelper will abort the download if the compressed to decompressed size ratio
// differs too much, so we override it
request.setMinimumArchiveBombSize(-1);
request.setDecompressedSafetyCheckThreshold(-1);
QNetworkReplyPtr reply(manager.get(request));
QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply));
@ -9471,7 +9471,7 @@ void tst_QNetworkReply::contentEncodingBigPayload()
QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
// QDecompressHelper will abort the download if the compressed to decompressed size ratio
// differs too much, so we override it
request.setMinimumArchiveBombSize(-1);
request.setDecompressedSafetyCheckThreshold(-1);
QNetworkReplyPtr reply(manager.get(request));
QTRY_VERIFY2_WITH_TIMEOUT(reply->isFinished(), qPrintable(reply->errorString()), 15000);