miniz updates:

- update from mainstream master to fix mainstream PR/159#issuecomment-1046220324
- fixes by Alice Rowan for mainstream issue 220
This commit is contained in:
Ozkan Sezer 2022-03-01 11:56:10 +03:00
parent 14b7338946
commit b76d5e1b9f

View file

@ -321,9 +321,20 @@ extern "C" {
sym = temp; \
bit_buf >>= code_len; \
num_bits -= code_len; \
code_len_hack = code_len; /* FIXME: workaround for miniz/#229 */ \
} \
MZ_MACRO_END
static void tinfl_clear_tree(tinfl_decompressor *r)
{
if (r->m_type == 0)
MZ_CLEAR_ARR(r->m_tree_0);
else if (r->m_type == 1)
MZ_CLEAR_ARR(r->m_tree_1);
else
MZ_CLEAR_ARR(r->m_tree_2);
}
tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
{
static const mz_uint16 s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
@ -432,6 +443,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
}
else
{
mz_uint code_len_hack; /* FIXME: workaround for miniz/#229 */
if (r->m_type == 1)
{
mz_uint8 *p = r->m_code_size_0;
@ -476,7 +488,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
pCode_size = pCode_sizes[r->m_type];
MZ_CLEAR_ARR(total_syms);
TINFL_MEMSET(pLookUp, 0, sizeof(r->m_look_up[0]));
TINFL_MEMSET(pTree, 0, r->m_table_sizes[r->m_type] * sizeof(pTree[0]) * 2);
tinfl_clear_tree(r);
for (i = 0; i < r->m_table_sizes[r->m_type]; ++i)
total_syms[pCode_size[i]]++;
used_syms = 0, total = 0;
@ -567,6 +579,9 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
{
TINFL_HUFF_DECODE(23, counter, r->m_look_up[0], r->m_tree_0);
/* FIXME: workaround for miniz/#229 */
if (!code_len_hack)
TINFL_CR_RETURN_FOREVER(101, TINFL_STATUS_FAILED);
if (counter >= 256)
break;
while (pOut_buf_cur >= pOut_buf_end)
@ -604,6 +619,9 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)];
} while (sym2 < 0);
}
/* FIXME: workaround for miniz/#229 */
if (!code_len)
TINFL_CR_RETURN_FOREVER(100, TINFL_STATUS_FAILED);
counter = sym2;
bit_buf >>= code_len;
num_bits -= code_len;