Commit e44c4108 for xz
commit e44c4108b83ea0b9387192348f52dd6504327bc9
Author: Lasse Collin <lasse.collin@tukaani.org>
Date: Sun Nov 22 19:22:05 2026 +0200
liblzma: Fix an integer overflow detection in lzma_index_append()
If lzma_indexes had been concatenated using lzma_index_cat(),
lzma_index_append() didn't detect if the total uncompressed size
of the concatenated lzma_index would grow past LZMA_VLI_MAX; it
only checked against the last Stream in lzma_index.
Typically one doesn't use lzma_index_append() after lzma_index_cat(),
so it's likely that few, if any, apps can trigger this bug.
Also add a few related assertions.
Reported-by: GitHub user katie-andtruth
diff --git a/src/liblzma/common/index.c b/src/liblzma/common/index.c
index 3fbb5b1c..89efccfd 100644
--- a/src/liblzma/common/index.c
+++ b/src/liblzma/common/index.c
@@ -739,7 +739,8 @@ lzma_index_append(lzma_index *i, const lzma_allocator *allocator,
+ lzma_vli_size(uncompressed_size);
// Check that uncompressed size will not overflow.
- if (uncompressed_base + uncompressed_size > LZMA_VLI_MAX)
+ assert(uncompressed_base <= i->uncompressed_size);
+ if (i->uncompressed_size + uncompressed_size > LZMA_VLI_MAX)
return LZMA_DATA_ERROR;
// Check that the new unpadded sum will not overflow. This is
@@ -805,6 +806,10 @@ lzma_index_append(lzma_index *i, const lzma_allocator *allocator,
++i->record_count;
i->index_list_size += index_list_size_add;
+ assert(i->total_size <= LZMA_VLI_MAX);
+ assert(i->uncompressed_size <= LZMA_VLI_MAX);
+ assert(i->index_list_size <= LZMA_BACKWARD_SIZE_MAX);
+
return LZMA_OK;
}