OSDN Git Service

allocate compression buffer on the heap from qCompress()
authorIvailo Monev <xakepa10@gmail.com>
Sat, 26 Feb 2022 14:07:20 +0000 (16:07 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 26 Feb 2022 14:07:32 +0000 (16:07 +0200)
fixes crash in case the buffer has to be larger than the stack limit

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/tools/qbytearray.cpp

index 71683aa..1c6ccd2 100644 (file)
@@ -343,8 +343,8 @@ QByteArray qCompress(const char* data, int nbytes, int compressionLevel)
         return QByteArray();
     }
 
-    QSTACKARRAY(char, compbuffer, boundresult);
-    const size_t compresult = libdeflate_gzip_compress(comp, data, nbytes, compbuffer, boundresult);
+    QByteArray result(boundresult, Qt::Uninitialized);
+    const size_t compresult = libdeflate_gzip_compress(comp, data, nbytes, result.data(), result.size());
     libdeflate_free_compressor(comp);
 
     if (Q_UNLIKELY(compresult <= 0)) {
@@ -352,7 +352,8 @@ QByteArray qCompress(const char* data, int nbytes, int compressionLevel)
         return QByteArray();
     }
 
-    return QByteArray(compbuffer, compresult);
+    result.resize(compresult);
+    return result;
 }
 
 /*!