]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Add support for LZMA_IGNORE_CHECK.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 5 Aug 2014 19:15:07 +0000 (22:15 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 5 Aug 2014 19:15:07 +0000 (22:15 +0300)
src/liblzma/api/lzma/container.h
src/liblzma/common/common.h
src/liblzma/common/stream_decoder.c

index 891c6b7af6a15d1f9af795ae0dc18baae9fd09e9..b9c5e71970d1597fc83233d6624c26d50d77a778 100644 (file)
@@ -473,6 +473,30 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
 #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
  * allow concatenating compressed files as is. From the formats currently
index b10a72e236c5d47d4d1962388aac380e5cdd6cfa..af14e479d0ed51dd445d5c242aaa4c3b6527b268 100644 (file)
@@ -75,6 +75,7 @@
        ( LZMA_TELL_NO_CHECK \
        | LZMA_TELL_UNSUPPORTED_CHECK \
        | LZMA_TELL_ANY_CHECK \
+       | LZMA_IGNORE_CHECK \
        | LZMA_CONCATENATED )
 
 
index 5243e4c64f1ad8a7419d9e245c0ba0c548abbda9..3ab938c9f1426d7421a8c5d52b299cad33614b4c 100644 (file)
@@ -57,6 +57,10 @@ struct lzma_coder_s {
        /// If true, LZMA_GET_CHECK is returned after decoding Stream Header.
        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
        /// 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
@@ -182,8 +186,8 @@ stream_decode(lzma_coder *coder, const lzma_allocator *allocator,
 
                coder->pos = 0;
 
-               // Version 0 is currently the only possible version.
-               coder->block_options.version = 0;
+               // Version 1 is needed to support the .ignore_check option.
+               coder->block_options.version = 1;
 
                // Set up a buffer to hold the filter chain. Block Header
                // 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,
                                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.
                const uint64_t memusage = lzma_raw_decoder_memusage(filters);
                lzma_ret ret;
@@ -433,6 +442,7 @@ lzma_stream_decoder_init(
        next->coder->tell_unsupported_check
                        = (flags & LZMA_TELL_UNSUPPORTED_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->first_stream = true;