From f4a1823837092fe05a8ca2a8fce917358462ade6 Mon Sep 17 00:00:00 2001 From: r-lyeh Date: Tue, 6 Oct 2015 20:21:15 +0200 Subject: [PATCH] alignment fix #46; see log: ``` D:\commit\miniz>zipalign.exe -c -v 4 __mz_example2_test__.zip Verifying alignment of __mz_example2_test__.zip (4)... 36 49.txt (OK - compressed) 639 48.txt (OK - compressed) 1243 47.txt (OK - compressed) 1847 46.txt (OK - compressed) 2451 45.txt (OK - compressed) 3054 44.txt (OK - compressed) 3657 43.txt (OK - compressed) 4261 42.txt (OK - compressed) 4865 41.txt (OK - compressed) 5469 40.txt (OK - compressed) 6072 39.txt (OK - compressed) 6676 38.txt (OK - compressed) 7281 37.txt (OK - compressed) 7886 36.txt (OK - compressed) 8491 35.txt (OK - compressed) 9096 34.txt (OK - compressed) 9701 33.txt (OK - compressed) 10306 32.txt (OK - compressed) 10911 31.txt (OK - compressed) 11516 30.txt (OK - compressed) 12120 29.txt (OK - compressed) 12723 28.txt (OK - compressed) 13327 27.txt (OK - compressed) 13931 26.txt (OK - compressed) 14536 25.txt (OK - compressed) 15141 24.txt (OK - compressed) 15746 23.txt (OK - compressed) 16351 22.txt (OK - compressed) 16955 21.txt (OK - compressed) 17559 20.txt (OK - compressed) 18162 19.txt (OK - compressed) 18766 18.txt (OK - compressed) 19371 17.txt (OK - compressed) 19976 16.txt (OK - compressed) 20581 15.txt (OK - compressed) 21186 14.txt (OK - compressed) 21791 13.txt (OK - compressed) 22396 12.txt (OK - compressed) 23001 11.txt (OK - compressed) 23606 10.txt (OK - compressed) 24209 9.txt (OK - compressed) 24811 8.txt (OK - compressed) 25414 7.txt (OK - compressed) 26017 6.txt (OK - compressed) 26620 5.txt (OK - compressed) 27222 4.txt (OK - compressed) 27824 3.txt (OK - compressed) 28427 2.txt (OK - compressed) 29030 1.txt (OK - compressed) 29633 0.txt (OK - compressed) 30240 directory/ (OK) Verification succesful ``` --- miniz.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/miniz.c b/miniz.c index 358143a..4cc583c 100644 --- a/miniz.c +++ b/miniz.c @@ -7,6 +7,7 @@ MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros). * Change History + 8/04/14 v1.15 r6 - Bugfixed data alignment (@r-lyeh) 10/13/13 v1.15 r4 - Interim bugfix release while I work on the next major release with Zip64 support (almost there!): - Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug would only have occured in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place() @@ -27,7 +28,7 @@ - Added example6.c, which dumps an image of the mandelbrot set to a PNG file. - Modified example2 to help test the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY flag more. - In r3: Bugfix to mz_zip_writer_add_file() found during merge: Fix possible src file fclose() leak if alignment bytes+local header file write faiiled - - In r4: Minor bugfix to mz_zip_writer_add_from_zip_reader(): Was pushing the wrong central dir header offset, appears harmless in this release, but it became a problem in the zip64 branch + - In r4: Minor bugfix to mz_zip_writer_add_from_zip_reader(): Was pushing the wrong central dir header offset, appears harmless in this release, but it became a problem in the zip64 branch 5/20/12 v1.14 - MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include (thanks fermtect). 5/19/12 v1.13 - From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit. - Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files. @@ -4323,13 +4324,20 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name return MZ_FALSE; } + /* align file offset (@r-lyeh) { */ + { + mz_uint offset = cur_archive_file_ofs + sizeof(local_dir_header) + archive_name_size + comment_size; + num_alignment_padding_bytes = pZip->m_file_offset_alignment ? (pZip->m_file_offset_alignment - (offset & (pZip->m_file_offset_alignment - 1))) % pZip->m_file_offset_alignment : 0; + } + /* } align file offset (@r-lyeh) */ + if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header))) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); return MZ_FALSE; } local_dir_header_ofs += num_alignment_padding_bytes; - if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); } + /* if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); } */ cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header); MZ_CLEAR_OBJ(local_dir_header);