X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flzms_decompress.c;h=4dd36627b37957faae16a14f639f27bf313e9f20;hb=754936f4654fae549d0fb6586c1f4cfea7e732d9;hp=4791054a7f468202d21e97d60fe830cc0667ee03;hpb=908381d2809a48acd9490ec080e51087ae1529fd;p=wimlib diff --git a/src/lzms_decompress.c b/src/lzms_decompress.c index 4791054a..4dd36627 100644 --- a/src/lzms_decompress.c +++ b/src/lzms_decompress.c @@ -348,7 +348,12 @@ struct lzms_decompressor { u32 delta_power_freqs[LZMS_NUM_DELTA_POWER_SYMS]; struct lzms_huffman_rebuild_info delta_power_rebuild_info; - u32 codewords[LZMS_MAX_NUM_SYMS]; + /* Temporary space for lzms_build_huffman_code() */ + union { + u32 codewords[LZMS_MAX_NUM_SYMS]; + DECODE_TABLE_WORKING_SPACE(working_space, LZMS_MAX_NUM_SYMS, + LZMS_MAX_CODEWORD_LENGTH); + }; }; // struct @@ -371,7 +376,7 @@ lzms_input_bitstream_init(struct lzms_input_bitstream *is, /* Ensure that at least @num_bits bits are in the bitbuffer variable. * @num_bits cannot be more than 32. */ -static inline void +static forceinline void lzms_ensure_bits(struct lzms_input_bitstream *is, unsigned num_bits) { unsigned avail; @@ -403,14 +408,14 @@ lzms_ensure_bits(struct lzms_input_bitstream *is, unsigned num_bits) } /* Get @num_bits bits from the bitbuffer variable. */ -static inline bitbuf_t +static forceinline bitbuf_t lzms_peek_bits(struct lzms_input_bitstream *is, unsigned num_bits) { return (is->bitbuf >> 1) >> (BITBUF_NBITS - num_bits - 1); } /* Remove @num_bits bits from the bitbuffer variable. */ -static inline void +static forceinline void lzms_remove_bits(struct lzms_input_bitstream *is, unsigned num_bits) { is->bitbuf <<= num_bits; @@ -418,7 +423,7 @@ lzms_remove_bits(struct lzms_input_bitstream *is, unsigned num_bits) } /* Remove and return @num_bits bits from the bitbuffer variable. */ -static inline bitbuf_t +static forceinline bitbuf_t lzms_pop_bits(struct lzms_input_bitstream *is, unsigned num_bits) { bitbuf_t bits = lzms_peek_bits(is, num_bits); @@ -427,7 +432,7 @@ lzms_pop_bits(struct lzms_input_bitstream *is, unsigned num_bits) } /* Read @num_bits bits from the input bitstream. */ -static inline bitbuf_t +static forceinline bitbuf_t lzms_read_bits(struct lzms_input_bitstream *is, unsigned num_bits) { lzms_ensure_bits(is, num_bits); @@ -452,7 +457,7 @@ lzms_range_decoder_init(struct lzms_range_decoder *rd, * probability entry to use. The state and probability entry will be updated * based on the decoded bit. */ -static inline int +static forceinline int lzms_decode_bit(struct lzms_range_decoder *rd, u32 *state_p, u32 num_states, struct lzms_probability_entry *probs) { @@ -517,7 +522,8 @@ lzms_build_huffman_code(struct lzms_huffman_rebuild_info *rebuild_info) rebuild_info->num_syms, rebuild_info->table_bits, (u8 *)rebuild_info->decode_table, - LZMS_MAX_CODEWORD_LENGTH); + LZMS_MAX_CODEWORD_LENGTH, + (u16 *)rebuild_info->codewords); rebuild_info->num_syms_until_rebuild = rebuild_info->rebuild_freq; } @@ -591,7 +597,7 @@ lzms_rebuild_huffman_code(struct lzms_huffman_rebuild_info *rebuild_info) /* XXX: mostly copied from read_huffsym() in decompress_common.h because LZMS * needs its own bitstream */ -static inline unsigned +static forceinline unsigned lzms_decode_huffman_symbol(struct lzms_input_bitstream *is, u16 decode_table[], unsigned table_bits, u32 freqs[], struct lzms_huffman_rebuild_info *rebuild_info) @@ -621,7 +627,7 @@ lzms_decode_huffman_symbol(struct lzms_input_bitstream *is, u16 decode_table[], return symbol; } -static inline unsigned +static forceinline unsigned lzms_decode_literal(struct lzms_decompressor *d, struct lzms_input_bitstream *is) { @@ -632,7 +638,7 @@ lzms_decode_literal(struct lzms_decompressor *d, &d->literal_rebuild_info); } -static inline u32 +static forceinline u32 lzms_decode_lz_offset(struct lzms_decompressor *d, struct lzms_input_bitstream *is) { @@ -645,7 +651,7 @@ lzms_decode_lz_offset(struct lzms_decompressor *d, lzms_read_bits(is, lzms_extra_offset_bits[slot]); } -static inline u32 +static forceinline u32 lzms_decode_length(struct lzms_decompressor *d, struct lzms_input_bitstream *is) { @@ -662,7 +668,7 @@ lzms_decode_length(struct lzms_decompressor *d, return length; } -static inline u32 +static forceinline u32 lzms_decode_delta_offset(struct lzms_decompressor *d, struct lzms_input_bitstream *is) { @@ -675,7 +681,7 @@ lzms_decode_delta_offset(struct lzms_decompressor *d, lzms_read_bits(is, lzms_extra_offset_bits[slot]); } -static inline unsigned +static forceinline unsigned lzms_decode_delta_power(struct lzms_decompressor *d, struct lzms_input_bitstream *is) { @@ -822,12 +828,10 @@ lzms_decompress(const void * const restrict in, const size_t in_nbytes, length = lzms_decode_length(d, &is); - if (unlikely(length > out_end - out_next)) - return -1; - if (unlikely(offset > out_next - (u8 *)out)) + if (unlikely(lz_copy(length, offset, out, out_next, out_end, + LZMS_MIN_MATCH_LENGTH))) return -1; - lz_copy(out_next, length, offset, out_end, LZMS_MIN_MATCH_LENGTH); out_next += length; } else { /* Delta match */