2007-12-08 22:42:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file stream_decoder.c
|
|
|
|
/// \brief Decodes .lzma Streams
|
|
|
|
//
|
|
|
|
// Copyright (C) 2007 Lasse Collin
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
#include "stream_decoder.h"
|
2007-12-08 22:42:33 +00:00
|
|
|
#include "block_decoder.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct lzma_coder_s {
|
|
|
|
enum {
|
2008-06-18 15:02:10 +00:00
|
|
|
SEQ_STREAM_HEADER,
|
|
|
|
SEQ_BLOCK_HEADER,
|
|
|
|
SEQ_BLOCK,
|
|
|
|
SEQ_INDEX,
|
|
|
|
SEQ_STREAM_FOOTER,
|
2008-08-28 19:53:15 +00:00
|
|
|
SEQ_STREAM_PADDING,
|
2007-12-08 22:42:33 +00:00
|
|
|
} sequence;
|
|
|
|
|
|
|
|
/// Block or Metadata decoder. This takes little memory and the same
|
|
|
|
/// data structure can be used to decode every Block Header, so it's
|
|
|
|
/// a good idea to have a separate lzma_next_coder structure for it.
|
|
|
|
lzma_next_coder block_decoder;
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
/// Block options decoded by the Block Header decoder and used by
|
|
|
|
/// the Block decoder.
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_block block_options;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
|
|
|
/// Stream Flags from Stream Header
|
2008-06-18 15:02:10 +00:00
|
|
|
lzma_stream_flags stream_flags;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
/// Index is hashed so that it can be compared to the sizes of Blocks
|
|
|
|
/// with O(1) memory usage.
|
|
|
|
lzma_index_hash *index_hash;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
/// Memory usage limit
|
|
|
|
uint64_t memlimit;
|
|
|
|
|
|
|
|
/// If true, LZMA_NO_CHECK is returned if the Stream has
|
|
|
|
/// no integrity check.
|
2008-09-06 12:14:30 +00:00
|
|
|
bool tell_no_check;
|
2008-08-28 19:53:15 +00:00
|
|
|
|
|
|
|
/// If true, LZMA_UNSUPPORTED_CHECK is returned if the Stream has
|
|
|
|
/// an integrity check that isn't supported by this liblzma build.
|
2008-09-06 12:14:30 +00:00
|
|
|
bool tell_unsupported_check;
|
2008-08-28 19:53:15 +00:00
|
|
|
|
2008-09-06 12:14:30 +00:00
|
|
|
/// If true, LZMA_GET_CHECK is returned after decoding Stream Header.
|
|
|
|
bool tell_any_check;
|
2008-08-28 19:53:15 +00:00
|
|
|
|
|
|
|
/// If true, we will decode concatenated Streams that possibly have
|
|
|
|
/// Stream Padding between or after them. LZMA_STREAM_END is returned
|
2008-09-02 11:56:52 +00:00
|
|
|
/// 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
|
|
|
|
/// multiple of four bytes.
|
2008-08-28 19:53:15 +00:00
|
|
|
bool concatenated;
|
|
|
|
|
|
|
|
/// When decoding concatenated Streams, this is true as long as we
|
|
|
|
/// are decoding the first Stream. This is needed to avoid misleading
|
|
|
|
/// LZMA_FORMAT_ERROR in case the later Streams don't have valid magic
|
|
|
|
/// bytes.
|
|
|
|
bool first_stream;
|
|
|
|
|
|
|
|
/// Write position in buffer[] and position in Stream Padding
|
|
|
|
size_t pos;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
/// Buffer to hold Stream Header, Block Header, and Stream Footer.
|
|
|
|
/// Block Header has biggest maximum size.
|
|
|
|
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
|
2007-12-08 22:42:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
static lzma_ret
|
|
|
|
stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator)
|
|
|
|
{
|
|
|
|
// Initialize the Index hash used to verify the Index.
|
|
|
|
coder->index_hash = lzma_index_hash_init(coder->index_hash, allocator);
|
|
|
|
if (coder->index_hash == NULL)
|
|
|
|
return LZMA_MEM_ERROR;
|
|
|
|
|
|
|
|
// Reset the rest of the variables.
|
|
|
|
coder->sequence = SEQ_STREAM_HEADER;
|
|
|
|
coder->block_options.filters = NULL;
|
|
|
|
coder->pos = 0;
|
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-08 22:42:33 +00:00
|
|
|
static lzma_ret
|
|
|
|
stream_decode(lzma_coder *coder, lzma_allocator *allocator,
|
|
|
|
const uint8_t *restrict in, size_t *restrict in_pos,
|
|
|
|
size_t in_size, uint8_t *restrict out,
|
|
|
|
size_t *restrict out_pos, size_t out_size, lzma_action action)
|
|
|
|
{
|
2008-06-18 15:02:10 +00:00
|
|
|
// When decoding the actual Block, it may be able to produce more
|
|
|
|
// output even if we don't give it any new input.
|
2008-08-28 19:53:15 +00:00
|
|
|
while (true)
|
2007-12-08 22:42:33 +00:00
|
|
|
switch (coder->sequence) {
|
2008-06-18 15:02:10 +00:00
|
|
|
case SEQ_STREAM_HEADER: {
|
|
|
|
// Copy the Stream Header to the internal buffer.
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
|
2008-06-18 15:02:10 +00:00
|
|
|
LZMA_STREAM_HEADER_SIZE);
|
|
|
|
|
|
|
|
// Return if we didn't get the whole Stream Header yet.
|
2008-08-28 19:53:15 +00:00
|
|
|
if (coder->pos < LZMA_STREAM_HEADER_SIZE)
|
2008-06-18 15:02:10 +00:00
|
|
|
return LZMA_OK;
|
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
coder->pos = 0;
|
2008-06-18 15:02:10 +00:00
|
|
|
|
|
|
|
// Decode the Stream Header.
|
2008-08-28 19:53:15 +00:00
|
|
|
const lzma_ret ret = lzma_stream_header_decode(
|
|
|
|
&coder->stream_flags, coder->buffer);
|
|
|
|
if (ret != LZMA_OK)
|
|
|
|
return ret == LZMA_FORMAT_ERROR && !coder->first_stream
|
|
|
|
? LZMA_DATA_ERROR : ret;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Copy the type of the Check so that Block Header and Block
|
|
|
|
// decoders see it.
|
|
|
|
coder->block_options.check = coder->stream_flags.check;
|
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
// Even if we return LZMA_*_CHECK below, we want
|
2008-06-18 15:02:10 +00:00
|
|
|
// to continue from Block Header decoding.
|
|
|
|
coder->sequence = SEQ_BLOCK_HEADER;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
// Detect if there's no integrity check or if it is
|
|
|
|
// unsupported if those were requested by the application.
|
2008-09-06 12:14:30 +00:00
|
|
|
if (coder->tell_no_check && coder->stream_flags.check
|
2008-08-28 19:53:15 +00:00
|
|
|
== LZMA_CHECK_NONE)
|
|
|
|
return LZMA_NO_CHECK;
|
|
|
|
|
2008-09-06 12:14:30 +00:00
|
|
|
if (coder->tell_unsupported_check
|
2008-08-28 19:53:15 +00:00
|
|
|
&& !lzma_check_is_supported(
|
|
|
|
coder->stream_flags.check))
|
2007-12-08 22:42:33 +00:00
|
|
|
return LZMA_UNSUPPORTED_CHECK;
|
|
|
|
|
2008-09-06 12:14:30 +00:00
|
|
|
if (coder->tell_any_check)
|
|
|
|
return LZMA_GET_CHECK;
|
2007-12-08 22:42:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Fall through
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
case SEQ_BLOCK_HEADER: {
|
2008-08-28 19:53:15 +00:00
|
|
|
if (*in_pos >= in_size)
|
|
|
|
return LZMA_OK;
|
|
|
|
|
|
|
|
if (coder->pos == 0) {
|
2008-06-18 15:02:10 +00:00
|
|
|
// Detect if it's Index.
|
|
|
|
if (in[*in_pos] == 0x00) {
|
|
|
|
coder->sequence = SEQ_INDEX;
|
|
|
|
break;
|
|
|
|
}
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Calculate the size of the Block Header. Note that
|
|
|
|
// Block Header decoder wants to see this byte too
|
|
|
|
// so don't advance *in_pos.
|
|
|
|
coder->block_options.header_size
|
|
|
|
= lzma_block_header_size_decode(
|
|
|
|
in[*in_pos]);
|
2008-01-16 12:48:04 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Copy the Block Header to the internal buffer.
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->block_options.header_size);
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Return if we didn't get the whole Block Header yet.
|
2008-08-28 19:53:15 +00:00
|
|
|
if (coder->pos < coder->block_options.header_size)
|
2008-06-18 15:02:10 +00:00
|
|
|
return LZMA_OK;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
coder->pos = 0;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Set up a buffer to hold the filter chain. Block Header
|
|
|
|
// decoder will initialize all members of this array so
|
|
|
|
// we don't need to do it here.
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_filter filters[LZMA_BLOCK_FILTERS_MAX + 1];
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->block_options.filters = filters;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Decode the Block Header.
|
|
|
|
return_if_error(lzma_block_header_decode(&coder->block_options,
|
|
|
|
allocator, coder->buffer));
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
// Check the memory usage limit.
|
|
|
|
const uint64_t memusage = lzma_memusage_decoder(filters);
|
|
|
|
lzma_ret ret;
|
|
|
|
|
|
|
|
if (memusage == UINT64_MAX) {
|
|
|
|
// One or more unknown Filter IDs.
|
2008-09-13 09:10:43 +00:00
|
|
|
ret = LZMA_OPTIONS_ERROR;
|
2008-08-28 19:53:15 +00:00
|
|
|
} else if (memusage > coder->memlimit) {
|
|
|
|
// The chain would need too much memory.
|
|
|
|
ret = LZMA_MEMLIMIT_ERROR;
|
|
|
|
} else {
|
|
|
|
// Memory usage is OK. Initialize the Block decoder.
|
|
|
|
ret = lzma_block_decoder_init(
|
|
|
|
&coder->block_decoder,
|
|
|
|
allocator, &coder->block_options);
|
|
|
|
}
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Free the allocated filter options since they are needed
|
|
|
|
// only to initialize the Block decoder.
|
|
|
|
for (size_t i = 0; i < LZMA_BLOCK_FILTERS_MAX; ++i)
|
|
|
|
lzma_free(filters[i].options, allocator);
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->block_options.filters = NULL;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
// Check if memory usage calculation and Block enocoder
|
|
|
|
// initialization succeeded.
|
|
|
|
if (ret != LZMA_OK)
|
2007-12-08 22:42:33 +00:00
|
|
|
return ret;
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->sequence = SEQ_BLOCK;
|
2007-12-08 22:42:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Fall through
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
case SEQ_BLOCK: {
|
2008-08-28 19:53:15 +00:00
|
|
|
const lzma_ret ret = coder->block_decoder.code(
|
2007-12-08 22:42:33 +00:00
|
|
|
coder->block_decoder.coder, allocator,
|
|
|
|
in, in_pos, in_size, out, out_pos, out_size,
|
|
|
|
action);
|
|
|
|
|
|
|
|
if (ret != LZMA_STREAM_END)
|
|
|
|
return ret;
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Block decoded successfully. Add the new size pair to
|
|
|
|
// the Index hash.
|
|
|
|
return_if_error(lzma_index_hash_append(coder->index_hash,
|
|
|
|
lzma_block_total_size_get(
|
|
|
|
&coder->block_options),
|
|
|
|
coder->block_options.uncompressed_size));
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->sequence = SEQ_BLOCK_HEADER;
|
2007-12-08 22:42:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
case SEQ_INDEX: {
|
2008-08-28 19:53:15 +00:00
|
|
|
// If we don't have any input, don't call
|
|
|
|
// lzma_index_hash_decode() since it would return
|
|
|
|
// LZMA_BUF_ERROR, which we must not do here.
|
|
|
|
if (*in_pos >= in_size)
|
|
|
|
return LZMA_OK;
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Decode the Index and compare it to the hash calculated
|
|
|
|
// from the sizes of the Blocks (if any).
|
|
|
|
const lzma_ret ret = lzma_index_hash_decode(coder->index_hash,
|
|
|
|
in, in_pos, in_size);
|
|
|
|
if (ret != LZMA_STREAM_END)
|
2007-12-08 22:42:33 +00:00
|
|
|
return ret;
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
coder->sequence = SEQ_STREAM_FOOTER;
|
2007-12-08 22:42:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Fall through
|
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
case SEQ_STREAM_FOOTER:
|
|
|
|
// Copy the Stream Footer to the internal buffer.
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_bufcpy(in, in_pos, in_size, coder->buffer, &coder->pos,
|
2008-06-18 15:02:10 +00:00
|
|
|
LZMA_STREAM_HEADER_SIZE);
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-06-18 15:02:10 +00:00
|
|
|
// Return if we didn't get the whole Stream Footer yet.
|
2008-08-28 19:53:15 +00:00
|
|
|
if (coder->pos < LZMA_STREAM_HEADER_SIZE)
|
2008-06-18 15:02:10 +00:00
|
|
|
return LZMA_OK;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
coder->pos = 0;
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Decode the Stream Footer. The decoder gives
|
|
|
|
// LZMA_FORMAT_ERROR if the magic bytes don't match,
|
|
|
|
// so convert that return code to LZMA_DATA_ERROR.
|
2008-06-18 15:02:10 +00:00
|
|
|
lzma_stream_flags footer_flags;
|
2008-09-02 11:56:52 +00:00
|
|
|
const lzma_ret ret = lzma_stream_footer_decode(
|
|
|
|
&footer_flags, coder->buffer);
|
|
|
|
if (ret != LZMA_OK)
|
|
|
|
return ret == LZMA_FORMAT_ERROR
|
|
|
|
? LZMA_DATA_ERROR : ret;
|
2008-06-18 15:02:10 +00:00
|
|
|
|
|
|
|
// Check that Index Size stored in the Stream Footer matches
|
|
|
|
// the real size of the Index field.
|
|
|
|
if (lzma_index_hash_size(coder->index_hash)
|
|
|
|
!= footer_flags.backward_size)
|
|
|
|
return LZMA_DATA_ERROR;
|
|
|
|
|
|
|
|
// Compare that the Stream Flags fields are identical in
|
|
|
|
// both Stream Header and Stream Footer.
|
2008-09-12 19:41:40 +00:00
|
|
|
return_if_error(lzma_stream_flags_compare(
|
|
|
|
&coder->stream_flags, &footer_flags));
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
if (!coder->concatenated)
|
|
|
|
return LZMA_STREAM_END;
|
|
|
|
|
|
|
|
coder->sequence = SEQ_STREAM_PADDING;
|
2008-09-02 11:56:52 +00:00
|
|
|
|
|
|
|
// Fall through
|
2008-08-28 19:53:15 +00:00
|
|
|
|
|
|
|
case SEQ_STREAM_PADDING:
|
|
|
|
assert(coder->concatenated);
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Skip over possible Stream Padding.
|
2008-08-28 19:53:15 +00:00
|
|
|
while (true) {
|
|
|
|
if (*in_pos >= in_size) {
|
|
|
|
// Unless LZMA_FINISH was used, we cannot
|
|
|
|
// know if there's more input coming later.
|
|
|
|
if (action != LZMA_FINISH)
|
|
|
|
return LZMA_OK;
|
|
|
|
|
|
|
|
// Stream Padding must be a multiple of
|
|
|
|
// four bytes.
|
|
|
|
return coder->pos == 0
|
|
|
|
? LZMA_STREAM_END
|
|
|
|
: LZMA_DATA_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// If the byte is not zero, it probably indicates
|
|
|
|
// beginning of a new Stream (or the file is corrupt).
|
|
|
|
if (in[*in_pos] != 0x00)
|
2008-08-28 19:53:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
++*in_pos;
|
|
|
|
coder->pos = (coder->pos + 1) & 3;
|
|
|
|
}
|
|
|
|
|
2008-09-02 11:56:52 +00:00
|
|
|
// Stream Padding must be a multiple of four bytes (empty
|
|
|
|
// Stream Padding is OK).
|
|
|
|
if (coder->pos != 0) {
|
|
|
|
++*in_pos;
|
|
|
|
return LZMA_DATA_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare to decode the next Stream.
|
|
|
|
return_if_error(stream_decoder_reset(coder, allocator));
|
2008-08-28 19:53:15 +00:00
|
|
|
break;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
|
|
|
default:
|
2008-06-18 15:02:10 +00:00
|
|
|
assert(0);
|
2007-12-08 22:42:33 +00:00
|
|
|
return LZMA_PROG_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
stream_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
|
|
|
|
{
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_next_end(&coder->block_decoder, allocator);
|
2008-06-18 15:02:10 +00:00
|
|
|
lzma_index_hash_end(coder->index_hash, allocator);
|
2007-12-08 22:42:33 +00:00
|
|
|
lzma_free(coder, allocator);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
static lzma_check
|
2008-09-06 12:14:30 +00:00
|
|
|
stream_decoder_get_check(const lzma_coder *coder)
|
2007-12-08 22:42:33 +00:00
|
|
|
{
|
2008-08-28 19:53:15 +00:00
|
|
|
return coder->stream_flags.check;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern lzma_ret
|
|
|
|
lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
|
|
|
|
uint64_t memlimit, uint32_t flags)
|
|
|
|
{
|
|
|
|
lzma_next_coder_init(lzma_stream_decoder_init, next, allocator);
|
|
|
|
|
|
|
|
if (flags & ~LZMA_SUPPORTED_FLAGS)
|
2008-09-13 09:10:43 +00:00
|
|
|
return LZMA_OPTIONS_ERROR;
|
2008-08-28 19:53:15 +00:00
|
|
|
|
2007-12-08 22:42:33 +00:00
|
|
|
if (next->coder == NULL) {
|
|
|
|
next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
|
|
|
|
if (next->coder == NULL)
|
|
|
|
return LZMA_MEM_ERROR;
|
|
|
|
|
|
|
|
next->code = &stream_decode;
|
|
|
|
next->end = &stream_decoder_end;
|
2008-09-06 12:14:30 +00:00
|
|
|
next->get_check = &stream_decoder_get_check;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
|
|
|
next->coder->block_decoder = LZMA_NEXT_CODER_INIT;
|
2008-06-18 15:02:10 +00:00
|
|
|
next->coder->index_hash = NULL;
|
2007-12-08 22:42:33 +00:00
|
|
|
}
|
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
next->coder->memlimit = memlimit;
|
2008-09-06 12:14:30 +00:00
|
|
|
next->coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0;
|
|
|
|
next->coder->tell_unsupported_check
|
|
|
|
= (flags & LZMA_TELL_UNSUPPORTED_CHECK) != 0;
|
|
|
|
next->coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
|
|
|
|
next->coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
2008-08-28 19:53:15 +00:00
|
|
|
return stream_decoder_reset(next->coder, allocator);
|
2007-12-08 22:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern LZMA_API lzma_ret
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_stream_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
|
2007-12-08 22:42:33 +00:00
|
|
|
{
|
2008-08-28 19:53:15 +00:00
|
|
|
lzma_next_strm_init(lzma_stream_decoder_init, strm, memlimit, flags);
|
2007-12-08 22:42:33 +00:00
|
|
|
|
|
|
|
strm->internal->supported_actions[LZMA_RUN] = true;
|
2008-08-28 19:53:15 +00:00
|
|
|
strm->internal->supported_actions[LZMA_FINISH] = true;
|
2007-12-08 22:42:33 +00:00
|
|
|
|
|
|
|
return LZMA_OK;
|
|
|
|
}
|