liblzma: Add support for LZMA_IGNORE_CHECK.

This commit is contained in:
Lasse Collin 2014-08-05 22:15:07 +03:00
parent 0e0f34b8e4
commit 9adbc2ff37
3 changed files with 37 additions and 2 deletions

View File

@ -473,6 +473,30 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
#define LZMA_TELL_ANY_CHECK UINT32_C(0x04) #define LZMA_TELL_ANY_CHECK UINT32_C(0x04)
/**
* This flag makes lzma_code() not calculate and verify the integrity check
* of the compressed data in .xz files. This means that invalid integrity
* check values won't be detected and LZMA_DATA_ERROR won't be returned in
* such cases.
*
* This flag only affects the checks of the compressed data itself; the CRC32
* values in the .xz headers will still be verified normally.
*
* Don't use this flag unless you know what you are doing. Possible reasons
* to use this flag:
*
* - Trying to recover data from a corrupt .xz file.
*
* - Speeding up decompression, which matters mostly with SHA-256
* or with files that have compressed extremely well. It's recommended
* to not use this flag for this purpose unless the file integrity is
* verified externally in some other way.
*
* Support for this flag was added in liblzma 5.1.4beta.
*/
#define LZMA_IGNORE_CHECK UINT32_C(0x10)
/** /**
* This flag enables decoding of concatenated files with file formats that * This flag enables decoding of concatenated files with file formats that
* allow concatenating compressed files as is. From the formats currently * allow concatenating compressed files as is. From the formats currently

View File

@ -75,6 +75,7 @@
( LZMA_TELL_NO_CHECK \ ( LZMA_TELL_NO_CHECK \
| LZMA_TELL_UNSUPPORTED_CHECK \ | LZMA_TELL_UNSUPPORTED_CHECK \
| LZMA_TELL_ANY_CHECK \ | LZMA_TELL_ANY_CHECK \
| LZMA_IGNORE_CHECK \
| LZMA_CONCATENATED ) | LZMA_CONCATENATED )

View File

@ -57,6 +57,10 @@ struct lzma_coder_s {
/// If true, LZMA_GET_CHECK is returned after decoding Stream Header. /// If true, LZMA_GET_CHECK is returned after decoding Stream Header.
bool tell_any_check; bool tell_any_check;
/// If true, we will tell the Block decoder to skip calculating
/// and verifying the integrity check.
bool ignore_check;
/// If true, we will decode concatenated Streams that possibly have /// If true, we will decode concatenated Streams that possibly have
/// Stream Padding between or after them. LZMA_STREAM_END is returned /// Stream Padding between or after them. LZMA_STREAM_END is returned
/// once the application isn't giving us any new input, and we aren't /// once the application isn't giving us any new input, and we aren't
@ -182,8 +186,8 @@ stream_decode(lzma_coder *coder, const lzma_allocator *allocator,
coder->pos = 0; coder->pos = 0;
// Version 0 is currently the only possible version. // Version 1 is needed to support the .ignore_check option.
coder->block_options.version = 0; coder->block_options.version = 1;
// Set up a buffer to hold the filter chain. Block Header // Set up a buffer to hold the filter chain. Block Header
// decoder will initialize all members of this array so // decoder will initialize all members of this array so
@ -195,6 +199,11 @@ stream_decode(lzma_coder *coder, const lzma_allocator *allocator,
return_if_error(lzma_block_header_decode(&coder->block_options, return_if_error(lzma_block_header_decode(&coder->block_options,
allocator, coder->buffer)); allocator, coder->buffer));
// If LZMA_IGNORE_CHECK was used, this flag needs to be set.
// It has to be set after lzma_block_header_decode() because
// it always resets this to false.
coder->block_options.ignore_check = coder->ignore_check;
// Check the memory usage limit. // Check the memory usage limit.
const uint64_t memusage = lzma_raw_decoder_memusage(filters); const uint64_t memusage = lzma_raw_decoder_memusage(filters);
lzma_ret ret; lzma_ret ret;
@ -433,6 +442,7 @@ lzma_stream_decoder_init(
next->coder->tell_unsupported_check next->coder->tell_unsupported_check
= (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0; = (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0;
next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0; next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
next->coder->ignore_check = (flags & LZMA_IGNORE_CHECK) != 0;
next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0; next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
next->coder->first_stream = true; next->coder->first_stream = true;