Skip to content

Commit 115ff0d

Browse files
committed
lib: miniz: upgrade to b43f8a0c22
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
1 parent 39d5872 commit 115ff0d

File tree

3 files changed

+44
-31
lines changed

3 files changed

+44
-31
lines changed

lib/miniz/VERSION.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
=== Miniz Version ===
22

3-
commit 6b6b27aff222b442fd897fc180400df057c34298
4-
Merge: 3a43b8c f52e09a
3+
commit b43f8a0c22d6bae6b5416264232f57a2aca539fe
4+
Merge: 17d6763 1e8c7ce
55
Author: Martin Raiber <martin@urbackup.org>
6-
Date: Sat Nov 28 10:03:15 2020 +0100
6+
Date: Sun Feb 7 22:03:46 2021 +0100
7+
8+
Merge pull request #147 from andiwand/write-with-dynamic-size
9+
write with dynamic size

lib/miniz/miniz.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
27162716
}
27172717

27182718
dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2719-
if ((dist > dist_from_out_buf_start || dist_from_out_buf_start == 0) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2719+
if ((dist == 0 || dist > dist_from_out_buf_start || dist_from_out_buf_start == 0) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
27202720
{
27212721
TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
27222722
}
@@ -3235,7 +3235,7 @@ struct mz_zip_internal_state_tag
32353235

32363236
#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
32373237

3238-
#if defined(DEBUG) || defined(_DEBUG) || defined(NDEBUG)
3238+
#if defined(DEBUG) || defined(_DEBUG)
32393239
static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(const mz_zip_array *pArray, mz_uint index)
32403240
{
32413241
MZ_ASSERT(index < pArray->m_size);
@@ -6392,13 +6392,13 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
63926392
return MZ_TRUE;
63936393
}
63946394

6395-
mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
6395+
mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
63966396
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
63976397
{
63986398
mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
63996399
mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes;
64006400
mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
6401-
mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0;
6401+
mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0;
64026402
size_t archive_name_size;
64036403
mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
64046404
mz_uint8 *pExtra_data = NULL;
@@ -6420,7 +6420,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
64206420

64216421
pState = pZip->m_pState;
64226422

6423-
if ((!pState->m_zip64) && (uncomp_size > MZ_UINT32_MAX))
6423+
if ((!pState->m_zip64) && (max_size > MZ_UINT32_MAX))
64246424
{
64256425
/* Source file is too large for non-zip64 */
64266426
/*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
@@ -6477,7 +6477,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
64776477
}
64786478
#endif
64796479

6480-
if (uncomp_size <= 3)
6480+
if (max_size <= 3)
64816481
level = 0;
64826482

64836483
if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes))
@@ -6493,19 +6493,19 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
64936493
MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
64946494
}
64956495

6496-
if (uncomp_size && level)
6496+
if (max_size && level)
64976497
{
64986498
method = MZ_DEFLATED;
64996499
}
65006500

65016501
MZ_CLEAR_OBJ(local_dir_header);
65026502
if (pState->m_zip64)
65036503
{
6504-
if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
6504+
if (max_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
65056505
{
65066506
pExtra_data = extra_data;
6507-
extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL,
6508-
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6507+
extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (max_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL,
6508+
(max_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
65096509
}
65106510

65116511
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), 0, 0, 0, method, gen_flags, dos_time, dos_date))
@@ -6556,9 +6556,8 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
65566556
cur_archive_file_ofs += user_extra_data_len;
65576557
}
65586558

6559-
if (uncomp_size)
6559+
if (max_size)
65606560
{
6561-
mz_uint64 uncomp_remaining = uncomp_size;
65626561
void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE);
65636562
if (!pRead_buf)
65646563
{
@@ -6567,19 +6566,27 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
65676566

65686567
if (!level)
65696568
{
6570-
while (uncomp_remaining)
6569+
while (1)
65716570
{
6572-
mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining);
6573-
if ((read_callback(callback_opaque, file_ofs, pRead_buf, n) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n))
6571+
size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE);
6572+
if (n == 0)
6573+
break;
6574+
6575+
if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size))
65746576
{
65756577
pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
65766578
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
65776579
}
6578-
file_ofs += n;
6580+
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)
6581+
{
6582+
pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6583+
return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
6584+
}
6585+
file_ofs += n;
65796586
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n);
6580-
uncomp_remaining -= n;
65816587
cur_archive_file_ofs += n;
65826588
}
6589+
uncomp_size = file_ofs;
65836590
comp_size = uncomp_size;
65846591
}
65856592
else
@@ -6606,24 +6613,26 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
66066613

66076614
for (;;)
66086615
{
6609-
size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
66106616
tdefl_status status;
66116617
tdefl_flush flush = TDEFL_NO_FLUSH;
66126618

6613-
if (read_callback(callback_opaque, file_ofs, pRead_buf, in_buf_size)!= in_buf_size)
6619+
size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE);
6620+
if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size))
66146621
{
66156622
mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
66166623
break;
66176624
}
66186625

6619-
file_ofs += in_buf_size;
6620-
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size);
6621-
uncomp_remaining -= in_buf_size;
6626+
file_ofs += n;
6627+
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n);
66226628

66236629
if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque))
66246630
flush = TDEFL_FULL_FLUSH;
66256631

6626-
status = tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? flush : TDEFL_FINISH);
6632+
if (n == 0)
6633+
flush = TDEFL_FINISH;
6634+
6635+
status = tdefl_compress_buffer(pComp, pRead_buf, n, flush);
66276636
if (status == TDEFL_STATUS_DONE)
66286637
{
66296638
result = MZ_TRUE;
@@ -6644,6 +6653,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
66446653
return MZ_FALSE;
66456654
}
66466655

6656+
uncomp_size = file_ofs;
66476657
comp_size = state.m_comp_size;
66486658
cur_archive_file_ofs = state.m_cur_archive_file_ofs;
66496659
}
@@ -6708,10 +6718,10 @@ static size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *p
67086718
return MZ_FREAD(pBuf, 1, n, pSrc_file);
67096719
}
67106720

6711-
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
6721+
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
67126722
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
67136723
{
6714-
return mz_zip_writer_add_read_buf_callback(pZip, pArchive_name, mz_file_read_func_stdio, pSrc_file, size_to_add, pFile_time, pComment, comment_size, level_and_flags,
6724+
return mz_zip_writer_add_read_buf_callback(pZip, pArchive_name, mz_file_read_func_stdio, pSrc_file, max_size, pFile_time, pComment, comment_size, level_and_flags,
67156725
user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len);
67166726
}
67176727

lib/miniz/miniz.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ enum
221221
#define MZ_DEFLATED 8
222222

223223
/* Heap allocation callbacks.
224-
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
224+
Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */
225225
typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
226226
typedef void (*mz_free_func)(void *opaque, void *address);
227227
typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
@@ -1290,7 +1290,7 @@ MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const cha
12901290

12911291
/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */
12921292
/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
1293-
MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 size_to_add,
1293+
MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size,
12941294
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
12951295
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
12961296

@@ -1300,7 +1300,7 @@ MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, c
13001300
MINIZ_EXPORT mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
13011301

13021302
/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
1303-
MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add,
1303+
MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size,
13041304
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
13051305
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
13061306
#endif

0 commit comments

Comments
 (0)