aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/block_header_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/block_header_decoder.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/liblzma/common/block_header_decoder.c b/src/liblzma/common/block_header_decoder.c
index 8421ac37..82afb425 100644
--- a/src/liblzma/common/block_header_decoder.c
+++ b/src/liblzma/common/block_header_decoder.c
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file block_header_decoder.c
-/// \brief Decodes Block Header from .lzma files
+/// \brief Decodes Block Header from .xz files
//
// Copyright (C) 2007 Lasse Collin
//
@@ -22,15 +22,15 @@
static void
-free_properties(lzma_block *options, lzma_allocator *allocator)
+free_properties(lzma_block *block, lzma_allocator *allocator)
{
// Free allocated filter options. The last array member is not
// touched after the initialization in the beginning of
// lzma_block_header_decode(), so we don't need to touch that here.
for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) {
- lzma_free(options->filters[i].options, allocator);
- options->filters[i].id = LZMA_VLI_UNKNOWN;
- options->filters[i].options = NULL;
+ lzma_free(block->filters[i].options, allocator);
+ block->filters[i].id = LZMA_VLI_UNKNOWN;
+ block->filters[i].options = NULL;
}
return;
@@ -38,7 +38,7 @@ free_properties(lzma_block *options, lzma_allocator *allocator)
extern LZMA_API lzma_ret
-lzma_block_header_decode(lzma_block *options,
+lzma_block_header_decode(lzma_block *block,
lzma_allocator *allocator, const uint8_t *in)
{
// NOTE: We consider the header to be corrupt not only when the
@@ -49,18 +49,21 @@ lzma_block_header_decode(lzma_block *options,
// Initialize the filter options array. This way the caller can
// safely free() the options even if an error occurs in this function.
for (size_t i = 0; i <= LZMA_FILTERS_MAX; ++i) {
- options->filters[i].id = LZMA_VLI_UNKNOWN;
- options->filters[i].options = NULL;
+ block->filters[i].id = LZMA_VLI_UNKNOWN;
+ block->filters[i].options = NULL;
}
+ // Always zero for now.
+ block->version = 0;
+
// Validate Block Header Size and Check type. The caller must have
// already set these, so it is a programming error if this test fails.
- if (lzma_block_header_size_decode(in[0]) != options->header_size
- || (unsigned int)(options->check) > LZMA_CHECK_ID_MAX)
+ if (lzma_block_header_size_decode(in[0]) != block->header_size
+ || (unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
return LZMA_PROG_ERROR;
// Exclude the CRC32 field.
- const size_t in_size = options->header_size - 4;
+ const size_t in_size = block->header_size - 4;
// Verify CRC32
if (lzma_crc32(in, in_size, 0) != integer_read_32(in + in_size))
@@ -75,32 +78,32 @@ lzma_block_header_decode(lzma_block *options,
// Compressed Size
if (in[1] & 0x40) {
- return_if_error(lzma_vli_decode(&options->compressed_size,
+ return_if_error(lzma_vli_decode(&block->compressed_size,
NULL, in, &in_pos, in_size));
// Validate Compressed Size. This checks that it isn't zero
// and that the total size of the Block is a valid VLI.
- if (lzma_block_unpadded_size(options) == 0)
+ if (lzma_block_unpadded_size(block) == 0)
return LZMA_DATA_ERROR;
} else {
- options->compressed_size = LZMA_VLI_UNKNOWN;
+ block->compressed_size = LZMA_VLI_UNKNOWN;
}
// Uncompressed Size
if (in[1] & 0x80)
- return_if_error(lzma_vli_decode(&options->uncompressed_size,
+ return_if_error(lzma_vli_decode(&block->uncompressed_size,
NULL, in, &in_pos, in_size));
else
- options->uncompressed_size = LZMA_VLI_UNKNOWN;
+ block->uncompressed_size = LZMA_VLI_UNKNOWN;
// Filter Flags
const size_t filter_count = (in[1] & 3) + 1;
for (size_t i = 0; i < filter_count; ++i) {
const lzma_ret ret = lzma_filter_flags_decode(
- &options->filters[i], allocator,
+ &block->filters[i], allocator,
in, &in_pos, in_size);
if (ret != LZMA_OK) {
- free_properties(options, allocator);
+ free_properties(block, allocator);
return ret;
}
}
@@ -108,7 +111,7 @@ lzma_block_header_decode(lzma_block *options,
// Padding
while (in_pos < in_size) {
if (in[in_pos++] != 0x00) {
- free_properties(options, allocator);
+ free_properties(block, allocator);
// Possibly some new field present so use
// LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR.