From 0b2eca3066975dadb594195542b0c3e20ae48762 Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Sun, 15 Sep 2024 06:20:17 -0700 Subject: [PATCH] fix: LZMA decompressor memory errors (#1873) ### Problem description I was unable to use the LZMA de-compressor even though 7zip was able to identify them as LZMA compressed and decompress them without a problem. Under the debugger the `lzma_code()` call was returning `LZMA_MEMLIMIT_ERROR`. ### Implementation description I found online that the error can be fixed using `lzma_memlimit_set()` using a value obtained with `lzma_memusage()`. I tried to avoid having to call `lzma_code()` twice but if the functions are called before the first `lzma_code()`the values of memory obtained fall short and error occurs again. I suspect that there are better ways to deal with this other than the code proposed in this PR, but I haven't been able to find any. --------- Co-authored-by: Nik --- plugins/decompress/source/content/pl_functions.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/decompress/source/content/pl_functions.cpp b/plugins/decompress/source/content/pl_functions.cpp index 5589a1b95..87388be39 100644 --- a/plugins/decompress/source/content/pl_functions.cpp +++ b/plugins/decompress/source/content/pl_functions.cpp @@ -174,6 +174,13 @@ namespace hex::plugin::decompress { section.resize(section.size() - stream.avail_out); break; } + + if (res == LZMA_MEMLIMIT_ERROR) { + auto usage = lzma_memusage(&stream); + lzma_memlimit_set(&stream, usage); + res = lzma_code(&stream, LZMA_RUN); + } + if (res != LZMA_OK) return false;