diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-23 13:36:07 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-23 13:36:07 +0200 |
commit | 99e12af4e2b866c011fe0106cd1e0bfdcc8fe9c6 (patch) | |
tree | 45a3b5e6acda6b7f61e089a1297e95dfb1f75350 /src/liblzma/common/metadata_encoder.c | |
parent | Fix a memory leak in metadata_decoder.c. (diff) | |
download | xz-99e12af4e2b866c011fe0106cd1e0bfdcc8fe9c6.tar.xz |
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.
Diffstat (limited to '')
-rw-r--r-- | src/liblzma/common/metadata_encoder.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/liblzma/common/metadata_encoder.c b/src/liblzma/common/metadata_encoder.c index 17587c5c..9f4a15b0 100644 --- a/src/liblzma/common/metadata_encoder.c +++ b/src/liblzma/common/metadata_encoder.c @@ -87,8 +87,7 @@ process(lzma_coder *coder) case SEQ_FLAGS: coder->buffer[coder->buffer_size] = 0; - if (coder->metadata.header_metadata_size - != LZMA_VLI_VALUE_UNKNOWN) + if (coder->metadata.header_metadata_size != 0) coder->buffer[coder->buffer_size] |= 0x01; if (coder->metadata.total_size != LZMA_VLI_VALUE_UNKNOWN) @@ -109,8 +108,7 @@ process(lzma_coder *coder) break; case SEQ_HEADER_METADATA_SIZE: - if (coder->metadata.header_metadata_size - != LZMA_VLI_VALUE_UNKNOWN) + if (coder->metadata.header_metadata_size != 0) write_vli(coder->metadata.header_metadata_size); coder->sequence = SEQ_TOTAL_SIZE; @@ -373,13 +371,14 @@ lzma_metadata_size(const lzma_metadata *metadata) lzma_vli size = 1; // Metadata Flags // 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) + || metadata->total_size == 0 || !lzma_vli_is_valid(metadata->uncompressed_size)) return 0; // 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); if (metadata->total_size != LZMA_VLI_VALUE_UNKNOWN) |