👷 Upgrade miniz to 2.1.0
This commit is contained in:
parent
cba048da4c
commit
380aa4457e
5 changed files with 174 additions and 69 deletions
|
@ -1,16 +1,31 @@
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### 2.1.0
|
||||||
|
|
||||||
|
- More instances of memcpy instead of cast and use memcpy per default
|
||||||
|
- Remove inline for c90 support
|
||||||
|
- New function to read files via callback functions when adding them
|
||||||
|
- Fix out of bounds read while reading Zip64 extended information
|
||||||
|
- guard memcpy when n == 0 because buffer may be NULL
|
||||||
|
- Implement inflateReset() function
|
||||||
|
- Move comp/decomp alloc/free prototypes under guarding #ifndef MZ_NO_MALLOC
|
||||||
|
- Fix large file support under Windows
|
||||||
|
- Don't warn if _LARGEFILE64_SOURCE is not defined to 1
|
||||||
|
- Fixes for MSVC warnings
|
||||||
|
- Remove check that path of file added to archive contains ':' or '\'
|
||||||
|
- Add !defined check on MINIZ_USE_ALIGNED_LOADS_AND_STORES
|
||||||
|
|
||||||
### 2.0.8
|
### 2.0.8
|
||||||
|
|
||||||
- Remove unimplemented functions (mz_zip_locate_file and mz_zip_locate_file_v2)
|
- Remove unimplemented functions (mz_zip_locate_file and mz_zip_locate_file_v2)
|
||||||
- Add license, changelog, readme and example files to release zip
|
- Add license, changelog, readme and example files to release zip
|
||||||
- Fix heap overflow to user buffer in tinfl_status tinfl_decompress
|
- Fix heap overflow to user buffer in tinfl_status tinfl_decompress
|
||||||
- Fix corrupt archive if uncompressed file smaller than 4 byte and file is added by mz_zip_writer_add_mem*
|
- Fix corrupt archive if uncompressed file smaller than 4 byte and the file is added by mz_zip_writer_add_mem*
|
||||||
|
|
||||||
### 2.0.7
|
### 2.0.7
|
||||||
|
|
||||||
- Removed need in C++ compiler in cmake build
|
- Removed need in C++ compiler in cmake build
|
||||||
- Fixed loads of uninitilized value errors found with Valgrind by memsetting m_dict to 0 in tdefl_init.
|
- Fixed a lot of uninitialized value errors found with Valgrind by memsetting m_dict to 0 in tdefl_init
|
||||||
- Fix resource leak in mz_zip_reader_init_file_v2
|
- Fix resource leak in mz_zip_reader_init_file_v2
|
||||||
- Fix assert with mz_zip_writer_add_mem* w/MZ_DEFAULT_COMPRESSION
|
- Fix assert with mz_zip_writer_add_mem* w/MZ_DEFAULT_COMPRESSION
|
||||||
- cmake build: install library and headers
|
- cmake build: install library and headers
|
||||||
|
@ -19,7 +34,7 @@
|
||||||
### 2.0.6
|
### 2.0.6
|
||||||
|
|
||||||
- Improve MZ_ZIP_FLAG_WRITE_ZIP64 documentation
|
- Improve MZ_ZIP_FLAG_WRITE_ZIP64 documentation
|
||||||
- Remove check for cur_archive_file_ofs > UINT_MAX, because cur_archive_file_ofs is not used after this point
|
- Remove check for cur_archive_file_ofs > UINT_MAX because cur_archive_file_ofs is not used after this point
|
||||||
- Add cmake debug configuration
|
- Add cmake debug configuration
|
||||||
- Fix PNG height when creating png files
|
- Fix PNG height when creating png files
|
||||||
- Add "iterative" file extraction method based on mz_zip_reader_extract_to_callback.
|
- Add "iterative" file extraction method based on mz_zip_reader_extract_to_callback.
|
||||||
|
@ -49,11 +64,12 @@
|
||||||
|
|
||||||
### 2.0.0 beta
|
### 2.0.0 beta
|
||||||
|
|
||||||
- Matthew Sitton merged to vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed
|
- Matthew Sitton merged miniz 1.x to Rich Geldreich's vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed
|
||||||
- Miniz is now split into several files
|
- Miniz is now split into several files
|
||||||
- Miniz does now not seek backwards when creating ZIP files. That is the ZIP files can be streamed
|
- Miniz does now not seek backwards when creating ZIP files. That is the ZIP files can be streamed
|
||||||
- Miniz automatically switches to the ZIP64 format the created ZIP files goes over ZIP file limits
|
- Miniz automatically switches to the ZIP64 format when the created ZIP files goes over ZIP file limits
|
||||||
- Similar to [SQLite](https://www.sqlite.org/amalgamation.html) the Miniz source code is amalgamated into one miniz.c/miniz.h pair in a build step (amalgamate.sh). Please use miniz.c/miniz.h in your projects
|
- Similar to [SQLite](https://www.sqlite.org/amalgamation.html) the Miniz source code is amalgamated into one miniz.c/miniz.h pair in a build step (amalgamate.sh). Please use miniz.c/miniz.h in your projects
|
||||||
|
- Miniz 2 is only source back-compatible with miniz 1.x. It breaks binary compatibility because structures changed
|
||||||
|
|
||||||
### v1.16 BETA Oct 19, 2013
|
### v1.16 BETA Oct 19, 2013
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "miniz.h"
|
#include "miniz.h"
|
||||||
#include "miniz_zip.h"
|
|
||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
typedef unsigned short uint16;
|
typedef unsigned short uint16;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
@ -18,26 +17,6 @@ static const char *s_pStr = "Good morning Dr. Chandra. This is Hal. I am ready f
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
{
|
|
||||||
mz_zip_archive zip_archive;
|
|
||||||
memset(&zip_archive, 0, sizeof(zip_archive)); // mz_zip_archive contains a bunch of pointers. set all to nullptr
|
|
||||||
mz_bool status = mz_zip_writer_init(&zip_archive, 0);
|
|
||||||
if (!status)
|
|
||||||
return;
|
|
||||||
|
|
||||||
status = mz_zip_writer_add_file(&zip_archive, "Images.zip", "Images/title.png", NULL, 0, MZ_DEFAULT_COMPRESSION);
|
|
||||||
if (!status)
|
|
||||||
return;
|
|
||||||
|
|
||||||
status = mz_zip_writer_finalize_archive(&zip_archive);
|
|
||||||
if (!status)
|
|
||||||
return;
|
|
||||||
|
|
||||||
status = mz_zip_writer_end(&zip_archive);
|
|
||||||
if (!status)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint step = 0;
|
uint step = 0;
|
||||||
int cmp_status;
|
int cmp_status;
|
||||||
uLong src_len = (uLong)strlen(s_pStr);
|
uLong src_len = (uLong)strlen(s_pStr);
|
||||||
|
|
|
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
|
||||||
// Add a new file to the archive. Note this is an IN-PLACE operation, so if it fails your archive is probably hosed (its central directory may not be complete) but it should be recoverable using zip -F or -FF. So use caution with this guy.
|
// Add a new file to the archive. Note this is an IN-PLACE operation, so if it fails your archive is probably hosed (its central directory may not be complete) but it should be recoverable using zip -F or -FF. So use caution with this guy.
|
||||||
// A more robust way to add a file to an archive would be to read it into memory, perform the operation, then write a new archive out to a temp file and then delete/rename the files.
|
// A more robust way to add a file to an archive would be to read it into memory, perform the operation, then write a new archive out to a temp file and then delete/rename the files.
|
||||||
// Or, write a new archive to disk to a temp file, then delete/rename the files. For this test this API is fine.
|
// Or, write a new archive to disk to a temp file, then delete/rename the files. For this test this API is fine.
|
||||||
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, archive_filename, data, 2, s_pComment, (uint16)strlen(s_pComment), MZ_BEST_COMPRESSION);
|
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, archive_filename, data, strlen(data) + 1, s_pComment, (uint16)strlen(s_pComment), MZ_BEST_COMPRESSION);
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
||||||
|
|
|
@ -397,6 +397,32 @@ int mz_inflateInit(mz_streamp pStream)
|
||||||
return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
|
return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mz_inflateReset(mz_streamp pStream)
|
||||||
|
{
|
||||||
|
inflate_state *pDecomp;
|
||||||
|
if (!pStream)
|
||||||
|
return MZ_STREAM_ERROR;
|
||||||
|
|
||||||
|
pStream->data_type = 0;
|
||||||
|
pStream->adler = 0;
|
||||||
|
pStream->msg = NULL;
|
||||||
|
pStream->total_in = 0;
|
||||||
|
pStream->total_out = 0;
|
||||||
|
pStream->reserved = 0;
|
||||||
|
|
||||||
|
pDecomp = (inflate_state *)pStream->state;
|
||||||
|
|
||||||
|
tinfl_init(&pDecomp->m_decomp);
|
||||||
|
pDecomp->m_dict_ofs = 0;
|
||||||
|
pDecomp->m_dict_avail = 0;
|
||||||
|
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
|
||||||
|
pDecomp->m_first_call = 1;
|
||||||
|
pDecomp->m_has_flushed = 0;
|
||||||
|
/* pDecomp->m_window_bits = window_bits */;
|
||||||
|
|
||||||
|
return MZ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int mz_inflate(mz_streamp pStream, int flush)
|
int mz_inflate(mz_streamp pStream, int flush)
|
||||||
{
|
{
|
||||||
inflate_state *pState;
|
inflate_state *pState;
|
||||||
|
@ -1340,13 +1366,13 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush)
|
||||||
|
|
||||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
|
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
|
||||||
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
||||||
static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p)
|
static mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p)
|
||||||
{
|
{
|
||||||
mz_uint16 ret;
|
mz_uint16 ret;
|
||||||
memcpy(&ret, p, sizeof(mz_uint16));
|
memcpy(&ret, p, sizeof(mz_uint16));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p)
|
static mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p)
|
||||||
{
|
{
|
||||||
mz_uint16 ret;
|
mz_uint16 ret;
|
||||||
memcpy(&ret, p, sizeof(mz_uint16));
|
memcpy(&ret, p, sizeof(mz_uint16));
|
||||||
|
@ -1455,6 +1481,16 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe
|
||||||
#endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES */
|
#endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES */
|
||||||
|
|
||||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
||||||
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
||||||
|
static mz_uint32 TDEFL_READ_UNALIGNED_WORD32(const mz_uint8* p)
|
||||||
|
{
|
||||||
|
mz_uint32 ret;
|
||||||
|
memcpy(&ret, p, sizeof(mz_uint32));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define TDEFL_READ_UNALIGNED_WORD32(p) *(const mz_uint32 *)(p)
|
||||||
|
#endif
|
||||||
static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
||||||
{
|
{
|
||||||
/* Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. */
|
/* Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. */
|
||||||
|
@ -1489,12 +1525,12 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
||||||
{
|
{
|
||||||
mz_uint cur_match_dist, cur_match_len = 1;
|
mz_uint cur_match_dist, cur_match_len = 1;
|
||||||
mz_uint8 *pCur_dict = d->m_dict + cur_pos;
|
mz_uint8 *pCur_dict = d->m_dict + cur_pos;
|
||||||
mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF;
|
mz_uint first_trigram = TDEFL_READ_UNALIGNED_WORD32(pCur_dict) & 0xFFFFFF;
|
||||||
mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
|
mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
|
||||||
mz_uint probe_pos = d->m_hash[hash];
|
mz_uint probe_pos = d->m_hash[hash];
|
||||||
d->m_hash[hash] = (mz_uint16)lookahead_pos;
|
d->m_hash[hash] = (mz_uint16)lookahead_pos;
|
||||||
|
|
||||||
if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
|
if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((TDEFL_READ_UNALIGNED_WORD32(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
|
||||||
{
|
{
|
||||||
const mz_uint16 *p = (const mz_uint16 *)pCur_dict;
|
const mz_uint16 *p = (const mz_uint16 *)pCur_dict;
|
||||||
const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos);
|
const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos);
|
||||||
|
@ -1524,7 +1560,11 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d)
|
||||||
cur_match_dist--;
|
cur_match_dist--;
|
||||||
|
|
||||||
pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
|
pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
|
||||||
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
||||||
|
memcpy(&pLZ_code_buf[1], &cur_match_dist, sizeof(cur_match_dist));
|
||||||
|
#else
|
||||||
*(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
|
*(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
|
||||||
|
#endif
|
||||||
pLZ_code_buf += 3;
|
pLZ_code_buf += 3;
|
||||||
*pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80);
|
*pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80);
|
||||||
|
|
||||||
|
@ -2143,6 +2183,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h,
|
||||||
return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE);
|
return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MINIZ_NO_MALLOC
|
||||||
/* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */
|
/* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */
|
||||||
/* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */
|
/* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */
|
||||||
/* structure size and allocation mechanism. */
|
/* structure size and allocation mechanism. */
|
||||||
|
@ -2155,6 +2196,7 @@ void tdefl_compressor_free(tdefl_compressor *pComp)
|
||||||
{
|
{
|
||||||
MZ_FREE(pComp);
|
MZ_FREE(pComp);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
@ -2688,8 +2730,12 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
|
||||||
const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
|
const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
#ifdef MINIZ_UNALIGNED_USE_MEMCPY
|
||||||
|
memcpy(pOut_buf_cur, pSrc, sizeof(mz_uint32)*2);
|
||||||
|
#else
|
||||||
((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
|
((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
|
||||||
((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
|
((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
|
||||||
|
#endif
|
||||||
pOut_buf_cur += 8;
|
pOut_buf_cur += 8;
|
||||||
} while ((pSrc += 8) < pSrc_end);
|
} while ((pSrc += 8) < pSrc_end);
|
||||||
if ((counter &= 7) < 3)
|
if ((counter &= 7) < 3)
|
||||||
|
@ -2881,6 +2927,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MINIZ_NO_MALLOC
|
||||||
tinfl_decompressor *tinfl_decompressor_alloc()
|
tinfl_decompressor *tinfl_decompressor_alloc()
|
||||||
{
|
{
|
||||||
tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor));
|
tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor));
|
||||||
|
@ -2893,6 +2940,7 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
|
||||||
{
|
{
|
||||||
MZ_FREE(pDecomp);
|
MZ_FREE(pDecomp);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -2961,8 +3009,8 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
#define MZ_FWRITE fwrite
|
#define MZ_FWRITE fwrite
|
||||||
#define MZ_FTELL64 _ftelli64
|
#define MZ_FTELL64 _ftelli64
|
||||||
#define MZ_FSEEK64 _fseeki64
|
#define MZ_FSEEK64 _fseeki64
|
||||||
#define MZ_FILE_STAT_STRUCT _stat
|
#define MZ_FILE_STAT_STRUCT _stat64
|
||||||
#define MZ_FILE_STAT _stat
|
#define MZ_FILE_STAT _stat64
|
||||||
#define MZ_FFLUSH fflush
|
#define MZ_FFLUSH fflush
|
||||||
#define MZ_FREOPEN mz_freopen
|
#define MZ_FREOPEN mz_freopen
|
||||||
#define MZ_DELETE_FILE remove
|
#define MZ_DELETE_FILE remove
|
||||||
|
@ -2996,7 +3044,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
#define MZ_FFLUSH fflush
|
#define MZ_FFLUSH fflush
|
||||||
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
|
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
|
||||||
#define MZ_DELETE_FILE remove
|
#define MZ_DELETE_FILE remove
|
||||||
#elif defined(__GNUC__) && _LARGEFILE64_SOURCE
|
#elif defined(__GNUC__) && defined(_LARGEFILE64_SOURCE)
|
||||||
#ifndef MINIZ_NO_TIME
|
#ifndef MINIZ_NO_TIME
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -3250,7 +3298,8 @@ static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zi
|
||||||
size_t orig_size = pArray->m_size;
|
size_t orig_size = pArray->m_size;
|
||||||
if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE))
|
if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
|
if (n > 0)
|
||||||
|
memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3647,21 +3696,47 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag
|
||||||
|
|
||||||
if (extra_size_remaining)
|
if (extra_size_remaining)
|
||||||
{
|
{
|
||||||
const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size;
|
const mz_uint8 *pExtra_data;
|
||||||
|
void* buf = NULL;
|
||||||
|
|
||||||
|
if (MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + ext_data_size > n)
|
||||||
|
{
|
||||||
|
buf = MZ_MALLOC(ext_data_size);
|
||||||
|
if(buf==NULL)
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
|
||||||
|
|
||||||
|
if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size, buf, ext_data_size) != ext_data_size)
|
||||||
|
{
|
||||||
|
MZ_FREE(buf);
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
pExtra_data = (mz_uint8*)buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
mz_uint32 field_id;
|
mz_uint32 field_id;
|
||||||
mz_uint32 field_data_size;
|
mz_uint32 field_data_size;
|
||||||
|
|
||||||
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
|
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
{
|
||||||
|
MZ_FREE(buf);
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||||
|
}
|
||||||
|
|
||||||
field_id = MZ_READ_LE16(pExtra_data);
|
field_id = MZ_READ_LE16(pExtra_data);
|
||||||
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
||||||
|
|
||||||
if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
|
if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
{
|
||||||
|
MZ_FREE(buf);
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||||
|
}
|
||||||
|
|
||||||
if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
|
if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
|
||||||
{
|
{
|
||||||
|
@ -3674,6 +3749,8 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag
|
||||||
pExtra_data += sizeof(mz_uint16) * 2 + field_data_size;
|
pExtra_data += sizeof(mz_uint16) * 2 + field_data_size;
|
||||||
extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size;
|
extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size;
|
||||||
} while (extra_size_remaining);
|
} while (extra_size_remaining);
|
||||||
|
|
||||||
|
MZ_FREE(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4870,7 +4947,7 @@ size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState,
|
||||||
if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))
|
if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))
|
||||||
{
|
{
|
||||||
/* The file is stored or the caller has requested the compressed data, calc amount to return. */
|
/* The file is stored or the caller has requested the compressed data, calc amount to return. */
|
||||||
copied_to_caller = MZ_MIN( buf_size, pState->comp_remaining );
|
copied_to_caller = (size_t)MZ_MIN( buf_size, pState->comp_remaining );
|
||||||
|
|
||||||
/* Zip is in memory....or requires reading from a file? */
|
/* Zip is in memory....or requires reading from a file? */
|
||||||
if (pState->pZip->m_pState->m_pMem)
|
if (pState->pZip->m_pState->m_pMem)
|
||||||
|
@ -5947,7 +6024,7 @@ static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char
|
||||||
if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + user_extra_data_len + comment_size) >= MZ_UINT32_MAX)
|
if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + user_extra_data_len + comment_size) >= MZ_UINT32_MAX)
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
|
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
|
||||||
|
|
||||||
if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size + user_extra_data_len, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes))
|
if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, (mz_uint16)(extra_size + user_extra_data_len), comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
||||||
|
|
||||||
if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) ||
|
if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) ||
|
||||||
|
@ -5971,13 +6048,7 @@ static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name)
|
||||||
if (*pArchive_name == '/')
|
if (*pArchive_name == '/')
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
|
||||||
while (*pArchive_name)
|
/* Making sure the name does not contain drive letters or DOS style backward slashes is the responsibility of the program using miniz*/
|
||||||
{
|
|
||||||
if ((*pArchive_name == '\\') || (*pArchive_name == ':'))
|
|
||||||
return MZ_FALSE;
|
|
||||||
|
|
||||||
pArchive_name++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -6168,7 +6239,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||||
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
|
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, bit_flags, dos_time, dos_date))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
||||||
|
|
||||||
if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
||||||
|
@ -6195,7 +6266,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||||
{
|
{
|
||||||
if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
|
if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
|
return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
|
||||||
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
|
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
||||||
|
|
||||||
if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
||||||
|
@ -6288,7 +6359,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||||
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment,
|
if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, (mz_uint16)extra_size, pComment,
|
||||||
comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
|
comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
|
||||||
user_extra_data_central, user_extra_data_central_len))
|
user_extra_data_central, user_extra_data_central_len))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
@ -6299,8 +6370,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MINIZ_NO_STDIO
|
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,
|
||||||
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,
|
|
||||||
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
|
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
|
||||||
{
|
{
|
||||||
mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
|
mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
|
||||||
|
@ -6313,6 +6383,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
mz_uint32 extra_size = 0;
|
mz_uint32 extra_size = 0;
|
||||||
mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
|
mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
|
||||||
mz_zip_internal_state *pState;
|
mz_zip_internal_state *pState;
|
||||||
|
mz_uint64 file_ofs = 0;
|
||||||
|
|
||||||
if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME))
|
if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME))
|
||||||
gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
|
gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
|
||||||
|
@ -6368,7 +6439,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
if (!pState->m_zip64)
|
if (!pState->m_zip64)
|
||||||
{
|
{
|
||||||
/* Bail early if the archive would obviously become too large */
|
/* Bail early if the archive would obviously become too large */
|
||||||
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
|
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
|
||||||
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
|
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
|
||||||
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
|
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
|
@ -6415,7 +6486,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
|
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))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
||||||
|
|
||||||
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
||||||
|
@ -6439,7 +6510,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
{
|
{
|
||||||
if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
|
if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
|
return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
|
||||||
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
|
if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
|
||||||
|
|
||||||
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
|
||||||
|
@ -6477,11 +6548,12 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
while (uncomp_remaining)
|
while (uncomp_remaining)
|
||||||
{
|
{
|
||||||
mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining);
|
mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining);
|
||||||
if ((MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n))
|
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))
|
||||||
{
|
{
|
||||||
pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
|
pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
||||||
}
|
}
|
||||||
|
file_ofs += n;
|
||||||
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n);
|
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n);
|
||||||
uncomp_remaining -= n;
|
uncomp_remaining -= n;
|
||||||
cur_archive_file_ofs += n;
|
cur_archive_file_ofs += n;
|
||||||
|
@ -6516,12 +6588,13 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
tdefl_status status;
|
tdefl_status status;
|
||||||
tdefl_flush flush = TDEFL_NO_FLUSH;
|
tdefl_flush flush = TDEFL_NO_FLUSH;
|
||||||
|
|
||||||
if (MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size)
|
if (read_callback(callback_opaque, file_ofs, pRead_buf, in_buf_size)!= in_buf_size)
|
||||||
{
|
{
|
||||||
mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_ofs += in_buf_size;
|
||||||
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size);
|
uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size);
|
||||||
uncomp_remaining -= in_buf_size;
|
uncomp_remaining -= in_buf_size;
|
||||||
|
|
||||||
|
@ -6589,7 +6662,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
(uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment, comment_size,
|
if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, (mz_uint16)extra_size, pComment, comment_size,
|
||||||
uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
|
uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
|
||||||
user_extra_data_central, user_extra_data_central_len))
|
user_extra_data_central, user_extra_data_central_len))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
@ -6600,6 +6673,26 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
|
||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MINIZ_NO_STDIO
|
||||||
|
|
||||||
|
static size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
|
||||||
|
{
|
||||||
|
MZ_FILE *pSrc_file = (MZ_FILE *)pOpaque;
|
||||||
|
mz_int64 cur_ofs = MZ_FTELL64(pSrc_file);
|
||||||
|
|
||||||
|
if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pSrc_file, (mz_int64)file_ofs, SEEK_SET))))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return MZ_FREAD(pBuf, 1, n, pSrc_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
MZ_FILE *pSrc_file = NULL;
|
MZ_FILE *pSrc_file = NULL;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* miniz.c 2.0.8 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
/* miniz.c 2.1.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
||||||
See "unlicense" statement at the end of this file.
|
See "unlicense" statement at the end of this file.
|
||||||
Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
|
Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
|
||||||
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
zlib replacement in many apps:
|
zlib replacement in many apps:
|
||||||
The z_stream struct, optional memory allocation callbacks
|
The z_stream struct, optional memory allocation callbacks
|
||||||
deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
|
deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
|
||||||
inflateInit/inflateInit2/inflate/inflateEnd
|
inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
|
||||||
compress, compress2, compressBound, uncompress
|
compress, compress2, compressBound, uncompress
|
||||||
CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
|
CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
|
||||||
Supports raw deflate streams or standard zlib streams with adler-32 checking.
|
Supports raw deflate streams or standard zlib streams with adler-32 checking.
|
||||||
|
@ -170,12 +170,16 @@
|
||||||
#define MINIZ_LITTLE_ENDIAN 0
|
#define MINIZ_LITTLE_ENDIAN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */
|
||||||
|
#if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES)
|
||||||
#if MINIZ_X86_OR_X64_CPU
|
#if MINIZ_X86_OR_X64_CPU
|
||||||
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
|
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
|
||||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
|
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
|
||||||
|
#define MINIZ_UNALIGNED_USE_MEMCPY
|
||||||
#else
|
#else
|
||||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
|
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
|
#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
|
||||||
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */
|
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */
|
||||||
|
@ -234,11 +238,11 @@ enum
|
||||||
MZ_DEFAULT_COMPRESSION = -1
|
MZ_DEFAULT_COMPRESSION = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MZ_VERSION "10.0.3"
|
#define MZ_VERSION "10.1.0"
|
||||||
#define MZ_VERNUM 0xA030
|
#define MZ_VERNUM 0xA100
|
||||||
#define MZ_VER_MAJOR 10
|
#define MZ_VER_MAJOR 10
|
||||||
#define MZ_VER_MINOR 0
|
#define MZ_VER_MINOR 1
|
||||||
#define MZ_VER_REVISION 3
|
#define MZ_VER_REVISION 0
|
||||||
#define MZ_VER_SUBREVISION 0
|
#define MZ_VER_SUBREVISION 0
|
||||||
|
|
||||||
#ifndef MINIZ_NO_ZLIB_APIS
|
#ifndef MINIZ_NO_ZLIB_APIS
|
||||||
|
@ -361,6 +365,9 @@ int mz_inflateInit(mz_streamp pStream);
|
||||||
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
|
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
|
||||||
int mz_inflateInit2(mz_streamp pStream, int window_bits);
|
int mz_inflateInit2(mz_streamp pStream, int window_bits);
|
||||||
|
|
||||||
|
/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
|
||||||
|
int mz_inflateReset(mz_streamp pStream);
|
||||||
|
|
||||||
/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */
|
/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */
|
||||||
/* Parameters: */
|
/* Parameters: */
|
||||||
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
||||||
|
@ -444,6 +451,7 @@ typedef void *const voidpc;
|
||||||
#define compressBound mz_compressBound
|
#define compressBound mz_compressBound
|
||||||
#define inflateInit mz_inflateInit
|
#define inflateInit mz_inflateInit
|
||||||
#define inflateInit2 mz_inflateInit2
|
#define inflateInit2 mz_inflateInit2
|
||||||
|
#define inflateReset mz_inflateReset
|
||||||
#define inflate mz_inflate
|
#define inflate mz_inflate
|
||||||
#define inflateEnd mz_inflateEnd
|
#define inflateEnd mz_inflateEnd
|
||||||
#define uncompress mz_uncompress
|
#define uncompress mz_uncompress
|
||||||
|
@ -737,11 +745,13 @@ mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
|
||||||
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
|
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
|
||||||
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
|
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
|
||||||
|
|
||||||
|
#ifndef MINIZ_NO_MALLOC
|
||||||
/* Allocate the tdefl_compressor structure in C so that */
|
/* Allocate the tdefl_compressor structure in C so that */
|
||||||
/* non-C language bindings to tdefl_ API don't need to worry about */
|
/* non-C language bindings to tdefl_ API don't need to worry about */
|
||||||
/* structure size and allocation mechanism. */
|
/* structure size and allocation mechanism. */
|
||||||
tdefl_compressor *tdefl_compressor_alloc();
|
tdefl_compressor *tdefl_compressor_alloc(void);
|
||||||
void tdefl_compressor_free(tdefl_compressor *pComp);
|
void tdefl_compressor_free(tdefl_compressor *pComp);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -789,12 +799,13 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
|
||||||
struct tinfl_decompressor_tag;
|
struct tinfl_decompressor_tag;
|
||||||
typedef struct tinfl_decompressor_tag tinfl_decompressor;
|
typedef struct tinfl_decompressor_tag tinfl_decompressor;
|
||||||
|
|
||||||
|
#ifndef MINIZ_NO_MALLOC
|
||||||
/* Allocate the tinfl_decompressor structure in C so that */
|
/* Allocate the tinfl_decompressor structure in C so that */
|
||||||
/* non-C language bindings to tinfl_ API don't need to worry about */
|
/* non-C language bindings to tinfl_ API don't need to worry about */
|
||||||
/* structure size and allocation mechanism. */
|
/* structure size and allocation mechanism. */
|
||||||
|
tinfl_decompressor *tinfl_decompressor_alloc(void);
|
||||||
tinfl_decompressor *tinfl_decompressor_alloc();
|
|
||||||
void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
|
void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Max size of LZ dictionary. */
|
/* Max size of LZ dictionary. */
|
||||||
#define TINFL_LZ_DICT_SIZE 32768
|
#define TINFL_LZ_DICT_SIZE 32768
|
||||||
|
@ -1269,6 +1280,12 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||||
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||||
|
|
||||||
|
/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */
|
||||||
|
/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
|
||||||
|
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, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||||
|
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||||
|
|
||||||
#ifndef MINIZ_NO_STDIO
|
#ifndef MINIZ_NO_STDIO
|
||||||
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
||||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||||
|
|
Loading…
Reference in a new issue