X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Flzx-decompress.c;h=456602675a718478dea825693fdd89588efb293b;hb=f3bfbdd5c07b4b096a2e8a35a03e9dfc6269e41f;hp=da462186c06870b2038098bc0b3aab97dc6dd229;hpb=a3bb2e86f2640f5d593d00250a627d3dcc9747a2;p=wimlib diff --git a/src/lzx-decompress.c b/src/lzx-decompress.c index da462186..45660267 100644 --- a/src/lzx-decompress.c +++ b/src/lzx-decompress.c @@ -107,6 +107,7 @@ */ #include "util.h" +#include "wimlib.h" #include "lzx.h" #include "decompress.h" #include @@ -326,7 +327,7 @@ lzx_read_block_header(struct input_bitstream *istream, unsigned len; ret = bitstream_ensure_bits(istream, 4); - if (ret != 0) { + if (ret) { ERROR("LZX input stream overrun"); return ret; } @@ -344,7 +345,7 @@ lzx_read_block_header(struct input_bitstream *istream, block_size = 32768; } else { ret = bitstream_read_bits(istream, 16, &block_size); - if (ret != 0) + if (ret) return ret; block_size = le16_to_cpu(block_size); } @@ -358,7 +359,7 @@ lzx_read_block_header(struct input_bitstream *istream, ret = bitstream_read_bits(istream, LZX_ALIGNEDTREE_ELEMENT_SIZE, &len); - if (ret != 0) + if (ret) return ret; tables->alignedtree_lens[i] = len; } @@ -369,7 +370,7 @@ lzx_read_block_header(struct input_bitstream *istream, LZX_ALIGNEDTREE_TABLEBITS, tables->alignedtree_lens, 8); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to make the decode " "table for the aligned offset tree"); return ret; @@ -387,7 +388,7 @@ lzx_read_block_header(struct input_bitstream *istream, * tree. */ ret = lzx_read_code_lens(istream, tables->maintree_lens, LZX_NUM_CHARS); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to read the code " "lengths for the first 256 elements of the " "main tree"); @@ -402,7 +403,7 @@ lzx_read_block_header(struct input_bitstream *istream, ret = lzx_read_code_lens(istream, tables->maintree_lens + LZX_NUM_CHARS, LZX_MAINTREE_NUM_SYMBOLS - LZX_NUM_CHARS); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to read the path " "lengths for the remaining elements of the main " "tree"); @@ -417,7 +418,7 @@ lzx_read_block_header(struct input_bitstream *istream, LZX_MAINTREE_TABLEBITS, tables->maintree_lens, LZX_MAX_CODEWORD_LEN); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to make the decode " "table for the main tree"); return ret; @@ -426,7 +427,7 @@ lzx_read_block_header(struct input_bitstream *istream, LZX_DEBUG("Reading path lengths for the length tree."); ret = lzx_read_code_lens(istream, tables->lentree_lens, LZX_LENTREE_NUM_SYMBOLS); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to read the path " "lengths for the length tree"); return ret; @@ -438,7 +439,7 @@ lzx_read_block_header(struct input_bitstream *istream, LZX_LENTREE_TABLEBITS, tables->lentree_lens, LZX_MAX_CODEWORD_LEN); - if (ret != 0) { + if (ret) { ERROR("lzx_decompress(): Failed to build the length " "Huffman tree"); return ret; @@ -455,13 +456,19 @@ lzx_read_block_header(struct input_bitstream *istream, * *already* aligned, the correct thing to do is to throw away * the next 16 bits. */ if (istream->bitsleft == 0) { - if (istream->data_bytes_left < 14) + if (istream->data_bytes_left < 14) { + ERROR("lzx_decompress(): Insufficient length in " + "uncompressed block"); return -1; + } istream->data += 2; istream->data_bytes_left -= 2; } else { - if (istream->data_bytes_left < 12) + if (istream->data_bytes_left < 12) { + ERROR("lzx_decompress(): Insufficient length in " + "uncompressed block"); return -1; + } istream->bitsleft = 0; istream->bitbuf = 0; } @@ -762,7 +769,7 @@ lzx_decompress_block(int block_type, unsigned block_size, while (window_pos < end) { ret = read_huffsym_using_maintree(istream, tables, &main_element); - if (ret != 0) + if (ret) return ret; if (main_element < LZX_NUM_CHARS) { @@ -786,27 +793,10 @@ lzx_decompress_block(int block_type, unsigned block_size, return 0; } -/* - * Decompresses a block of LZX-compressed data as used in the WIM file format. - * - * Note that this will NOT work unmodified for LZX as used in the cabinet - * format, which is not the same as in the WIM format! - * - * @compressed_data: A pointer to the compressed data. - * - * @compressed_len: The length of the compressed data, in bytes. - * - * @uncompressed_data: A pointer to the buffer into which to write the - * uncompressed data. - * - * @uncompressed_len: The length of the uncompressed data. It must be - * 32768 bytes or less. - * - * Return 0 on success; non-zero on failure. - */ -int -lzx_decompress(const void *compressed_data, unsigned compressed_len, - void *uncompressed_data, unsigned uncompressed_len) +/* Documented in wimlib.h */ +WIMLIBAPI int +wimlib_lzx_decompress(const void *compressed_data, unsigned compressed_len, + void *uncompressed_data, unsigned uncompressed_len) { struct lzx_tables tables; struct input_bitstream istream; @@ -846,7 +836,7 @@ lzx_decompress(const void *compressed_data, unsigned compressed_len, LZX_DEBUG("Reading block header."); ret = lzx_read_block_header(&istream, &block_size, &block_type, &tables, &queue); - if (ret != 0) + if (ret) return ret; LZX_DEBUG("block_size = %u, window_pos = %u", @@ -873,7 +863,7 @@ lzx_decompress(const void *compressed_data, unsigned compressed_len, &tables, &queue, &istream); - if (ret != 0) + if (ret) return ret; if (tables.maintree_lens[0xe8] != 0) e8_preprocessing_done = true;