]> granicus.if.org Git - xz/commitdiff
Make the raw value of the Check field available to applications
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 26 May 2009 11:48:48 +0000 (14:48 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 26 May 2009 11:48:48 +0000 (14:48 +0300)
via lzma_block structure.

This changes ABI but not doesn't break API.

src/liblzma/api/lzma/block.h
src/liblzma/common/block_buffer_encoder.c
src/liblzma/common/block_decoder.c
src/liblzma/common/block_encoder.c

index 566edce15e192f312b8a28e86537d085ee630653..ab2bb5bf7ee58cf2aa959aed7732ece032fa6c30 100644 (file)
@@ -207,6 +207,23 @@ typedef struct {
         */
        lzma_filter *filters;
 
+       /**
+        * \brief       Raw value stored in the Check field
+        *
+        * After successful coding, the first lzma_check_size(check) bytes
+        * of this array contain the raw value stored in the Check field.
+        *
+        * Note that CRC32 and CRC64 are stored in little endian byte order.
+        * Take it into account if you display the Check values to the user.
+        *
+        * Written by:
+        *  - lzma_block_encoder()
+        *  - lzma_block_decoder()
+        *  - lzma_block_buffer_encode()
+        *  - lzma_block_buffer_decode()
+        */
+       uint8_t raw_check[64];
+
        /*
         * Reserved space to allow possible future extensions without
         * breaking the ABI. You should not touch these, because the names
index ef6aeb82faa298621a6b8c83fba5adbf8e5294ca..4d90feef50bd2d7cdce07516f81469e00e4aba36 100644 (file)
@@ -290,6 +290,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
                lzma_check_update(&check, block->check, in, in_size);
                lzma_check_finish(&check, block->check);
 
+               memcpy(block->raw_check, check.buffer.u8, check_size);
                memcpy(out + *out_pos, check.buffer.u8, check_size);
                *out_pos += check_size;
        }
index 9b998e63cc828cfc83f8d127c666e1bd6366d9fa..a3ce6f49500ca952b116c56631f2160334d7281f 100644 (file)
@@ -146,26 +146,22 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator,
        // Fall through
 
        case SEQ_CHECK: {
-               const bool chksup = lzma_check_is_supported(
-                               coder->block->check);
-
-               while (*in_pos < in_size) {
-                       // coder->check.buffer[] may be uninitialized when
-                       // the Check ID is not supported.
-                       if (chksup && coder->check.buffer.u8[coder->check_pos]
-                                       != in[*in_pos]) {
-                               ++*in_pos;
-                               return LZMA_DATA_ERROR;
-                       }
-
-                       ++*in_pos;
-
-                       if (++coder->check_pos == lzma_check_size(
-                                       coder->block->check))
-                               return LZMA_STREAM_END;
-               }
+               const size_t check_size = lzma_check_size(coder->block->check);
+               lzma_bufcpy(in, in_pos, in_size, coder->block->raw_check,
+                               &coder->check_pos, check_size);
+               if (coder->check_pos < check_size)
+                       return LZMA_OK;
+
+               // Validate the Check only if we support it.
+               // coder->check.buffer may be uninitialized
+               // when the Check ID is not supported.
+               if (lzma_check_is_supported(coder->block->check)
+                               && memcmp(coder->block->raw_check,
+                                       coder->check.buffer.u8,
+                                       check_size) != 0)
+                       return LZMA_DATA_ERROR;
 
-               return LZMA_OK;
+               return LZMA_STREAM_END;
        }
        }
 
index 0d7b3ef23c97131b924627df5dd08e08f424f74b..567889aa2f6415d643001ae7e8435a154c3d0b76 100644 (file)
@@ -117,18 +117,15 @@ block_encode(lzma_coder *coder, lzma_allocator *allocator,
        // Fall through
 
        case SEQ_CHECK: {
-               const uint32_t check_size
-                               = lzma_check_size(coder->block->check);
-
-               while (*out_pos < out_size) {
-                       out[*out_pos] = coder->check.buffer.u8[coder->pos];
-                       ++*out_pos;
-
-                       if (++coder->pos == check_size)
-                               return LZMA_STREAM_END;
-               }
-
-               return LZMA_OK;
+               const size_t check_size = lzma_check_size(coder->block->check);
+               lzma_bufcpy(coder->check.buffer.u8, &coder->pos, check_size,
+                               out, out_pos, out_size);
+               if (coder->pos < check_size)
+                       return LZMA_OK;
+
+               memcpy(coder->block->raw_check, coder->check.buffer.u8,
+                               check_size);
+               return LZMA_STREAM_END;
        }
        }