XZ Utils  5.1.0alpha
Functions
stream_flags_decoder.c File Reference

Decodes Stream Header and Stream Footer from .xz files. More...

#include "stream_flags_common.h"

Functions

static bool stream_flags_decode (lzma_stream_flags *options, const uint8_t *in)
lzma_ret lzma_stream_header_decode (lzma_stream_flags *options, const uint8_t *in)
 Decode Stream Header.
lzma_ret lzma_stream_footer_decode (lzma_stream_flags *options, const uint8_t *in)
 Decode Stream Footer.

Detailed Description

Decodes Stream Header and Stream Footer from .xz files.


Function Documentation

lzma_ret lzma_stream_header_decode ( lzma_stream_flags options,
const uint8_t *  in 
)

Decode Stream Header.

Parameters:
optionsTarget for the decoded Stream Header options.
inBeginning of the input buffer of LZMA_STREAM_HEADER_SIZE bytes.

options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to help comparing Stream Flags from Stream Header and Stream Footer with lzma_stream_flags_compare().

Returns:
- LZMA_OK: Decoding was successful.
  • LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given buffer cannot be Stream Header.
  • LZMA_DATA_ERROR: CRC32 doesn't match, thus the header is corrupt.
  • LZMA_OPTIONS_ERROR: Unsupported options are present in the header.
Note:
When decoding .xz files that contain multiple Streams, it may make sense to print "file format not recognized" only if decoding of the Stream Header of the first Stream gives LZMA_FORMAT_ERROR. If non-first Stream Header gives LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is probably more appropriate.

For example, Stream decoder in liblzma uses LZMA_DATA_ERROR if LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode() when decoding non-first Stream.

References lzma_crc32(), LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_STREAM_FLAGS_SIZE, and LZMA_VLI_UNKNOWN.

Referenced by parse_indexes().

lzma_ret lzma_stream_footer_decode ( lzma_stream_flags options,
const uint8_t *  in 
)

Decode Stream Footer.

Parameters:
optionsTarget for the decoded Stream Header options.
inBeginning of the input buffer of LZMA_STREAM_HEADER_SIZE bytes.
Returns:
- LZMA_OK: Decoding was successful.
  • LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given buffer cannot be Stream Footer.
  • LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer is corrupt.
  • LZMA_OPTIONS_ERROR: Unsupported options are present in Stream Footer.
Note:
If Stream Header was already decoded successfully, but decoding Stream Footer returns LZMA_FORMAT_ERROR, the application should probably report some other error message than "file format not recognized", since the file more likely is corrupt (possibly truncated). Stream decoder in liblzma uses LZMA_DATA_ERROR in this situation.

References lzma_crc32(), LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, LZMA_OK, LZMA_OPTIONS_ERROR, and LZMA_STREAM_FLAGS_SIZE.

Referenced by parse_indexes().