Skip to content

Commit ca47ca2

Browse files
committed
lib: miniz: upgade to GIT version 6b6b27a
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
1 parent 90b2354 commit ca47ca2

File tree

3 files changed

+177
-141
lines changed

3 files changed

+177
-141
lines changed

lib/miniz/VERSION.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== Miniz Version ===
2+
3+
commit 6b6b27aff222b442fd897fc180400df057c34298
4+
Merge: 3a43b8c f52e09a
5+
Author: Martin Raiber <martin@urbackup.org>
6+
Date: Sat Nov 28 10:03:15 2020 +0100

lib/miniz/miniz.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "miniz.h"
12
/**************************************************************************
23
*
34
* Copyright 2013-2014 RAD Game Tools and Valve Software
@@ -24,7 +25,7 @@
2425
*
2526
**************************************************************************/
2627

27-
#include "miniz.h"
28+
2829

2930
typedef unsigned char mz_validate_uint16[sizeof(mz_uint16) == 2 ? 1 : -1];
3031
typedef unsigned char mz_validate_uint32[sizeof(mz_uint32) == 4 ? 1 : -1];
@@ -82,6 +83,12 @@ mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
8283
}
8384
return ~crcu32;
8485
}
86+
#elif defined(USE_EXTERNAL_MZCRC)
87+
/* If USE_EXTERNAL_CRC is defined, an external module will export the
88+
* mz_crc32() symbol for us to use, e.g. an SSE-accelerated version.
89+
* Depending on the impl, it may be necessary to ~ the input/output crc values.
90+
*/
91+
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len);
8592
#else
8693
/* Faster, but larger CPU cache footprint.
8794
*/
@@ -157,17 +164,17 @@ void mz_free(void *p)
157164
MZ_FREE(p);
158165
}
159166

160-
void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
167+
MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
161168
{
162169
(void)opaque, (void)items, (void)size;
163170
return MZ_MALLOC(items * size);
164171
}
165-
void miniz_def_free_func(void *opaque, void *address)
172+
MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address)
166173
{
167174
(void)opaque, (void)address;
168175
MZ_FREE(address);
169176
}
170-
void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
177+
MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
171178
{
172179
(void)opaque, (void)address, (void)items, (void)size;
173180
return MZ_REALLOC(address, items * size);
@@ -546,19 +553,18 @@ int mz_inflateEnd(mz_streamp pStream)
546553
}
547554
return MZ_OK;
548555
}
549-
550-
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
556+
int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
551557
{
552558
mz_stream stream;
553559
int status;
554560
memset(&stream, 0, sizeof(stream));
555561

556562
/* In case mz_ulong is 64-bits (argh I hate longs). */
557-
if ((source_len | *pDest_len) > 0xFFFFFFFFU)
563+
if ((*pSource_len | *pDest_len) > 0xFFFFFFFFU)
558564
return MZ_PARAM_ERROR;
559565

560566
stream.next_in = pSource;
561-
stream.avail_in = (mz_uint32)source_len;
567+
stream.avail_in = (mz_uint32)*pSource_len;
562568
stream.next_out = pDest;
563569
stream.avail_out = (mz_uint32)*pDest_len;
564570

@@ -567,6 +573,7 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
567573
return status;
568574

569575
status = mz_inflate(&stream, MZ_FINISH);
576+
*pSource_len = *pSource_len - stream.avail_in;
570577
if (status != MZ_STREAM_END)
571578
{
572579
mz_inflateEnd(&stream);
@@ -577,6 +584,11 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
577584
return mz_inflateEnd(&stream);
578585
}
579586

587+
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
588+
{
589+
return mz_uncompress2(pDest, pDest_len, pSource, &source_len);
590+
}
591+
580592
const char *mz_error(int err)
581593
{
582594
static struct
@@ -654,7 +666,6 @@ const char *mz_error(int err)
654666

655667

656668

657-
658669
#ifdef __cplusplus
659670
extern "C" {
660671
#endif
@@ -2205,7 +2216,7 @@ void tdefl_compressor_free(tdefl_compressor *pComp)
22052216
#ifdef __cplusplus
22062217
}
22072218
#endif
2208-
/**************************************************************************
2219+
/**************************************************************************
22092220
*
22102221
* Copyright 2013-2014 RAD Game Tools and Valve Software
22112222
* Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
@@ -2705,7 +2716,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
27052716
}
27062717

27072718
dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2708-
if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2719+
if ((dist > dist_from_out_buf_start || dist_from_out_buf_start == 0) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
27092720
{
27102721
TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
27112722
}
@@ -2945,7 +2956,7 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
29452956
#ifdef __cplusplus
29462957
}
29472958
#endif
2948-
/**************************************************************************
2959+
/**************************************************************************
29492960
*
29502961
* Copyright 2013-2014 RAD Game Tools and Valve Software
29512962
* Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
@@ -3044,7 +3055,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
30443055
#define MZ_FFLUSH fflush
30453056
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
30463057
#define MZ_DELETE_FILE remove
3047-
#elif defined(__GNUC__) && defined(_LARGEFILE64_SOURCE)
3058+
#elif defined(__USE_LARGEFILE64) /* gcc, clang */
30483059
#ifndef MINIZ_NO_TIME
30493060
#include <utime.h>
30503061
#endif
@@ -4592,7 +4603,9 @@ void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFile
45924603
mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
45934604
{
45944605
int status = TINFL_STATUS_DONE;
4606+
#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
45954607
mz_uint file_crc32 = MZ_CRC32_INIT;
4608+
#endif
45964609
mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
45974610
mz_zip_archive_file_stat file_stat;
45984611
void *pRead_buf = NULL;
@@ -4888,7 +4901,7 @@ mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive
48884901
if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
48894902
{
48904903
/* Decompression required, therefore intermediate read buffer required */
4891-
pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE);
4904+
pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
48924905
if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)pState->read_buf_size)))
48934906
{
48944907
mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
@@ -5246,7 +5259,10 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
52465259
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
52475260

52485261
if (!mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE))
5249-
return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
5262+
{
5263+
mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
5264+
goto handle_failure;
5265+
}
52505266

52515267
if (local_header_filename_len)
52525268
{
@@ -5280,14 +5296,20 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
52805296
mz_uint32 field_id, field_data_size, field_total_size;
52815297

52825298
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
5283-
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
5299+
{
5300+
mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
5301+
goto handle_failure;
5302+
}
52845303

52855304
field_id = MZ_READ_LE16(pExtra_data);
52865305
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
52875306
field_total_size = field_data_size + sizeof(mz_uint16) * 2;
52885307

52895308
if (field_total_size > extra_size_remaining)
5290-
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
5309+
{
5310+
mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
5311+
goto handle_failure;
5312+
}
52915313

52925314
if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
52935315
{

0 commit comments

Comments
 (0)