block_header_decoder.c   block_header_decoder.c 
skipping to change at line 17 skipping to change at line 17
// //
// This file has been put into the public domain. // This file has been put into the public domain.
// You can do whatever you want with this file. // You can do whatever you want with this file.
// //
/////////////////////////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////////////////////////// ////
#include "common.h" #include "common.h"
#include "check.h" #include "check.h"
static void static void
free_properties(lzma_block *block, lzma_allocator *allocator) free_properties(lzma_block *block, const lzma_allocator *allocator)
{ {
// Free allocated filter options. The last array member is not // Free allocated filter options. The last array member is not
// touched after the initialization in the beginning of // touched after the initialization in the beginning of
// lzma_block_header_decode(), so we don't need to touch that here. // lzma_block_header_decode(), so we don't need to touch that here.
for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) { for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) {
lzma_free(block->filters[i].options, allocator); lzma_free(block->filters[i].options, allocator);
block->filters[i].id = LZMA_VLI_UNKNOWN; block->filters[i].id = LZMA_VLI_UNKNOWN;
block->filters[i].options = NULL; block->filters[i].options = NULL;
} }
return; return;
} }
extern LZMA_API(lzma_ret) extern LZMA_API(lzma_ret)
lzma_block_header_decode(lzma_block *block, lzma_block_header_decode(lzma_block *block,
lzma_allocator *allocator, const uint8_t *in) const lzma_allocator *allocator, const uint8_t *in)
{ {
// NOTE: We consider the header to be corrupt not only when the // NOTE: We consider the header to be corrupt not only when the
// CRC32 doesn't match, but also when variable-length integers // CRC32 doesn't match, but also when variable-length integers
// are invalid or over 63 bits, or if the header is too small // are invalid or over 63 bits, or if the header is too small
// to contain the claimed information. // to contain the claimed information.
// Initialize the filter options array. This way the caller can // Initialize the filter options array. This way the caller can
// safely free() the options even if an error occurs in this functio n. // safely free() the options even if an error occurs in this functio n.
for (size_t i = 0; i <= LZMA_FILTERS_MAX; ++i) { for (size_t i = 0; i <= LZMA_FILTERS_MAX; ++i) {
block->filters[i].id = LZMA_VLI_UNKNOWN; block->filters[i].id = LZMA_VLI_UNKNOWN;
block->filters[i].options = NULL; block->filters[i].options = NULL;
} }
// Always zero for now. // Versions 0 and 1 are supported. If a newer version was specified,
block->version = 0; // we need to downgrade it.
if (block->version > 1)
block->version = 1;
// This isn't a Block Header option, but since the decompressor will
// read it if version >= 1, it's better to initialize it here than
// to expect the caller to do it since in almost all cases this
// should be false.
block->ignore_check = false;
// Validate Block Header Size and Check type. The caller must have // Validate Block Header Size and Check type. The caller must have
// already set these, so it is a programming error if this test fail s. // already set these, so it is a programming error if this test fail s.
if (lzma_block_header_size_decode(in[0]) != block->header_size if (lzma_block_header_size_decode(in[0]) != block->header_size
|| (unsigned int)(block->check) > LZMA_CHECK_ID_MAX) || (unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
return LZMA_PROG_ERROR; return LZMA_PROG_ERROR;
// Exclude the CRC32 field. // Exclude the CRC32 field.
const size_t in_size = block->header_size - 4; const size_t in_size = block->header_size - 4;
 End of changes. 3 change blocks. 
4 lines changed or deleted 12 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/