richgel999/miniz

Broken zip files since 2.2.0

kim2048 opened this issue · 0 comments

Hi,
I have noticed that my zip files can no longer be opened properly with "7zip" since created with miniz 2.2.0 (only the first file is visible, no sizes set - and it reports a data error when pressing "test"). And unzip reports an error as well.

I binary compared the 2.2.0 zip file with the 2.1.0 and the only difference is, that in the 2.2.0 version, the "general purpose bit flag" is 0 instead of 8 (= sizes stored in the data descriptor).

My creation code looks like this:

mz_zip_archive archive;
mz_zip_writer_init_heap( &archive, 0u, 0u );
mz_zip_writer_add_file( &archive, "test1.dat", "c:\\test.dat", nullptr, 0u, (mz_uint)MZ_DEFAULT_COMPRESSION );
mz_zip_writer_add_file( &archive, "test2.dat", "c:\\test.dat", nullptr, 0u, (mz_uint)MZ_DEFAULT_COMPRESSION );
mz_zip_writer_add_file( &archive, "test3.dat", "c:\\test.dat", nullptr, 0u, (mz_uint)MZ_DEFAULT_COMPRESSION );
mz_zip_writer_finalize_heap_archive( &archive, &pData, &dataSize );
mz_zip_writer_end( &archive );

When I use mz_zip_writer_add_mem instead of mz_zip_writer_add_file the flag is set to 8 and everything is okay.

It looks like the line *d->m_pLZ_flags = 0; in tdefl_compress_buffer is causing this behaviour (it's the only change between 2.1.0 and 2.2.0 where flags are involved).