From 8a08a877086c54b6cc5d8f2baa57da745d713d15 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 27 Dec 2019 05:24:04 +0000 Subject: [PATCH] warn on negative data size from qCompress() function Signed-off-by: Ivailo Monev --- src/core/tools/qbytearray.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/tools/qbytearray.cpp b/src/core/tools/qbytearray.cpp index 3d26af12b..20f7a04c9 100644 --- a/src/core/tools/qbytearray.cpp +++ b/src/core/tools/qbytearray.cpp @@ -405,13 +405,14 @@ QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel) #ifdef QT_FAST_COMPRESS return qFastCompress(reinterpret_cast(data), nbytes, compressionLevel); #else - if (nbytes == 0) { - return QByteArray(4, '\0'); - } if (Q_UNLIKELY(!data)) { qWarning("qCompress: Data is null"); return QByteArray(); + } else if (Q_UNLIKELY(nbytes <= 0)) { + qWarning("qCompress: Data size is negative or zero"); + return QByteArray(4, '\0'); } + if (compressionLevel < -1 || compressionLevel > 9) compressionLevel = -1; -- 2.11.0