Commit 5d8a735d for xz
commit 5d8a735db7614599a7cd527af739c6e59370e3aa
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Tue Nov 17 19:13:15 2026 +0200
liblzma: Initialize total_in and total_out even if an error occurs
Reported-by: GitHub user katie-andtruth
Reported-by: Pu Cheng
Link: https://github.com/tukaani-project/xz/pull/265
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
index 6e031a56..7f73559e 100644
--- a/src/liblzma/common/common.c
+++ b/src/liblzma/common/common.c
@@ -179,6 +179,12 @@ lzma_strm_init(lzma_stream *strm)
if (strm == NULL)
return LZMA_PROG_ERROR;
+ // Initialize these here because the API docs suggest that these
+ // are initialized even if an error occurs. liblzma 5.8.4 and older
+ // didn't initialize these on error.
+ strm->total_in = 0;
+ strm->total_out = 0;
+
if (strm->internal == NULL) {
strm->internal = lzma_alloc(sizeof(lzma_internal),
strm->allocator);
@@ -193,9 +199,6 @@ lzma_strm_init(lzma_stream *strm)
strm->internal->sequence = ISEQ_RUN;
strm->internal->allow_buf_error = false;
- strm->total_in = 0;
- strm->total_out = 0;
-
return LZMA_OK;
}