liblzma: Verify the filter chain in threaded encoder initialization.

This way an invalid filter chain is detected at the Stream
encoder initialization instead of delaying it to the first
call to lzma_code() which triggers the initialization of
the actual filter encoder(s).
This commit is contained in:
Lasse Collin 2014-11-25 12:32:05 +02:00
parent 107a263d5b
commit 2301f3f05d
1 changed files with 6 additions and 3 deletions

View File

@ -947,9 +947,12 @@ stream_encoder_mt_init(lzma_next_coder *next, const lzma_allocator *allocator,
return LZMA_MEM_ERROR; return LZMA_MEM_ERROR;
#endif #endif
// FIXME TODO: Validate the filter chain so that we can give // Validate the filter chain so that we can give an error in this
// an error in this function instead of delaying it to the first // function instead of delaying it to the first call to lzma_code().
// call to lzma_code(). // The memory usage calculation verifies the filter chain as
// a side effect so we take advatange of that.
if (lzma_raw_encoder_memusage(filters) == UINT64_MAX)
return LZMA_OPTIONS_ERROR;
// Validate the Check ID. // Validate the Check ID.
if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX) if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX)