kdecore: check for LZMA_BUF_ERROR when attempting to grow the output buffer

output is still truncated to the initial speculative size, i.e. lzma_code()
returns LZMA_OK even if the output buffer is not big enough to hold the
decompressed data - it just stops decompressing when the output buffer
size is reached

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-17 22:42:53 +03:00
parent 458788a6d9
commit 37c67fafbb

View file

@ -221,6 +221,7 @@ bool KDecompressor::process(const QByteArray &data)
case KDecompressor::TypeBZip2: {
uint speculativesize = (data.size() * 2);
d->m_result.resize(speculativesize);
int decompresult = BZ_OUTBUFF_FULL;
while (decompresult == BZ_OUTBUFF_FULL) {
decompresult = BZ2_bzBuffToBuffDecompress(
@ -267,13 +268,16 @@ bool KDecompressor::process(const QByteArray &data)
return false;
}
decompresult = LZMA_MEM_ERROR;
while (decompresult == LZMA_MEM_ERROR) {
// FIXME: LZMA_BUF_ERROR is not returned if the output buffer is not big enough, what's
// going on?
decompresult = LZMA_BUF_ERROR;
while (decompresult == LZMA_BUF_ERROR) {
decompresult = lzma_code(&decomp, LZMA_FINISH);
if (decompresult == LZMA_MEM_ERROR) {
if (decompresult == LZMA_BUF_ERROR) {
speculativesize = (speculativesize + QT_BUFFSIZE);
d->m_result.resize(speculativesize);
decomp.avail_out = speculativesize;
}
if (speculativesize >= INT_MAX) {