From 13a74b78e37f16c9096ba5fe1859cc04eaa2f9f7 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sat, 13 Sep 2008 12:10:43 +0300 Subject: Renamed constants: - LZMA_VLI_VALUE_MAX -> LZMA_VLI_MAX - LZMA_VLI_VALUE_UNKNOWN -> LZMA_VLI_UNKNOWN - LZMA_HEADER_ERRRO -> LZMA_OPTIONS_ERROR --- src/liblzma/common/alignment.c | 6 +++--- src/liblzma/common/alone_decoder.c | 2 +- src/liblzma/common/auto_decoder.c | 2 +- src/liblzma/common/block_decoder.c | 12 ++++++------ src/liblzma/common/block_encoder.c | 6 +++--- src/liblzma/common/block_header_decoder.c | 16 ++++++++-------- src/liblzma/common/block_header_encoder.c | 24 ++++++++++++------------ src/liblzma/common/block_util.c | 8 ++++---- src/liblzma/common/chunk_size.c | 2 +- src/liblzma/common/easy.c | 4 ++-- src/liblzma/common/filter_common.c | 22 +++++++++++----------- src/liblzma/common/filter_decoder.c | 6 +++--- src/liblzma/common/filter_encoder.c | 14 +++++++------- src/liblzma/common/index.c | 24 +++++++++++------------- src/liblzma/common/index.h | 2 +- src/liblzma/common/index_hash.c | 13 ++++++------- src/liblzma/common/stream_decoder.c | 4 ++-- src/liblzma/common/stream_encoder.c | 4 ++-- src/liblzma/common/stream_flags_common.c | 6 +++--- src/liblzma/common/stream_flags_decoder.c | 6 +++--- src/liblzma/common/stream_flags_encoder.c | 4 ++-- src/liblzma/common/vli_encoder.c | 2 +- src/liblzma/common/vli_size.c | 2 +- 23 files changed, 94 insertions(+), 97 deletions(-) (limited to 'src/liblzma/common') diff --git a/src/liblzma/common/alignment.c b/src/liblzma/common/alignment.c index ba9ecb03..cfd515e6 100644 --- a/src/liblzma/common/alignment.c +++ b/src/liblzma/common/alignment.c @@ -23,7 +23,7 @@ extern LZMA_API uint32_t lzma_alignment_input(const lzma_filter *filters, uint32_t guess) { - for (size_t i = 0; filters[i].id != LZMA_VLI_VALUE_UNKNOWN; ++i) { + for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) { switch (filters[i].id) { case LZMA_FILTER_DELTA: // The same as the input, check the next filter. @@ -68,12 +68,12 @@ lzma_alignment_input(const lzma_filter *filters, uint32_t guess) extern LZMA_API uint32_t lzma_alignment_output(const lzma_filter *filters, uint32_t guess) { - if (filters[0].id == LZMA_VLI_VALUE_UNKNOWN) + if (filters[0].id == LZMA_VLI_UNKNOWN) return UINT32_MAX; // Find the last filter in the chain. size_t i = 0; - while (filters[i + 1].id != LZMA_VLI_VALUE_UNKNOWN) + while (filters[i + 1].id != LZMA_VLI_UNKNOWN) ++i; do { diff --git a/src/liblzma/common/alone_decoder.c b/src/liblzma/common/alone_decoder.c index 4c76ae71..45cb54e5 100644 --- a/src/liblzma/common/alone_decoder.c +++ b/src/liblzma/common/alone_decoder.c @@ -108,7 +108,7 @@ alone_decode(lzma_coder *coder, // if the uncompressed size is known, it must be less // than 256 GiB. Again, if someone complains, this // will be reconsidered. - if (coder->uncompressed_size != LZMA_VLI_VALUE_UNKNOWN + if (coder->uncompressed_size != LZMA_VLI_UNKNOWN && coder->uncompressed_size >= (LZMA_VLI_C(1) << 38)) return LZMA_FORMAT_ERROR; diff --git a/src/liblzma/common/auto_decoder.c b/src/liblzma/common/auto_decoder.c index 4272dadf..05a9fbb4 100644 --- a/src/liblzma/common/auto_decoder.c +++ b/src/liblzma/common/auto_decoder.c @@ -131,7 +131,7 @@ auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator, lzma_next_coder_init(auto_decoder_init, next, allocator); if (flags & ~LZMA_SUPPORTED_FLAGS) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; if (next->coder == NULL) { next->coder = lzma_alloc(sizeof(lzma_coder), allocator); diff --git a/src/liblzma/common/block_decoder.c b/src/liblzma/common/block_decoder.c index 9eb33651..f9101c7d 100644 --- a/src/liblzma/common/block_decoder.c +++ b/src/liblzma/common/block_decoder.c @@ -58,8 +58,8 @@ struct lzma_coder_s { static inline bool update_size(lzma_vli *size, lzma_vli add, lzma_vli limit) { - if (limit > LZMA_VLI_VALUE_MAX) - limit = LZMA_VLI_VALUE_MAX; + if (limit > LZMA_VLI_MAX) + limit = LZMA_VLI_MAX; if (limit < *size || limit - *size < add) return true; @@ -73,7 +73,7 @@ update_size(lzma_vli *size, lzma_vli add, lzma_vli limit) static inline bool is_size_valid(lzma_vli size, lzma_vli reference) { - return reference == LZMA_VLI_VALUE_UNKNOWN || reference == size; + return reference == LZMA_VLI_UNKNOWN || reference == size; } @@ -96,7 +96,7 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator, const size_t out_used = *out_pos - out_start; // NOTE: We compare to compressed_limit here, which prevents - // the total size of the Block growing past LZMA_VLI_VALUE_MAX. + // the total size of the Block growing past LZMA_VLI_MAX. if (update_size(&coder->compressed_size, in_used, coder->compressed_limit) || update_size(&coder->uncompressed_size, @@ -224,8 +224,8 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator, // value so that Total Size of the Block still is a valid VLI and // a multiple of four. next->coder->compressed_limit - = options->compressed_size == LZMA_VLI_VALUE_UNKNOWN - ? (LZMA_VLI_VALUE_MAX & ~LZMA_VLI_C(3)) + = options->compressed_size == LZMA_VLI_UNKNOWN + ? (LZMA_VLI_MAX & ~LZMA_VLI_C(3)) - options->header_size - lzma_check_size(options->check) : options->compressed_size; diff --git a/src/liblzma/common/block_encoder.c b/src/liblzma/common/block_encoder.c index 7dffbb82..3c678f7d 100644 --- a/src/liblzma/common/block_encoder.c +++ b/src/liblzma/common/block_encoder.c @@ -23,7 +23,7 @@ /// The maximum size of a single Block is limited by the maximum size of -/// a Stream, which is 2^63 - 1 bytes (i.e. LZMA_VLI_VALUE_MAX). We could +/// a Stream, which is 2^63 - 1 bytes (i.e. LZMA_VLI_MAX). We could /// take into account the headers etc. to determine the exact maximum size /// of the Compressed Data field, but the complexity would give us nothing /// useful. Instead, limit the size of Compressed Data so that even with @@ -33,7 +33,7 @@ /// /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of /// the Compressed Data field, it will still stay in the proper limit. -#define COMPRESSED_SIZE_MAX ((LZMA_VLI_VALUE_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \ +#define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \ - LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3)) @@ -73,7 +73,7 @@ block_encode(lzma_coder *coder, lzma_allocator *allocator, size_t *restrict out_pos, size_t out_size, lzma_action action) { // Check that our amount of input stays in proper limits. - if (LZMA_VLI_VALUE_MAX - coder->uncompressed_size < in_size - *in_pos) + if (LZMA_VLI_MAX - coder->uncompressed_size < in_size - *in_pos) return LZMA_PROG_ERROR; switch (coder->sequence) { diff --git a/src/liblzma/common/block_header_decoder.c b/src/liblzma/common/block_header_decoder.c index 1d75f335..3b8e9f36 100644 --- a/src/liblzma/common/block_header_decoder.c +++ b/src/liblzma/common/block_header_decoder.c @@ -29,7 +29,7 @@ free_properties(lzma_block *options, lzma_allocator *allocator) // lzma_block_header_decode(), so we don't need to touch that here. for (size_t i = 0; i < LZMA_BLOCK_FILTERS_MAX; ++i) { lzma_free(options->filters[i].options, allocator); - options->filters[i].id = LZMA_VLI_VALUE_UNKNOWN; + options->filters[i].id = LZMA_VLI_UNKNOWN; options->filters[i].options = NULL; } @@ -49,7 +49,7 @@ 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_BLOCK_FILTERS_MAX; ++i) { - options->filters[i].id = LZMA_VLI_VALUE_UNKNOWN; + options->filters[i].id = LZMA_VLI_UNKNOWN; options->filters[i].options = NULL; } @@ -73,7 +73,7 @@ lzma_block_header_decode(lzma_block *options, // Check for unsupported flags. if (in[1] & 0x3C) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Start after the Block Header Size and Block Flags fields. size_t in_pos = 2; @@ -83,7 +83,7 @@ lzma_block_header_decode(lzma_block *options, return_if_error(lzma_vli_decode(&options->compressed_size, NULL, in, &in_pos, in_size)); - if (options->compressed_size > LZMA_VLI_VALUE_MAX / 4 - 1) + if (options->compressed_size > LZMA_VLI_MAX / 4 - 1) return LZMA_DATA_ERROR; options->compressed_size = (options->compressed_size + 1) * 4; @@ -94,7 +94,7 @@ lzma_block_header_decode(lzma_block *options, if (lzma_block_total_size_get(options) == 0) return LZMA_DATA_ERROR; } else { - options->compressed_size = LZMA_VLI_VALUE_UNKNOWN; + options->compressed_size = LZMA_VLI_UNKNOWN; } // Uncompressed Size @@ -102,7 +102,7 @@ lzma_block_header_decode(lzma_block *options, return_if_error(lzma_vli_decode(&options->uncompressed_size, NULL, in, &in_pos, in_size)); else - options->uncompressed_size = LZMA_VLI_VALUE_UNKNOWN; + options->uncompressed_size = LZMA_VLI_UNKNOWN; // Filter Flags const size_t filter_count = (in[1] & 3) + 1; @@ -122,8 +122,8 @@ lzma_block_header_decode(lzma_block *options, free_properties(options, allocator); // Possibly some new field present so use - // LZMA_HEADER_ERROR instead of LZMA_DATA_ERROR. - return LZMA_HEADER_ERROR; + // LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR. + return LZMA_OPTIONS_ERROR; } } diff --git a/src/liblzma/common/block_header_encoder.c b/src/liblzma/common/block_header_encoder.c index 3a16e6c3..9326350b 100644 --- a/src/liblzma/common/block_header_encoder.c +++ b/src/liblzma/common/block_header_encoder.c @@ -28,8 +28,8 @@ lzma_block_header_size(lzma_block *options) size_t size = 1 + 1 + 4; // Compressed Size - if (options->compressed_size != LZMA_VLI_VALUE_UNKNOWN) { - if (options->compressed_size > LZMA_VLI_VALUE_MAX / 4 - 1 + if (options->compressed_size != LZMA_VLI_UNKNOWN) { + if (options->compressed_size > LZMA_VLI_MAX / 4 - 1 || options->compressed_size == 0 || (options->compressed_size & 3)) return LZMA_PROG_ERROR; @@ -38,7 +38,7 @@ lzma_block_header_size(lzma_block *options) } // Uncompressed Size - if (options->uncompressed_size != LZMA_VLI_VALUE_UNKNOWN) { + if (options->uncompressed_size != LZMA_VLI_UNKNOWN) { const size_t add = lzma_vli_size(options->uncompressed_size); if (add == 0) return LZMA_PROG_ERROR; @@ -48,10 +48,10 @@ lzma_block_header_size(lzma_block *options) // List of Filter Flags if (options->filters == NULL - || options->filters[0].id == LZMA_VLI_VALUE_UNKNOWN) + || options->filters[0].id == LZMA_VLI_UNKNOWN) return LZMA_PROG_ERROR; - for (size_t i = 0; options->filters[i].id != LZMA_VLI_VALUE_UNKNOWN; + for (size_t i = 0; options->filters[i].id != LZMA_VLI_UNKNOWN; ++i) { // Don't allow too many filters. if (i == 4) @@ -94,14 +94,14 @@ lzma_block_header_encode(const lzma_block *options, uint8_t *out) size_t out_pos = 2; // Compressed Size - if (options->compressed_size != LZMA_VLI_VALUE_UNKNOWN) { + if (options->compressed_size != LZMA_VLI_UNKNOWN) { // Compressed Size must be non-zero, fit into a 63-bit // integer and be a multiple of four. Also the Total Size // of the Block must fit into 63-bit integer. if (options->compressed_size == 0 || (options->compressed_size & 3) || options->compressed_size - > LZMA_VLI_VALUE_MAX + > LZMA_VLI_MAX || lzma_block_total_size_get(options) == 0) return LZMA_PROG_ERROR; @@ -111,14 +111,14 @@ lzma_block_header_encode(const lzma_block *options, uint8_t *out) } // Uncompressed Size - if (options->uncompressed_size != LZMA_VLI_VALUE_UNKNOWN) + if (options->uncompressed_size != LZMA_VLI_UNKNOWN) return_if_error(lzma_vli_encode( options->uncompressed_size, NULL, out, &out_pos, out_size)); // Filter Flags if (options->filters == NULL - || options->filters[0].id == LZMA_VLI_VALUE_UNKNOWN) + || options->filters[0].id == LZMA_VLI_UNKNOWN) return LZMA_PROG_ERROR; size_t filter_count = 0; @@ -132,15 +132,15 @@ lzma_block_header_encode(const lzma_block *options, uint8_t *out) out, &out_pos, out_size)); } while (options->filters[++filter_count].id - != LZMA_VLI_VALUE_UNKNOWN); + != LZMA_VLI_UNKNOWN); // Block Flags out[1] = filter_count - 1; - if (options->compressed_size != LZMA_VLI_VALUE_UNKNOWN) + if (options->compressed_size != LZMA_VLI_UNKNOWN) out[1] |= 0x40; - if (options->uncompressed_size != LZMA_VLI_VALUE_UNKNOWN) + if (options->uncompressed_size != LZMA_VLI_UNKNOWN) out[1] |= 0x80; // Padding diff --git a/src/liblzma/common/block_util.c b/src/liblzma/common/block_util.c index 798163bb..7b46ba32 100644 --- a/src/liblzma/common/block_util.c +++ b/src/liblzma/common/block_util.c @@ -56,17 +56,17 @@ lzma_block_total_size_get(const lzma_block *options) // If Compressed Size is unknown, return that we cannot know // Total Size either. - if (options->compressed_size == LZMA_VLI_VALUE_UNKNOWN) - return LZMA_VLI_VALUE_UNKNOWN; + if (options->compressed_size == LZMA_VLI_UNKNOWN) + return LZMA_VLI_UNKNOWN; const lzma_vli total_size = options->compressed_size + options->header_size + lzma_check_size(options->check); // Validate the calculated Total Size. - if (options->compressed_size > LZMA_VLI_VALUE_MAX + if (options->compressed_size > LZMA_VLI_MAX || (options->compressed_size & 3) - || total_size > LZMA_VLI_VALUE_MAX) + || total_size > LZMA_VLI_MAX) return 0; return total_size; diff --git a/src/liblzma/common/chunk_size.c b/src/liblzma/common/chunk_size.c index 042201d2..74d4a6f4 100644 --- a/src/liblzma/common/chunk_size.c +++ b/src/liblzma/common/chunk_size.c @@ -39,7 +39,7 @@ extern LZMA_API size_t lzma_chunk_size(const lzma_options_filter *filters) { - while (filters->id != LZMA_VLI_VALUE_UNKNOWN) { + while (filters->id != LZMA_VLI_UNKNOWN) { switch (filters->id) { // TODO LZMA_FILTER_SPARSE diff --git a/src/liblzma/common/easy.c b/src/liblzma/common/easy.c index 6f6dc0fa..7446bc79 100644 --- a/src/liblzma/common/easy.c +++ b/src/liblzma/common/easy.c @@ -42,7 +42,7 @@ easy_set_filters(lzma_filter *filters, uint32_t level) } else if (level <= 9) { filters[0].id = LZMA_FILTER_LZMA2; filters[0].options = (void *)(&lzma_preset_lzma[level - 1]); - filters[1].id = LZMA_VLI_VALUE_UNKNOWN; + filters[1].id = LZMA_VLI_UNKNOWN; #endif } else { @@ -92,7 +92,7 @@ easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, } if (easy_set_filters(next->coder->filters, level)) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; return lzma_stream_encoder_init(&next->coder->stream_encoder, allocator, next->coder->filters, LZMA_CHECK_CRC32); diff --git a/src/liblzma/common/filter_common.c b/src/liblzma/common/filter_common.c index 886ddb53..7097ce51 100644 --- a/src/liblzma/common/filter_common.c +++ b/src/liblzma/common/filter_common.c @@ -119,7 +119,7 @@ static const struct { }, #endif { - .id = LZMA_VLI_VALUE_UNKNOWN + .id = LZMA_VLI_UNKNOWN } }; @@ -128,7 +128,7 @@ static lzma_ret validate_chain(const lzma_filter *filters, size_t *count) { // There must be at least one filter. - if (filters == NULL || filters[0].id == LZMA_VLI_VALUE_UNKNOWN) + if (filters == NULL || filters[0].id == LZMA_VLI_UNKNOWN) return LZMA_PROG_ERROR; // Number of non-last filters that may change the size of the data @@ -147,25 +147,25 @@ validate_chain(const lzma_filter *filters, size_t *count) do { size_t j; for (j = 0; filters[i].id != features[j].id; ++j) - if (features[j].id == LZMA_VLI_VALUE_UNKNOWN) - return LZMA_HEADER_ERROR; + if (features[j].id == LZMA_VLI_UNKNOWN) + return LZMA_OPTIONS_ERROR; // If the previous filter in the chain cannot be a non-last // filter, the chain is invalid. if (!non_last_ok) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; non_last_ok = features[j].non_last_ok; last_ok = features[j].last_ok; changes_size_count += features[j].changes_size; - } while (filters[++i].id != LZMA_VLI_VALUE_UNKNOWN); + } while (filters[++i].id != LZMA_VLI_UNKNOWN); // There must be 1-4 filters. The last filter must be usable as // the last filter in the chain. At maximum of three filters are // allowed to change the size of the data. if (i > LZMA_BLOCK_FILTERS_MAX || !last_ok || changes_size_count > 3) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; *count = i; return LZMA_OK; @@ -193,7 +193,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_coder *const fc = coder_find(options[i].id); if (fc == NULL || fc->init == NULL) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; filters[j].init = fc->init; filters[j].options = options[i].options; @@ -203,7 +203,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_coder *const fc = coder_find(options[i].id); if (fc == NULL || fc->init == NULL) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; filters[i].init = fc->init; filters[i].options = options[i].options; @@ -227,7 +227,7 @@ lzma_memusage_coder(lzma_filter_find coder_find, const lzma_filter *filters) { // The chain has to have at least one filter. - if (filters[0].id == LZMA_VLI_VALUE_UNKNOWN) + if (filters[0].id == LZMA_VLI_UNKNOWN) return UINT64_MAX; uint64_t total = 0; @@ -254,7 +254,7 @@ lzma_memusage_coder(lzma_filter_find coder_find, total += usage; } - } while (filters[++i].id != LZMA_VLI_VALUE_UNKNOWN); + } while (filters[++i].id != LZMA_VLI_UNKNOWN); // Add some fixed amount of extra. It's to compensate memory usage // of Stream, Block etc. coders, malloc() overhead, stack etc. diff --git a/src/liblzma/common/filter_decoder.c b/src/liblzma/common/filter_decoder.c index fb5632e8..8b7e532f 100644 --- a/src/liblzma/common/filter_decoder.c +++ b/src/liblzma/common/filter_decoder.c @@ -42,7 +42,7 @@ typedef struct { /// Decodes Filter Properties. /// /// \return - LZMA_OK: Properties decoded successfully. - /// - LZMA_HEADER_ERROR: Unsupported properties + /// - LZMA_OPTIONS_ERROR: Unsupported properties /// - LZMA_MEM_ERROR: Memory allocation failed. lzma_ret (*props_decode)(void **options, lzma_allocator *allocator, const uint8_t *props, size_t props_size); @@ -196,10 +196,10 @@ lzma_properties_decode(lzma_filter *filter, lzma_allocator *allocator, const lzma_filter_decoder *const fd = decoder_find(filter->id); if (fd == NULL) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; if (fd->props_decode == NULL) - return props_size == 0 ? LZMA_OK : LZMA_HEADER_ERROR; + return props_size == 0 ? LZMA_OK : LZMA_OPTIONS_ERROR; return fd->props_decode( &filter->options, allocator, props, props_size); diff --git a/src/liblzma/common/filter_encoder.c b/src/liblzma/common/filter_encoder.c index 8f2c517f..550d5483 100644 --- a/src/liblzma/common/filter_encoder.c +++ b/src/liblzma/common/filter_encoder.c @@ -53,7 +53,7 @@ typedef struct { /// Encodes Filter Properties. /// /// \return - LZMA_OK: Properties encoded sucessfully. - /// - LZMA_HEADER_ERROR: Unsupported options + /// - LZMA_OPTIONS_ERROR: Unsupported options /// - LZMA_PROG_ERROR: Invalid options or not enough /// output space lzma_ret (*props_encode)(const void *options, uint8_t *out); @@ -223,14 +223,14 @@ lzma_chunk_size(const lzma_filter *filters) { lzma_vli max = 0; - for (size_t i = 0; filters[i].id != LZMA_VLI_VALUE_UNKNOWN; ++i) { + for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) { const lzma_filter_encoder *const fe = encoder_find(filters[i].id); if (fe->chunk_size != NULL) { const lzma_vli size = fe->chunk_size(filters[i].options); - if (size == LZMA_VLI_VALUE_UNKNOWN) - return LZMA_VLI_VALUE_UNKNOWN; + if (size == LZMA_VLI_UNKNOWN) + return LZMA_VLI_UNKNOWN; if (size > max) max = size; @@ -247,11 +247,11 @@ lzma_properties_size(uint32_t *size, const lzma_filter *filter) const lzma_filter_encoder *const fe = encoder_find(filter->id); if (fe == NULL) { // Unknown filter - if the Filter ID is a proper VLI, - // return LZMA_HEADER_ERROR instead of LZMA_PROG_ERROR, + // return LZMA_OPTIONS_ERROR instead of LZMA_PROG_ERROR, // because it's possible that we just don't have support // compiled in for the requested filter. - return filter->id <= LZMA_VLI_VALUE_MAX - ? LZMA_HEADER_ERROR : LZMA_PROG_ERROR; + return filter->id <= LZMA_VLI_MAX + ? LZMA_OPTIONS_ERROR : LZMA_PROG_ERROR; } if (fe->props_size_get == NULL) { diff --git a/src/liblzma/common/index.c b/src/liblzma/common/index.c index f01206de..f965749f 100644 --- a/src/liblzma/common/index.c +++ b/src/liblzma/common/index.c @@ -270,8 +270,8 @@ static lzma_ret index_append(lzma_index *i, lzma_allocator *allocator, lzma_vli total_size, lzma_vli uncompressed_size, bool is_padding) { - if (total_size > LZMA_VLI_VALUE_MAX - || uncompressed_size > LZMA_VLI_VALUE_MAX) + if (total_size > LZMA_VLI_MAX + || uncompressed_size > LZMA_VLI_MAX) return LZMA_DATA_ERROR; // This looks a bit ugly. We want to first validate that the Index @@ -286,9 +286,8 @@ index_append(lzma_index *i, lzma_allocator *allocator, lzma_vli total_size, // First update the info so we can validate it. i->padding_size += total_size; - if (i->padding_size > LZMA_VLI_VALUE_MAX - || lzma_index_file_size(i) - > LZMA_VLI_VALUE_MAX) + if (i->padding_size > LZMA_VLI_MAX + || lzma_index_file_size(i) > LZMA_VLI_MAX) ret = LZMA_DATA_ERROR; // Would grow past the limits. else ret = index_append_real(i, allocator, @@ -309,11 +308,10 @@ index_append(lzma_index *i, lzma_allocator *allocator, lzma_vli total_size, ++i->count; i->index_list_size += index_list_size_add; - if (i->total_size > LZMA_VLI_VALUE_MAX - || i->uncompressed_size > LZMA_VLI_VALUE_MAX + if (i->total_size > LZMA_VLI_MAX + || i->uncompressed_size > LZMA_VLI_MAX || lzma_index_size(i) > LZMA_BACKWARD_SIZE_MAX - || lzma_index_file_size(i) - > LZMA_VLI_VALUE_MAX) + || lzma_index_file_size(i) > LZMA_VLI_MAX) ret = LZMA_DATA_ERROR; // Would grow past the limits. else ret = index_append_real(i, allocator, @@ -545,16 +543,16 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src, lzma_allocator *allocator, lzma_vli padding) { if (dest == NULL || src == NULL || dest == src - || padding > LZMA_VLI_VALUE_MAX) + || padding > LZMA_VLI_MAX) return LZMA_PROG_ERROR; // Check that the combined size of the Indexes stays within limits. { const lzma_vli dest_size = lzma_index_file_size(dest); const lzma_vli src_size = lzma_index_file_size(src); - if (dest_size + src_size > LZMA_VLI_VALUE_UNKNOWN + if (dest_size + src_size > LZMA_VLI_UNKNOWN || dest_size + src_size + padding - > LZMA_VLI_VALUE_UNKNOWN) + > LZMA_VLI_UNKNOWN) return LZMA_DATA_ERROR; } @@ -562,7 +560,7 @@ lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src, // Index + Stream Footer + Stream Padding + Stream Header. // // NOTE: This cannot overflow, because Index Size is always - // far smaller than LZMA_VLI_VALUE_MAX, and adding two VLIs + // far smaller than LZMA_VLI_MAX, and adding two VLIs // (Index Size and padding) doesn't overflow. It may become // an invalid VLI if padding is huge, but that is caught by // index_append(). diff --git a/src/liblzma/common/index.h b/src/liblzma/common/index.h index 303ad43a..df897367 100644 --- a/src/liblzma/common/index.h +++ b/src/liblzma/common/index.h @@ -24,7 +24,7 @@ /// Maximum encoded value of Total Size. -#define TOTAL_SIZE_ENCODED_MAX (LZMA_VLI_VALUE_MAX / 4 - 1) +#define TOTAL_SIZE_ENCODED_MAX (LZMA_VLI_MAX / 4 - 1) /// Convert the real Total Size value to a value that is stored to the Index. #define total_size_encode(size) ((size) / 4 - 1) diff --git a/src/liblzma/common/index_hash.c b/src/liblzma/common/index_hash.c index dc533f9e..5e581838 100644 --- a/src/liblzma/common/index_hash.c +++ b/src/liblzma/common/index_hash.c @@ -150,9 +150,9 @@ lzma_index_hash_append(lzma_index_hash *index_hash, lzma_vli total_size, lzma_vli uncompressed_size) { // Validate the arguments. - if (index_hash->sequence != SEQ_BLOCK || total_size == 0 || - total_size > LZMA_VLI_VALUE_MAX || (total_size & 3) - || uncompressed_size > LZMA_VLI_VALUE_MAX) + if (index_hash->sequence != SEQ_BLOCK || total_size == 0 + || total_size > LZMA_VLI_MAX || (total_size & 3) + || uncompressed_size > LZMA_VLI_MAX) return LZMA_PROG_ERROR; // Update the hash. @@ -160,16 +160,15 @@ lzma_index_hash_append(lzma_index_hash *index_hash, lzma_vli total_size, total_size, uncompressed_size)); // Validate the properties of *info are still in allowed limits. - if (index_hash->blocks.total_size > LZMA_VLI_VALUE_MAX - || index_hash->blocks.uncompressed_size - > LZMA_VLI_VALUE_MAX + if (index_hash->blocks.total_size > LZMA_VLI_MAX + || index_hash->blocks.uncompressed_size > LZMA_VLI_MAX || index_size(index_hash->blocks.count, index_hash->blocks.index_list_size) > LZMA_BACKWARD_SIZE_MAX || index_stream_size(index_hash->blocks.total_size, index_hash->blocks.count, index_hash->blocks.index_list_size) - > LZMA_VLI_VALUE_MAX) + > LZMA_VLI_MAX) return LZMA_DATA_ERROR; return LZMA_OK; diff --git a/src/liblzma/common/stream_decoder.c b/src/liblzma/common/stream_decoder.c index 5360d87c..95bb3ada 100644 --- a/src/liblzma/common/stream_decoder.c +++ b/src/liblzma/common/stream_decoder.c @@ -198,7 +198,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator, if (memusage == UINT64_MAX) { // One or more unknown Filter IDs. - ret = LZMA_HEADER_ERROR; + ret = LZMA_OPTIONS_ERROR; } else if (memusage > coder->memlimit) { // The chain would need too much memory. ret = LZMA_MEMLIMIT_ERROR; @@ -375,7 +375,7 @@ lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator, lzma_next_coder_init(lzma_stream_decoder_init, next, allocator); if (flags & ~LZMA_SUPPORTED_FLAGS) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; if (next->coder == NULL) { next->coder = lzma_alloc(sizeof(lzma_coder), allocator); diff --git a/src/liblzma/common/stream_encoder.c b/src/liblzma/common/stream_encoder.c index 8748f52e..0376fd3b 100644 --- a/src/liblzma/common/stream_encoder.c +++ b/src/liblzma/common/stream_encoder.c @@ -66,8 +66,8 @@ block_encoder_init(lzma_coder *coder, lzma_allocator *allocator) // initialized, it is a good idea to do it here, because this way // we catch if someone gave us Filter ID that cannot be used in // Blocks/Streams. - coder->block_options.compressed_size = LZMA_VLI_VALUE_UNKNOWN; - coder->block_options.uncompressed_size = LZMA_VLI_VALUE_UNKNOWN; + coder->block_options.compressed_size = LZMA_VLI_UNKNOWN; + coder->block_options.uncompressed_size = LZMA_VLI_UNKNOWN; return_if_error(lzma_block_header_size(&coder->block_options)); diff --git a/src/liblzma/common/stream_flags_common.c b/src/liblzma/common/stream_flags_common.c index aaa9fe02..1f7220ec 100644 --- a/src/liblzma/common/stream_flags_common.c +++ b/src/liblzma/common/stream_flags_common.c @@ -30,7 +30,7 @@ lzma_stream_flags_compare( { // We can compare only version 0 structures. if (a->version != 0 || b->version != 0) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Check type if ((unsigned int)(a->check) > LZMA_CHECK_ID_MAX @@ -41,8 +41,8 @@ lzma_stream_flags_compare( return LZMA_DATA_ERROR; // Backward Sizes are compared only if they are known in both. - if (a->backward_size != LZMA_VLI_VALUE_UNKNOWN - && b->backward_size != LZMA_VLI_VALUE_UNKNOWN) { + if (a->backward_size != LZMA_VLI_UNKNOWN + && b->backward_size != LZMA_VLI_UNKNOWN) { if (!is_backward_size_valid(a) || !is_backward_size_valid(b)) return LZMA_PROG_ERROR; diff --git a/src/liblzma/common/stream_flags_decoder.c b/src/liblzma/common/stream_flags_decoder.c index a54ce813..48379e53 100644 --- a/src/liblzma/common/stream_flags_decoder.c +++ b/src/liblzma/common/stream_flags_decoder.c @@ -51,13 +51,13 @@ lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in) // Stream Flags if (stream_flags_decode(options, in + sizeof(lzma_header_magic))) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Set Backward Size to indicate unknown value. That way // lzma_stream_flags_compare() can be used to compare Stream Header // and Stream Footer while keeping it useful also for comparing // two Stream Footers. - options->backward_size = LZMA_VLI_VALUE_UNKNOWN; + options->backward_size = LZMA_VLI_UNKNOWN; return LZMA_OK; } @@ -79,7 +79,7 @@ lzma_stream_footer_decode(lzma_stream_flags *options, const uint8_t *in) // Stream Flags if (stream_flags_decode(options, in + sizeof(uint32_t) * 2)) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Backward Size options->backward_size = integer_read_32(in + sizeof(uint32_t)); diff --git a/src/liblzma/common/stream_flags_encoder.c b/src/liblzma/common/stream_flags_encoder.c index 88ed81e0..e73a5133 100644 --- a/src/liblzma/common/stream_flags_encoder.c +++ b/src/liblzma/common/stream_flags_encoder.c @@ -40,7 +40,7 @@ lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out) + 4 == LZMA_STREAM_HEADER_SIZE); if (options->version != 0) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Magic memcpy(out, lzma_header_magic, sizeof(lzma_header_magic)); @@ -67,7 +67,7 @@ lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out) == LZMA_STREAM_HEADER_SIZE); if (options->version != 0) - return LZMA_HEADER_ERROR; + return LZMA_OPTIONS_ERROR; // Backward Size if (!is_backward_size_valid(options)) diff --git a/src/liblzma/common/vli_encoder.c b/src/liblzma/common/vli_encoder.c index 53022f16..4bb4d351 100644 --- a/src/liblzma/common/vli_encoder.c +++ b/src/liblzma/common/vli_encoder.c @@ -31,7 +31,7 @@ lzma_vli_encode(lzma_vli vli, size_t *restrict vli_pos, vli_pos = &vli_pos_internal; // Validate the arguments. - if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_VALUE_MAX) + if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_MAX) return LZMA_PROG_ERROR; if (*out_pos >= out_size) diff --git a/src/liblzma/common/vli_size.c b/src/liblzma/common/vli_size.c index 547bba0b..e87094d8 100644 --- a/src/liblzma/common/vli_size.c +++ b/src/liblzma/common/vli_size.c @@ -23,7 +23,7 @@ extern LZMA_API uint32_t lzma_vli_size(lzma_vli vli) { - if (vli > LZMA_VLI_VALUE_MAX) + if (vli > LZMA_VLI_MAX) return 0; uint32_t i = 0; -- cgit v1.2.3