stream_decoder.c | stream_decoder.c | |||
---|---|---|---|---|
skipping to change at line 59 | skipping to change at line 59 | |||
/// no integrity check. | /// no integrity check. | |||
bool tell_no_check; | bool tell_no_check; | |||
/// If true, LZMA_UNSUPPORTED_CHECK is returned if the Stream has | /// If true, LZMA_UNSUPPORTED_CHECK is returned if the Stream has | |||
/// an integrity check that isn't supported by this liblzma build. | /// an integrity check that isn't supported by this liblzma build. | |||
bool tell_unsupported_check; | bool tell_unsupported_check; | |||
/// If true, LZMA_GET_CHECK is returned after decoding Stream Header . | /// If true, LZMA_GET_CHECK is returned after decoding Stream Header . | |||
bool tell_any_check; | bool tell_any_check; | |||
/// If true, we will tell the Block decoder to skip calculating | ||||
/// and verifying the integrity check. | ||||
bool ignore_check; | ||||
/// If true, we will decode concatenated Streams that possibly have | /// If true, we will decode concatenated Streams that possibly have | |||
/// Stream Padding between or after them. LZMA_STREAM_END is returne d | /// Stream Padding between or after them. LZMA_STREAM_END is returne d | |||
/// once the application isn't giving us any new input, and we aren' t | /// once the application isn't giving us any new input, and we aren' t | |||
/// in the middle of a Stream, and possible Stream Padding is a | /// in the middle of a Stream, and possible Stream Padding is a | |||
/// multiple of four bytes. | /// multiple of four bytes. | |||
bool concatenated; | bool concatenated; | |||
/// When decoding concatenated Streams, this is true as long as we | /// When decoding concatenated Streams, this is true as long as we | |||
/// are decoding the first Stream. This is needed to avoid misleadin g | /// are decoding the first Stream. This is needed to avoid misleadin g | |||
/// LZMA_FORMAT_ERROR in case the later Streams don't have valid mag ic | /// LZMA_FORMAT_ERROR in case the later Streams don't have valid mag ic | |||
skipping to change at line 81 | skipping to change at line 85 | |||
/// Write position in buffer[] and position in Stream Padding | /// Write position in buffer[] and position in Stream Padding | |||
size_t pos; | size_t pos; | |||
/// Buffer to hold Stream Header, Block Header, and Stream Footer. | /// Buffer to hold Stream Header, Block Header, and Stream Footer. | |||
/// Block Header has biggest maximum size. | /// Block Header has biggest maximum size. | |||
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX]; | uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX]; | |||
}; | }; | |||
static lzma_ret | static lzma_ret | |||
stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator) | stream_decoder_reset(lzma_coder *coder, const lzma_allocator *allocator) | |||
{ | { | |||
// Initialize the Index hash used to verify the Index. | // Initialize the Index hash used to verify the Index. | |||
coder->index_hash = lzma_index_hash_init(coder->index_hash, allocato r); | coder->index_hash = lzma_index_hash_init(coder->index_hash, allocato r); | |||
if (coder->index_hash == NULL) | if (coder->index_hash == NULL) | |||
return LZMA_MEM_ERROR; | return LZMA_MEM_ERROR; | |||
// Reset the rest of the variables. | // Reset the rest of the variables. | |||
coder->sequence = SEQ_STREAM_HEADER; | coder->sequence = SEQ_STREAM_HEADER; | |||
coder->pos = 0; | coder->pos = 0; | |||
return LZMA_OK; | return LZMA_OK; | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
stream_decode(lzma_coder *coder, lzma_allocator *allocator, | stream_decode(lzma_coder *coder, const lzma_allocator *allocator, | |||
const uint8_t *restrict in, size_t *restrict in_pos, | const uint8_t *restrict in, size_t *restrict in_pos, | |||
size_t in_size, uint8_t *restrict out, | size_t in_size, uint8_t *restrict out, | |||
size_t *restrict out_pos, size_t out_size, lzma_action actio n) | size_t *restrict out_pos, size_t out_size, lzma_action actio n) | |||
{ | { | |||
// When decoding the actual Block, it may be able to produce more | // When decoding the actual Block, it may be able to produce more | |||
// output even if we don't give it any new input. | // output even if we don't give it any new input. | |||
while (true) | while (true) | |||
switch (coder->sequence) { | switch (coder->sequence) { | |||
case SEQ_STREAM_HEADER: { | case SEQ_STREAM_HEADER: { | |||
// Copy the Stream Header to the internal buffer. | // Copy the Stream Header to the internal buffer. | |||
skipping to change at line 182 | skipping to change at line 186 | |||
// Copy the Block Header to the internal buffer. | // Copy the Block Header to the internal buffer. | |||
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos, | lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos, | |||
coder->block_options.header_size); | coder->block_options.header_size); | |||
// Return if we didn't get the whole Block Header yet. | // Return if we didn't get the whole Block Header yet. | |||
if (coder->pos < coder->block_options.header_size) | if (coder->pos < coder->block_options.header_size) | |||
return LZMA_OK; | return LZMA_OK; | |||
coder->pos = 0; | coder->pos = 0; | |||
// Version 0 is currently the only possible version. | // Version 1 is needed to support the .ignore_check option. | |||
coder->block_options.version = 0; | coder->block_options.version = 1; | |||
// Set up a buffer to hold the filter chain. Block Header | // Set up a buffer to hold the filter chain. Block Header | |||
// decoder will initialize all members of this array so | // decoder will initialize all members of this array so | |||
// we don't need to do it here. | // we don't need to do it here. | |||
lzma_filter filters[LZMA_FILTERS_MAX + 1]; | lzma_filter filters[LZMA_FILTERS_MAX + 1]; | |||
coder->block_options.filters = filters; | coder->block_options.filters = filters; | |||
// Decode the Block Header. | // Decode the Block Header. | |||
return_if_error(lzma_block_header_decode(&coder->block_optio ns, | return_if_error(lzma_block_header_decode(&coder->block_optio ns, | |||
allocator, coder->buffer)); | allocator, coder->buffer)); | |||
// If LZMA_IGNORE_CHECK was used, this flag needs to be set. | ||||
// It has to be set after lzma_block_header_decode() because | ||||
// it always resets this to false. | ||||
coder->block_options.ignore_check = coder->ignore_check; | ||||
// Check the memory usage limit. | // Check the memory usage limit. | |||
const uint64_t memusage = lzma_raw_decoder_memusage(filters) ; | const uint64_t memusage = lzma_raw_decoder_memusage(filters) ; | |||
lzma_ret ret; | lzma_ret ret; | |||
if (memusage == UINT64_MAX) { | if (memusage == UINT64_MAX) { | |||
// One or more unknown Filter IDs. | // One or more unknown Filter IDs. | |||
ret = LZMA_OPTIONS_ERROR; | ret = LZMA_OPTIONS_ERROR; | |||
} else { | } else { | |||
// Now we can set coder->memusage since we know that | // Now we can set coder->memusage since we know that | |||
// the filter chain is valid. We don't want | // the filter chain is valid. We don't want | |||
skipping to change at line 365 | skipping to change at line 374 | |||
default: | default: | |||
assert(0); | assert(0); | |||
return LZMA_PROG_ERROR; | return LZMA_PROG_ERROR; | |||
} | } | |||
// Never reached | // Never reached | |||
} | } | |||
static void | static void | |||
stream_decoder_end(lzma_coder *coder, lzma_allocator *allocator) | stream_decoder_end(lzma_coder *coder, const lzma_allocator *allocator) | |||
{ | { | |||
lzma_next_end(&coder->block_decoder, allocator); | lzma_next_end(&coder->block_decoder, allocator); | |||
lzma_index_hash_end(coder->index_hash, allocator); | lzma_index_hash_end(coder->index_hash, allocator); | |||
lzma_free(coder, allocator); | lzma_free(coder, allocator); | |||
return; | return; | |||
} | } | |||
static lzma_check | static lzma_check | |||
stream_decoder_get_check(const lzma_coder *coder) | stream_decoder_get_check(const lzma_coder *coder) | |||
{ | { | |||
skipping to change at line 397 | skipping to change at line 406 | |||
if (new_memlimit < coder->memusage) | if (new_memlimit < coder->memusage) | |||
return LZMA_MEMLIMIT_ERROR; | return LZMA_MEMLIMIT_ERROR; | |||
coder->memlimit = new_memlimit; | coder->memlimit = new_memlimit; | |||
} | } | |||
return LZMA_OK; | return LZMA_OK; | |||
} | } | |||
extern lzma_ret | extern lzma_ret | |||
lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator, | lzma_stream_decoder_init( | |||
lzma_next_coder *next, const lzma_allocator *allocator, | ||||
uint64_t memlimit, uint32_t flags) | uint64_t memlimit, uint32_t flags) | |||
{ | { | |||
lzma_next_coder_init(&lzma_stream_decoder_init, next, allocator); | lzma_next_coder_init(&lzma_stream_decoder_init, next, allocator); | |||
if (memlimit == 0) | if (memlimit == 0) | |||
return LZMA_PROG_ERROR; | return LZMA_PROG_ERROR; | |||
if (flags & ~LZMA_SUPPORTED_FLAGS) | if (flags & ~LZMA_SUPPORTED_FLAGS) | |||
return LZMA_OPTIONS_ERROR; | return LZMA_OPTIONS_ERROR; | |||
skipping to change at line 428 | skipping to change at line 438 | |||
next->coder->block_decoder = LZMA_NEXT_CODER_INIT; | next->coder->block_decoder = LZMA_NEXT_CODER_INIT; | |||
next->coder->index_hash = NULL; | next->coder->index_hash = NULL; | |||
} | } | |||
next->coder->memlimit = memlimit; | next->coder->memlimit = memlimit; | |||
next->coder->memusage = LZMA_MEMUSAGE_BASE; | next->coder->memusage = LZMA_MEMUSAGE_BASE; | |||
next->coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0; | next->coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0; | |||
next->coder->tell_unsupported_check | next->coder->tell_unsupported_check | |||
= (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0; | = (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0; | |||
next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0; | next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0; | |||
next->coder->ignore_check = (flags & LZMA_IGNORE_CHECK) != 0; | ||||
next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0; | next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0; | |||
next->coder->first_stream = true; | next->coder->first_stream = true; | |||
return stream_decoder_reset(next->coder, allocator); | return stream_decoder_reset(next->coder, allocator); | |||
} | } | |||
extern LZMA_API(lzma_ret) | extern LZMA_API(lzma_ret) | |||
lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) | lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags) | |||
{ | { | |||
lzma_next_strm_init(lzma_stream_decoder_init, strm, memlimit, flags) ; | lzma_next_strm_init(lzma_stream_decoder_init, strm, memlimit, flags) ; | |||
End of changes. 8 change blocks. | ||||
6 lines changed or deleted | 17 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/ |