1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 11:24:56 +00:00

liblzma: file info decoder: Add an integer overflow check

After the previous commit, the overflow should be impossible, but it's
better to add the check anyway.

Fixes: https://github.com/tukaani-project/xz/pull/226
This commit is contained in:
Lasse Collin 2026-06-16 21:48:57 +03:00
parent a73f4c6715
commit 56c18ccfb7
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -717,6 +717,13 @@ file_info_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
}
}
// combined_index_memusage + this_index_memusage shouldn't overflow
// because combined_index_memusage is limited by how much can be
// successfully allocated, and this_index_memusage is limited by
// INDEX_RECORDS_MAX in index_decoder.c. Check for overflow anyway.
if (UINT64_MAX - combined_index_memusage < this_index_memusage)
return LZMA_PROG_ERROR;
// Now we know the total memory usage/requirement. If we had neither
// old Indexes nor a new Index, this will be zero which isn't
// acceptable as lzma_memusage() has to return non-zero on success