1
0
mirror of https://git.tukaani.org/xz.git synced 2025-12-11 16:08:45 +00:00

liblzma: Silence two Coverity warnings

lzma_lzma_decoder_memusage() returns UINT64_MAX if lc/lp/pb aren't
valid. alone_decoder.c and lzip_decoder.c didn't check the return
value because in both it is known that lc/lp/pb are valid. Make them
call the _nocheck() variant instead which skips the validation (it
already existed for LZMA2's internal use).

Fixes: Coverity CID 464658
Fixes: Coverity CID 897069
This commit is contained in:
Lasse Collin 2025-11-02 12:17:50 +02:00
parent be365b7010
commit 90b67853d5
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
3 changed files with 12 additions and 8 deletions

View File

@ -128,8 +128,10 @@ alone_decode(void *coder_ptr, const lzma_allocator *allocator,
lzma_set_ext_size(coder->options, coder->uncompressed_size);
// Calculate the memory usage so that it is ready
// for SEQ_CODER_INIT.
coder->memusage = lzma_lzma_decoder_memusage(&coder->options)
// for SEQ_CODER_INIT. We know that lc/lp/pb are valid
// so we can use the _nocheck variant.
coder->memusage
= lzma_lzma_decoder_memusage_nocheck(&coder->options)
+ LZMA_MEMUSAGE_BASE;
coder->pos = 0;

View File

@ -212,7 +212,8 @@ lzip_decode(void *coder_ptr, const lzma_allocator *allocator,
coder->options.pb = LZIP_PB;
// Calculate the memory usage.
coder->memusage = lzma_lzma_decoder_memusage(&coder->options)
coder->memusage
= lzma_lzma_decoder_memusage_nocheck(&coder->options)
+ LZMA_MEMUSAGE_BASE;
// Initialization is a separate step because if we return

View File

@ -23,6 +23,12 @@ extern lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next,
extern uint64_t lzma_lzma_decoder_memusage(const void *options);
/// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
/// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb. Also
/// alone_decoder.c and lzip_decoder.c use this because there lc/lp/pb
/// are known to be valid.
extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options);
extern lzma_ret lzma_lzma_props_decode(
void **options, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size);
@ -42,11 +48,6 @@ extern bool lzma_lzma_lclppb_decode(
extern lzma_ret lzma_lzma_decoder_create(
lzma_lz_decoder *lz, const lzma_allocator *allocator,
const lzma_options_lzma *opt, lzma_lz_options *lz_options);
/// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
/// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb.
extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options);
#endif
#endif