Commit 111f5cb6 for xz
commit 111f5cb6de0c0afbef5d46a51eeb01eafaa4b8ff
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Sat Nov 28 15:35:56 2026 +0200
liblzma: mt dec: Set mem_direct_mode before Block decoder init
If Block decoder initialization fails due to allocation failure, it's
nice if lzma_memusage() will then return the amount of memory that the
decoder tried to allocate. Before this commit, the return value was from
the previous Block if it used direct mode, or LZMA_MEMUSAGE_BASE (32 KiB).
diff --git a/src/liblzma/common/stream_decoder_mt.c b/src/liblzma/common/stream_decoder_mt.c
index 43502fee..d7937e2c 100644
--- a/src/liblzma/common/stream_decoder_mt.c
+++ b/src/liblzma/common/stream_decoder_mt.c
@@ -1591,6 +1591,12 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
// array.
threads_end(coder, allocator);
+ // Make the memory usage visible to _memconfig().
+ // Do this before initializing the Block decoder: if
+ // the initialization fails, we want lzma_memusage()
+ // to report what the memory usage would have been.
+ coder->mem_direct_mode = coder->mem_next_filters;
+
// Initialize the Block decoder.
const lzma_ret ret = lzma_block_decoder_init(
&coder->block_decoder, allocator,
@@ -1605,9 +1611,6 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
if (ret != LZMA_OK)
return ret;
- // Make the memory usage visible to _memconfig().
- coder->mem_direct_mode = coder->mem_next_filters;
-
coder->sequence = SEQ_BLOCK_DIRECT_RUN;
FALLTHROUGH;
}