4 void *tinfl_decompress_mem_to_heap(const void *, size_t, size_t *, int);
11 typedef unsigned char mz_uint8
;
12 typedef signed short mz_int16
;
13 typedef unsigned short mz_uint16
;
14 typedef unsigned int mz_uint32
;
15 typedef unsigned int mz_uint
;
16 typedef int64_t mz_int64
;
17 typedef uint64_t mz_uint64
;
20 typedef mz_uint32 tinfl_bit_buf_t
;
21 #define TINFL_BITBUF_SIZE (32)
25 TINFL_MAX_HUFF_TABLES
= 3,
26 TINFL_MAX_HUFF_SYMBOLS_0
= 288,
27 TINFL_MAX_HUFF_SYMBOLS_1
= 32,
28 TINFL_MAX_HUFF_SYMBOLS_2
= 19,
29 TINFL_FAST_LOOKUP_BITS
= 10,
30 TINFL_FAST_LOOKUP_SIZE
= 1 << TINFL_FAST_LOOKUP_BITS
33 struct tinfl_decompressor_tag
;
34 typedef struct tinfl_decompressor_tag tinfl_decompressor
;
35 struct tinfl_decompressor_tag
37 mz_uint32 m_state
, m_num_bits
, m_zhdr0
, m_zhdr1
, m_z_adler32
, m_final
, m_type
, m_check_adler32
, m_dist
, m_counter
, m_num_extra
, m_table_sizes
[TINFL_MAX_HUFF_TABLES
];
38 tinfl_bit_buf_t m_bit_buf
;
39 size_t m_dist_from_out_buf_start
;
40 mz_int16 m_look_up
[TINFL_MAX_HUFF_TABLES
][TINFL_FAST_LOOKUP_SIZE
];
41 mz_int16 m_tree_0
[TINFL_MAX_HUFF_SYMBOLS_0
* 2];
42 mz_int16 m_tree_1
[TINFL_MAX_HUFF_SYMBOLS_1
* 2];
43 mz_int16 m_tree_2
[TINFL_MAX_HUFF_SYMBOLS_2
* 2];
44 mz_uint8 m_code_size_0
[TINFL_MAX_HUFF_SYMBOLS_0
];
45 mz_uint8 m_code_size_1
[TINFL_MAX_HUFF_SYMBOLS_1
];
46 mz_uint8 m_code_size_2
[TINFL_MAX_HUFF_SYMBOLS_2
];
47 mz_uint8 m_raw_header
[4], m_len_codes
[TINFL_MAX_HUFF_SYMBOLS_0
+ TINFL_MAX_HUFF_SYMBOLS_1
+ 137];
50 #define MZ_MALLOC(x) malloc(x)
51 #define MZ_FREE(x) free(x)
52 #define MZ_REALLOC(p, x) realloc(p, x)
54 #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
55 #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
56 #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
57 #define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
58 #define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
62 /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
63 /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
64 /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
65 TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS
= -4,
67 /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
68 TINFL_STATUS_BAD_PARAM
= -3,
70 /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
71 TINFL_STATUS_ADLER32_MISMATCH
= -2,
73 /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
74 TINFL_STATUS_FAILED
= -1,
76 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
78 /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
79 /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
80 TINFL_STATUS_DONE
= 0,
82 /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
83 /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
84 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
85 TINFL_STATUS_NEEDS_MORE_INPUT
= 1,
87 /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
88 /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
89 /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
90 /* so I may need to add some code to address this. */
91 TINFL_STATUS_HAS_MORE_OUTPUT
= 2
94 /* Decompression flags used by tinfl_decompress(). */
95 /* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
96 /* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */
97 /* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */
98 /* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
101 TINFL_FLAG_PARSE_ZLIB_HEADER
= 1,
102 TINFL_FLAG_HAS_MORE_INPUT
= 2,
103 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF
= 4,
104 TINFL_FLAG_COMPUTE_ADLER32
= 8
107 #define MZ_MACRO_END while (0)
108 #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U))
109 #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U))
111 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
115 #define MZ_ASSERT(X) assert(X)
120 /* Initializes the decompressor to its initial state. */
121 #define tinfl_init(r) \
128 typedef int (*tinfl_put_buf_func_ptr
)(const void *pBuf
, int len
, void *pUser
);
130 /* Max size of LZ dictionary. */
131 #define TINFL_LZ_DICT_SIZE 32768