Reputation: 995
I need to use the miniz library for decompressing some zip files in my project. The problem is that the function
tinfl_decompress
always exits with status TINFL_STATUS_FAILED
.
I have done some debugging and found out the offending lines of code in miniz.c:
line 1452:
counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
counter is set to 1;
line 1453:
if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
(((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))))
evaluates to false; however since counter is set to 1, counter remains equal to 1.
line 1454:
if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); }
since the counter value is 1 the macro TINFL_CR_RETURN_FOREVER is called. Such macro jumps to the label common_exit
.
Apart from inside my project, I have tested the miniz library with the examples provided with the libary. Specifically, I have tried to decompress both my own personal zip archives as well as the one generated by the example2 included with the miniz library with example5.
Issuing the folling command at the command prompt
example5.exe d __mz_example2_test__.zip __mz_example2_test__.decompress
generates the following output:
miniz.c example5 (demonstrates tinfl/tdefl)
Mode: d, Level: 9
Input File: "__mz_example2_test__.zip"
Output File: "__mz_example2_test__.decompress"
Input file size: 33768
tinfl_decompress() failed with status -1!
How can I fix this? What am I doing wrong?
Upvotes: 0
Views: 1878
Reputation: 112502
Line 1452 is looking for a zlib header. The zlib format is not the zip format. You would need to write your own zip format decoder and then use miniz in a raw inflate mode which does not look for a zlib header but instead decodes raw deflate data at the location you found by decoding the zip headers.
Or you could just use libzip, which does all that for you.
Upvotes: 1