From d33040548ff727a040ea66174cbd838e883fed56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 24 Jun 2021 14:16:58 +0200 Subject: [PATCH] QNetworkRequest: Rename (set)minimumArchiveBombSize To (set)decompressedSafetyCheckThreshold, as suggested on the API review. Task-number: QTBUG-94407 Change-Id: Iffc52691022939ae46703de8a0416355487b716f Reviewed-by: Timur Pocheptsov Reviewed-by: Edward Welbourne --- src/network/access/qdecompresshelper.cpp | 10 +++++----- src/network/access/qdecompresshelper_p.h | 4 ++-- src/network/access/qnetworkreplyhttpimpl.cpp | 3 ++- src/network/access/qnetworkrequest.cpp | 14 +++++++------- src/network/access/qnetworkrequest.h | 4 ++-- .../qdecompresshelper/tst_qdecompresshelper.cpp | 4 ++-- .../access/qnetworkreply/tst_qnetworkreply.cpp | 4 ++-- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/network/access/qdecompresshelper.cpp b/src/network/access/qdecompresshelper.cpp index d51f9a290e5..451684bf1b7 100644 --- a/src/network/access/qdecompresshelper.cpp +++ b/src/network/access/qdecompresshelper.cpp @@ -329,7 +329,7 @@ bool QDecompressHelper::countInternal(const QByteArray &data) if (countDecompressed) { if (!countHelper) { countHelper = std::make_unique(); - 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(); - 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::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 diff --git a/src/network/access/qdecompresshelper_p.h b/src/network/access/qdecompresshelper_p.h index 96199a91f87..33241e14f1c 100644 --- a/src/network/access/qdecompresshelper_p.h +++ b/src/network/access/qdecompresshelper_p.h @@ -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; diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index cc6590f7131..b68e82a5e12 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1366,7 +1366,8 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QListminimumArchiveBombSize; + 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) diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index fe18115f757..72848ff4901 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -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) diff --git a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp index 02f81b0e6cc..c9849fdcdfc 100644 --- a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp +++ b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp @@ -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); diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 4713652d8c1..ccc70cfff4b 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -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);