003 File Manager
Current Path:
/usr/src/contrib/xz/src/liblzma/common
usr
/
src
/
contrib
/
xz
/
src
/
liblzma
/
common
/
📁
..
📄
alone_decoder.c
(5.53 KB)
📄
alone_decoder.h
(601 B)
📄
alone_encoder.c
(3.66 KB)
📄
auto_decoder.c
(4.79 KB)
📄
block_buffer_decoder.c
(2.31 KB)
📄
block_buffer_encoder.c
(9.89 KB)
📄
block_buffer_encoder.h
(763 B)
📄
block_decoder.c
(6.82 KB)
📄
block_decoder.h
(576 B)
📄
block_encoder.c
(5.63 KB)
📄
block_encoder.h
(1.85 KB)
📄
block_header_decoder.c
(3.62 KB)
📄
block_header_encoder.c
(3.27 KB)
📄
block_util.c
(2.58 KB)
📄
common.c
(10.4 KB)
📄
common.h
(10.22 KB)
📄
easy_buffer_encoder.c
(840 B)
📄
easy_decoder_memusage.c
(668 B)
📄
easy_encoder.c
(678 B)
📄
easy_encoder_memusage.c
(654 B)
📄
easy_preset.c
(727 B)
📄
easy_preset.h
(921 B)
📄
filter_buffer_decoder.c
(2.45 KB)
📄
filter_buffer_encoder.c
(1.5 KB)
📄
filter_common.c
(8.5 KB)
📄
filter_common.h
(1.23 KB)
📄
filter_decoder.c
(4.32 KB)
📄
filter_decoder.h
(617 B)
📄
filter_encoder.c
(7.17 KB)
📄
filter_encoder.h
(732 B)
📄
filter_flags_decoder.c
(1.16 KB)
📄
filter_flags_encoder.c
(1.37 KB)
📄
hardware_cputhreads.c
(526 B)
📄
hardware_physmem.c
(683 B)
📄
index.c
(34.61 KB)
📄
index.h
(1.93 KB)
📄
index_decoder.c
(8.4 KB)
📄
index_encoder.c
(5.72 KB)
📄
index_encoder.h
(584 B)
📄
index_hash.c
(8.77 KB)
📄
memcmplen.h
(4.71 KB)
📄
outqueue.c
(4.48 KB)
📄
outqueue.h
(4.88 KB)
📄
stream_buffer_decoder.c
(2.72 KB)
📄
stream_buffer_encoder.c
(3.96 KB)
📄
stream_decoder.c
(12.7 KB)
📄
stream_decoder.h
(599 B)
📄
stream_encoder.c
(9.63 KB)
📄
stream_encoder_mt.c
(29.64 KB)
📄
stream_flags_common.c
(1.29 KB)
📄
stream_flags_common.h
(883 B)
📄
stream_flags_decoder.c
(2.23 KB)
📄
stream_flags_encoder.c
(2.01 KB)
📄
vli_decoder.c
(2.5 KB)
📄
vli_encoder.c
(1.89 KB)
📄
vli_size.c
(630 B)
Editing: alone_decoder.c
/////////////////////////////////////////////////////////////////////////////// // /// \file alone_decoder.c /// \brief Decoder for LZMA_Alone files // // Author: Lasse Collin // // This file has been put into the public domain. // You can do whatever you want with this file. // /////////////////////////////////////////////////////////////////////////////// #include "alone_decoder.h" #include "lzma_decoder.h" #include "lz_decoder.h" typedef struct { lzma_next_coder next; enum { SEQ_PROPERTIES, SEQ_DICTIONARY_SIZE, SEQ_UNCOMPRESSED_SIZE, SEQ_CODER_INIT, SEQ_CODE, } sequence; /// If true, reject files that are unlikely to be .lzma files. /// If false, more non-.lzma files get accepted and will give /// LZMA_DATA_ERROR either immediately or after a few output bytes. bool picky; /// Position in the header fields size_t pos; /// Uncompressed size decoded from the header lzma_vli uncompressed_size; /// Memory usage limit uint64_t memlimit; /// Amount of memory actually needed (only an estimate) uint64_t memusage; /// Options decoded from the header needed to initialize /// the LZMA decoder lzma_options_lzma options; } lzma_alone_coder; static lzma_ret alone_decode(void *coder_ptr, const 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) { lzma_alone_coder *coder = coder_ptr; while (*out_pos < out_size && (coder->sequence == SEQ_CODE || *in_pos < in_size)) switch (coder->sequence) { case SEQ_PROPERTIES: if (lzma_lzma_lclppb_decode(&coder->options, in[*in_pos])) return LZMA_FORMAT_ERROR; coder->sequence = SEQ_DICTIONARY_SIZE; ++*in_pos; break; case SEQ_DICTIONARY_SIZE: coder->options.dict_size |= (size_t)(in[*in_pos]) << (coder->pos * 8); if (++coder->pos == 4) { if (coder->picky && coder->options.dict_size != UINT32_MAX) { // A hack to ditch tons of false positives: // We allow only dictionary sizes that are // 2^n or 2^n + 2^(n-1). LZMA_Alone created // only files with 2^n, but accepts any // dictionary size. uint32_t d = coder->options.dict_size - 1; d |= d >> 2; d |= d >> 3; d |= d >> 4; d |= d >> 8; d |= d >> 16; ++d; if (d != coder->options.dict_size) return LZMA_FORMAT_ERROR; } coder->pos = 0; coder->sequence = SEQ_UNCOMPRESSED_SIZE; } ++*in_pos; break; case SEQ_UNCOMPRESSED_SIZE: coder->uncompressed_size |= (lzma_vli)(in[*in_pos]) << (coder->pos * 8); ++*in_pos; if (++coder->pos < 8) break; // Another hack to ditch false positives: Assume that // if the uncompressed size is known, it must be less // than 256 GiB. if (coder->picky && coder->uncompressed_size != LZMA_VLI_UNKNOWN && coder->uncompressed_size >= (LZMA_VLI_C(1) << 38)) return LZMA_FORMAT_ERROR; // Calculate the memory usage so that it is ready // for SEQ_CODER_INIT. coder->memusage = lzma_lzma_decoder_memusage(&coder->options) + LZMA_MEMUSAGE_BASE; coder->pos = 0; coder->sequence = SEQ_CODER_INIT; // Fall through case SEQ_CODER_INIT: { if (coder->memusage > coder->memlimit) return LZMA_MEMLIMIT_ERROR; lzma_filter_info filters[2] = { { .init = &lzma_lzma_decoder_init, .options = &coder->options, }, { .init = NULL, } }; const lzma_ret ret = lzma_next_filter_init(&coder->next, allocator, filters); if (ret != LZMA_OK) return ret; // Use a hack to set the uncompressed size. lzma_lz_decoder_uncompressed(coder->next.coder, coder->uncompressed_size); coder->sequence = SEQ_CODE; break; } case SEQ_CODE: { return coder->next.code(coder->next.coder, allocator, in, in_pos, in_size, out, out_pos, out_size, action); } default: return LZMA_PROG_ERROR; } return LZMA_OK; } static void alone_decoder_end(void *coder_ptr, const lzma_allocator *allocator) { lzma_alone_coder *coder = coder_ptr; lzma_next_end(&coder->next, allocator); lzma_free(coder, allocator); return; } static lzma_ret alone_decoder_memconfig(void *coder_ptr, uint64_t *memusage, uint64_t *old_memlimit, uint64_t new_memlimit) { lzma_alone_coder *coder = coder_ptr; *memusage = coder->memusage; *old_memlimit = coder->memlimit; if (new_memlimit != 0) { if (new_memlimit < coder->memusage) return LZMA_MEMLIMIT_ERROR; coder->memlimit = new_memlimit; } return LZMA_OK; } extern lzma_ret lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator, uint64_t memlimit, bool picky) { lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator); lzma_alone_coder *coder = next->coder; if (coder == NULL) { coder = lzma_alloc(sizeof(lzma_alone_coder), allocator); if (coder == NULL) return LZMA_MEM_ERROR; next->coder = coder; next->code = &alone_decode; next->end = &alone_decoder_end; next->memconfig = &alone_decoder_memconfig; coder->next = LZMA_NEXT_CODER_INIT; } coder->sequence = SEQ_PROPERTIES; coder->picky = picky; coder->pos = 0; coder->options.dict_size = 0; coder->options.preset_dict = NULL; coder->options.preset_dict_size = 0; coder->uncompressed_size = 0; coder->memlimit = my_max(1, memlimit); coder->memusage = LZMA_MEMUSAGE_BASE; return LZMA_OK; } extern LZMA_API(lzma_ret) lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit) { lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit, false); strm->internal->supported_actions[LZMA_RUN] = true; strm->internal->supported_actions[LZMA_FINISH] = true; return LZMA_OK; }
Upload File
Create Folder