mirror of https://git.tukaani.org/xz.git
Fix Size of Header Metadata Block handling. Now
lzma_metadata.header_metadata_size == LZMA_VLI_VALUE_UNKNOWN is not allowed at all. To indicate missing Header Metadata Block, header_metadata_size must be set to zero. This is what Metadata decoder does after this patch too. Note that other missing fields in lzma_metadata are still indicated with LZMA_VLI_VALUE_UNKNOWN. This isn't as illogical as it sounds at first, because missing Size of Header Metadata Block means that Header Metadata Block is not present in the Stream. With other Metadata fields, a missing field means only that the value is unknown.
This commit is contained in:
parent
58b78ab20c
commit
99e12af4e2
|
@ -367,7 +367,7 @@ lzma_info_metadata_set(lzma_info *info, lzma_allocator *allocator,
|
||||||
lzma_bool eat_index)
|
lzma_bool eat_index)
|
||||||
{
|
{
|
||||||
// Validate *metadata.
|
// Validate *metadata.
|
||||||
if (!lzma_vli_is_valid(metadata->header_metadata_size)
|
if (metadata->header_metadata_size > LZMA_VLI_VALUE_MAX
|
||||||
|| !lzma_vli_is_valid(metadata->total_size)
|
|| !lzma_vli_is_valid(metadata->total_size)
|
||||||
|| !lzma_vli_is_valid(metadata->uncompressed_size)) {
|
|| !lzma_vli_is_valid(metadata->uncompressed_size)) {
|
||||||
if (eat_index) {
|
if (eat_index) {
|
||||||
|
@ -403,15 +403,10 @@ lzma_info_metadata_set(lzma_info *info, lzma_allocator *allocator,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size of Header Metadata
|
// Size of Header Metadata
|
||||||
if (!is_header_metadata) {
|
if (!is_header_metadata)
|
||||||
// If it is marked unknown in Metadata, it means that
|
|
||||||
// it's not present.
|
|
||||||
const lzma_vli size = metadata->header_metadata_size
|
|
||||||
!= LZMA_VLI_VALUE_UNKNOWN
|
|
||||||
? metadata->header_metadata_size : 0;
|
|
||||||
return_if_error(lzma_info_size_set(
|
return_if_error(lzma_info_size_set(
|
||||||
info, LZMA_INFO_HEADER_METADATA, size));
|
info, LZMA_INFO_HEADER_METADATA,
|
||||||
}
|
metadata->header_metadata_size));
|
||||||
|
|
||||||
// Total Size
|
// Total Size
|
||||||
if (metadata->total_size != LZMA_VLI_VALUE_UNKNOWN)
|
if (metadata->total_size != LZMA_VLI_VALUE_UNKNOWN)
|
||||||
|
|
|
@ -169,6 +169,12 @@ process(lzma_coder *coder, lzma_allocator *allocator)
|
||||||
return LZMA_DATA_ERROR;
|
return LZMA_DATA_ERROR;
|
||||||
|
|
||||||
--coder->todo_count;
|
--coder->todo_count;
|
||||||
|
} else {
|
||||||
|
// Zero indicates that Size of Header Metadata Block
|
||||||
|
// is not present. That is, after successful Metadata
|
||||||
|
// decoding, metadata->header_metadata_size is
|
||||||
|
// never LZMA_VLI_VALUE_UNKNOWN.
|
||||||
|
coder->metadata->header_metadata_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
coder->sequence = SEQ_TOTAL_SIZE;
|
coder->sequence = SEQ_TOTAL_SIZE;
|
||||||
|
|
|
@ -87,8 +87,7 @@ process(lzma_coder *coder)
|
||||||
case SEQ_FLAGS:
|
case SEQ_FLAGS:
|
||||||
coder->buffer[coder->buffer_size] = 0;
|
coder->buffer[coder->buffer_size] = 0;
|
||||||
|
|
||||||
if (coder->metadata.header_metadata_size
|
if (coder->metadata.header_metadata_size != 0)
|
||||||
!= LZMA_VLI_VALUE_UNKNOWN)
|
|
||||||
coder->buffer[coder->buffer_size] |= 0x01;
|
coder->buffer[coder->buffer_size] |= 0x01;
|
||||||
|
|
||||||
if (coder->metadata.total_size != LZMA_VLI_VALUE_UNKNOWN)
|
if (coder->metadata.total_size != LZMA_VLI_VALUE_UNKNOWN)
|
||||||
|
@ -109,8 +108,7 @@ process(lzma_coder *coder)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEQ_HEADER_METADATA_SIZE:
|
case SEQ_HEADER_METADATA_SIZE:
|
||||||
if (coder->metadata.header_metadata_size
|
if (coder->metadata.header_metadata_size != 0)
|
||||||
!= LZMA_VLI_VALUE_UNKNOWN)
|
|
||||||
write_vli(coder->metadata.header_metadata_size);
|
write_vli(coder->metadata.header_metadata_size);
|
||||||
|
|
||||||
coder->sequence = SEQ_TOTAL_SIZE;
|
coder->sequence = SEQ_TOTAL_SIZE;
|
||||||
|
@ -373,13 +371,14 @@ lzma_metadata_size(const lzma_metadata *metadata)
|
||||||
lzma_vli size = 1; // Metadata Flags
|
lzma_vli size = 1; // Metadata Flags
|
||||||
|
|
||||||
// Validate header_metadata_size, total_size, and uncompressed_size.
|
// Validate header_metadata_size, total_size, and uncompressed_size.
|
||||||
if (!lzma_vli_is_valid(metadata->header_metadata_size)
|
if (metadata->header_metadata_size > LZMA_VLI_VALUE_MAX
|
||||||
|| !lzma_vli_is_valid(metadata->total_size)
|
|| !lzma_vli_is_valid(metadata->total_size)
|
||||||
|
|| metadata->total_size == 0
|
||||||
|| !lzma_vli_is_valid(metadata->uncompressed_size))
|
|| !lzma_vli_is_valid(metadata->uncompressed_size))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Add the sizes of these three fields.
|
// Add the sizes of these three fields.
|
||||||
if (metadata->header_metadata_size != LZMA_VLI_VALUE_UNKNOWN)
|
if (metadata->header_metadata_size != 0)
|
||||||
size += lzma_vli_size(metadata->header_metadata_size);
|
size += lzma_vli_size(metadata->header_metadata_size);
|
||||||
|
|
||||||
if (metadata->total_size != LZMA_VLI_VALUE_UNKNOWN)
|
if (metadata->total_size != LZMA_VLI_VALUE_UNKNOWN)
|
||||||
|
|
|
@ -527,7 +527,7 @@ test6(void)
|
||||||
// still present in Footer.
|
// still present in Footer.
|
||||||
reset();
|
reset();
|
||||||
metadata = my_metadata;
|
metadata = my_metadata;
|
||||||
metadata.header_metadata_size = LZMA_VLI_VALUE_UNKNOWN;
|
metadata.header_metadata_size = 0;
|
||||||
expect(lzma_info_size_set(info, LZMA_INFO_HEADER_METADATA, 0)
|
expect(lzma_info_size_set(info, LZMA_INFO_HEADER_METADATA, 0)
|
||||||
== LZMA_OK);
|
== LZMA_OK);
|
||||||
expect(lzma_info_metadata_set(info, NULL, &metadata, true, false)
|
expect(lzma_info_metadata_set(info, NULL, &metadata, true, false)
|
||||||
|
@ -539,7 +539,7 @@ test6(void)
|
||||||
// from Footer.
|
// from Footer.
|
||||||
reset();
|
reset();
|
||||||
metadata = my_metadata;
|
metadata = my_metadata;
|
||||||
metadata.header_metadata_size = LZMA_VLI_VALUE_UNKNOWN;
|
metadata.header_metadata_size = 0;
|
||||||
expect(lzma_info_metadata_set(info, NULL, &my_metadata, true, false)
|
expect(lzma_info_metadata_set(info, NULL, &my_metadata, true, false)
|
||||||
== LZMA_OK);
|
== LZMA_OK);
|
||||||
expect(lzma_info_size_set(info, LZMA_INFO_HEADER_METADATA,
|
expect(lzma_info_size_set(info, LZMA_INFO_HEADER_METADATA,
|
||||||
|
|
Loading…
Reference in New Issue