From 454f4679ef838f866faf26e8f20c960ae5191795 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. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-104972 Change-Id: Ifa375f59fb6ff5e0324d2208f4c2882174f9a44d Reviewed-by: Edward Welbourne --- 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 826c0b2be0..f5b468ad6e 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -633,7 +633,8 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) if (len > MaxDecompressedSize) 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();