Commit b53838ae for xz
commit b53838ae0caf9f09b976a8577cf4392910d6f02c
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Tue May 19 13:52:41 2026 +0300
liblzma: lzma_stream_buffer_decode: Fix wrong error code
lzma_stream_buffer_decode() would often fail with LZMA_BUF_ERROR
when it should have failed with LZMA_DATA_ERROR.
In debug builds this also resulted in an assertion failure.
In the _buffer_decode() functions, LZMA_BUF_ERROR is only used when
the output buffer is too small. Truncated input is LZMA_DATA_ERROR.
Reported-by: Guanni Qu
Reported-by: Omkhar Arasaratnam
Fixes: c81f13ff2927 ("Added lzma_stream_buffer_decode() and made minor cleanups.")
diff --git a/src/liblzma/common/stream_buffer_decoder.c b/src/liblzma/common/stream_buffer_decoder.c
index c4f91fb4..bbf20046 100644
--- a/src/liblzma/common/stream_buffer_decoder.c
+++ b/src/liblzma/common/stream_buffer_decoder.c
@@ -50,10 +50,6 @@ lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
if (ret == LZMA_STREAM_END) {
ret = LZMA_OK;
} else {
- // Something went wrong, restore the positions.
- *in_pos = in_start;
- *out_pos = out_start;
-
if (ret == LZMA_OK) {
// Either the input was truncated or the
// output buffer was too small.
@@ -78,6 +74,10 @@ lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
stream_decoder.coder,
memlimit, &memusage, 0);
}
+
+ // Something went wrong, restore the positions.
+ *in_pos = in_start;
+ *out_pos = out_start;
}
}