From dbffd02febd86aebdff78c27db04009dc81cdc07 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 8 Sep 2022 16:26:01 +0200 Subject: [PATCH] qUncompress: make a narrowing conversion explicit ... and add an assertion. The assertion can only trigger if our definition of MaxDecompressedSize is wrong. Task-number: QTBUG-104972 Change-Id: Ifa375f59fb6ff5e0324d2208f4c2882174f9a44d Reviewed-by: Edward Welbourne (cherry picked from commit 454f4679ef838f866faf26e8f20c960ae5191795) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qbytearray.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 0559ff8fd5d..a3aecd282c6 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -638,7 +638,8 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) return invalidCompressedData(); } - QByteArray::DataPointer d(QByteArray::Data::allocate(len)); + Q_ASSERT(len <= size_t((std::numeric_limits::max)())); + QByteArray::DataPointer d(QByteArray::Data::allocate(qsizetype(len))); if (d.data() == nullptr) // allocation failed return invalidCompressedData();