Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_miniz Namespace Reference

Classes

struct  mz_stream_s
struct  mz_dummy_time_t_tag
struct  tdefl_compressor
struct  tinfl_huff_table
struct  tinfl_decompressor_tag
struct  mz_zip_archive_file_stat
struct  mz_zip_archive
struct  mz_zip_reader_extract_iter_state
struct  inflate_state
struct  tdefl_sym_freq
struct  tdefl_output_buffer
struct  mz_zip_array
struct  mz_zip_internal_state_tag
struct  mz_zip_writer_add_state

Typedefs

typedef unsigned long mz_ulong
typedef void *(* mz_alloc_func) (void *opaque, size_t items, size_t size)
typedef void(* mz_free_func) (void *opaque, void *address)
typedef void *(* mz_realloc_func) (void *opaque, void *address, size_t items, size_t size)
typedef struct duckdb_miniz::mz_stream_s mz_stream
typedef mz_stream * mz_streamp
typedef unsigned char mz_uint8
typedef signed short mz_int16
typedef unsigned short mz_uint16
typedef unsigned int mz_uint32
typedef unsigned int mz_uint
typedef int64_t mz_int64
typedef uint64_t mz_uint64
typedef int mz_bool
typedef struct duckdb_miniz::mz_dummy_time_t_tag mz_dummy_time_t
typedef mz_bool(* tdefl_put_buf_func_ptr) (const void *pBuf, int len, void *pUser)
typedef int(* tinfl_put_buf_func_ptr) (const void *pBuf, int len, void *pUser)
typedef struct tinfl_decompressor_tag tinfl_decompressor
typedef mz_uint32 tinfl_bit_buf_t
typedef size_t(* mz_file_read_func) (void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
typedef size_t(* mz_file_write_func) (void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
typedef mz_bool(* mz_file_needs_keepalive) (void *pOpaque)
typedef struct mz_zip_internal_state_tag mz_zip_internal_state
typedef unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 :-1]
typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 :-1]
typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 :-1]

Enumerations

enum  {
  MZ_DEFAULT_STRATEGY = 0 , MZ_FILTERED = 1 , MZ_HUFFMAN_ONLY = 2 , MZ_RLE = 3 ,
  MZ_FIXED = 4
}
enum  {
  MZ_NO_COMPRESSION = 0 , MZ_BEST_SPEED = 1 , MZ_BEST_COMPRESSION = 9 , MZ_UBER_COMPRESSION = 10 ,
  MZ_DEFAULT_LEVEL = 6 , MZ_DEFAULT_COMPRESSION = -1
}
enum  {
  MZ_NO_FLUSH = 0 , MZ_PARTIAL_FLUSH = 1 , MZ_SYNC_FLUSH = 2 , MZ_FULL_FLUSH = 3 ,
  MZ_FINISH = 4 , MZ_BLOCK = 5
}
enum  {
  MZ_OK = 0 , MZ_STREAM_END = 1 , MZ_NEED_DICT = 2 , MZ_ERRNO = -1 ,
  MZ_STREAM_ERROR = -2 , MZ_DATA_ERROR = -3 , MZ_MEM_ERROR = -4 , MZ_BUF_ERROR = -5 ,
  MZ_VERSION_ERROR = -6 , MZ_PARAM_ERROR = -10000
}
enum  { TDEFL_HUFFMAN_ONLY = 0 , TDEFL_DEFAULT_MAX_PROBES = 128 , TDEFL_MAX_PROBES_MASK = 0xFFF }
enum  {
  TDEFL_WRITE_ZLIB_HEADER = 0x01000 , TDEFL_COMPUTE_ADLER32 = 0x02000 , TDEFL_GREEDY_PARSING_FLAG = 0x04000 , TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000 ,
  TDEFL_RLE_MATCHES = 0x10000 , TDEFL_FILTER_MATCHES = 0x20000 , TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000 , TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
}
enum  {
  TDEFL_MAX_HUFF_TABLES = 3 , TDEFL_MAX_HUFF_SYMBOLS_0 = 288 , TDEFL_MAX_HUFF_SYMBOLS_1 = 32 , TDEFL_MAX_HUFF_SYMBOLS_2 = 19 ,
  TDEFL_LZ_DICT_SIZE = 32768 , TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1 , TDEFL_MIN_MATCH_LEN = 3 , TDEFL_MAX_MATCH_LEN = 258
}
enum  {
  TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024 , TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10 , TDEFL_MAX_HUFF_SYMBOLS = 288 , TDEFL_LZ_HASH_BITS = 15 ,
  TDEFL_LEVEL1_HASH_SIZE_MASK = 4095 , TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3 , TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
}
enum  tdefl_status { TDEFL_STATUS_BAD_PARAM = -2 , TDEFL_STATUS_PUT_BUF_FAILED = -1 , TDEFL_STATUS_OKAY = 0 , TDEFL_STATUS_DONE = 1 }
enum  tdefl_flush { TDEFL_NO_FLUSH = 0 , TDEFL_SYNC_FLUSH = 2 , TDEFL_FULL_FLUSH = 3 , TDEFL_FINISH = 4 }
enum  { TINFL_FLAG_PARSE_ZLIB_HEADER = 1 , TINFL_FLAG_HAS_MORE_INPUT = 2 , TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4 , TINFL_FLAG_COMPUTE_ADLER32 = 8 }
enum  tinfl_status {
  TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4 , TINFL_STATUS_BAD_PARAM = -3 , TINFL_STATUS_ADLER32_MISMATCH = -2 , TINFL_STATUS_FAILED = -1 ,
  TINFL_STATUS_DONE = 0 , TINFL_STATUS_NEEDS_MORE_INPUT = 1 , TINFL_STATUS_HAS_MORE_OUTPUT = 2
}
enum  {
  TINFL_MAX_HUFF_TABLES = 3 , TINFL_MAX_HUFF_SYMBOLS_0 = 288 , TINFL_MAX_HUFF_SYMBOLS_1 = 32 , TINFL_MAX_HUFF_SYMBOLS_2 = 19 ,
  TINFL_FAST_LOOKUP_BITS = 10 , TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
}
enum  { MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024 , MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512 , MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512 }
enum  mz_zip_mode { MZ_ZIP_MODE_INVALID = 0 , MZ_ZIP_MODE_READING = 1 , MZ_ZIP_MODE_WRITING = 2 , MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3 }
enum  mz_zip_flags {
  MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100 , MZ_ZIP_FLAG_IGNORE_PATH = 0x0200 , MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400 , MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800 ,
  MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000 , MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000 , MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000 , MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000 ,
  MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000
}
enum  mz_zip_type {
  MZ_ZIP_TYPE_INVALID = 0 , MZ_ZIP_TYPE_USER , MZ_ZIP_TYPE_MEMORY , MZ_ZIP_TYPE_HEAP ,
  MZ_ZIP_TYPE_FILE , MZ_ZIP_TYPE_CFILE , MZ_ZIP_TOTAL_TYPES
}
enum  mz_zip_error {
  MZ_ZIP_NO_ERROR = 0 , MZ_ZIP_UNDEFINED_ERROR , MZ_ZIP_TOO_MANY_FILES , MZ_ZIP_FILE_TOO_LARGE ,
  MZ_ZIP_UNSUPPORTED_METHOD , MZ_ZIP_UNSUPPORTED_ENCRYPTION , MZ_ZIP_UNSUPPORTED_FEATURE , MZ_ZIP_FAILED_FINDING_CENTRAL_DIR ,
  MZ_ZIP_NOT_AN_ARCHIVE , MZ_ZIP_INVALID_HEADER_OR_CORRUPTED , MZ_ZIP_UNSUPPORTED_MULTIDISK , MZ_ZIP_DECOMPRESSION_FAILED ,
  MZ_ZIP_COMPRESSION_FAILED , MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE , MZ_ZIP_CRC_CHECK_FAILED , MZ_ZIP_UNSUPPORTED_CDIR_SIZE ,
  MZ_ZIP_ALLOC_FAILED , MZ_ZIP_FILE_OPEN_FAILED , MZ_ZIP_FILE_CREATE_FAILED , MZ_ZIP_FILE_WRITE_FAILED ,
  MZ_ZIP_FILE_READ_FAILED , MZ_ZIP_FILE_CLOSE_FAILED , MZ_ZIP_FILE_SEEK_FAILED , MZ_ZIP_FILE_STAT_FAILED ,
  MZ_ZIP_INVALID_PARAMETER , MZ_ZIP_INVALID_FILENAME , MZ_ZIP_BUF_TOO_SMALL , MZ_ZIP_INTERNAL_ERROR ,
  MZ_ZIP_FILE_NOT_FOUND , MZ_ZIP_ARCHIVE_TOO_LARGE , MZ_ZIP_VALIDATION_FAILED , MZ_ZIP_WRITE_CALLBACK_FAILED ,
  MZ_ZIP_TOTAL_ERRORS
}
enum  { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 }
enum  {
  MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06054b50 , MZ_ZIP_CENTRAL_DIR_HEADER_SIG = 0x02014b50 , MZ_ZIP_LOCAL_DIR_HEADER_SIG = 0x04034b50 , MZ_ZIP_LOCAL_DIR_HEADER_SIZE = 30 ,
  MZ_ZIP_CENTRAL_DIR_HEADER_SIZE = 46 , MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE = 22 , MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06064b50 , MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 0x07064b50 ,
  MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE = 56 , MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE = 20 , MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID = 0x0001 , MZ_ZIP_DATA_DESCRIPTOR_ID = 0x08074b50 ,
  MZ_ZIP_DATA_DESCRIPTER_SIZE64 = 24 , MZ_ZIP_DATA_DESCRIPTER_SIZE32 = 16 , MZ_ZIP_CDH_SIG_OFS = 0 , MZ_ZIP_CDH_VERSION_MADE_BY_OFS = 4 ,
  MZ_ZIP_CDH_VERSION_NEEDED_OFS = 6 , MZ_ZIP_CDH_BIT_FLAG_OFS = 8 , MZ_ZIP_CDH_METHOD_OFS = 10 , MZ_ZIP_CDH_FILE_TIME_OFS = 12 ,
  MZ_ZIP_CDH_FILE_DATE_OFS = 14 , MZ_ZIP_CDH_CRC32_OFS = 16 , MZ_ZIP_CDH_COMPRESSED_SIZE_OFS = 20 , MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS = 24 ,
  MZ_ZIP_CDH_FILENAME_LEN_OFS = 28 , MZ_ZIP_CDH_EXTRA_LEN_OFS = 30 , MZ_ZIP_CDH_COMMENT_LEN_OFS = 32 , MZ_ZIP_CDH_DISK_START_OFS = 34 ,
  MZ_ZIP_CDH_INTERNAL_ATTR_OFS = 36 , MZ_ZIP_CDH_EXTERNAL_ATTR_OFS = 38 , MZ_ZIP_CDH_LOCAL_HEADER_OFS = 42 , MZ_ZIP_LDH_SIG_OFS = 0 ,
  MZ_ZIP_LDH_VERSION_NEEDED_OFS = 4 , MZ_ZIP_LDH_BIT_FLAG_OFS = 6 , MZ_ZIP_LDH_METHOD_OFS = 8 , MZ_ZIP_LDH_FILE_TIME_OFS = 10 ,
  MZ_ZIP_LDH_FILE_DATE_OFS = 12 , MZ_ZIP_LDH_CRC32_OFS = 14 , MZ_ZIP_LDH_COMPRESSED_SIZE_OFS = 18 , MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22 ,
  MZ_ZIP_LDH_FILENAME_LEN_OFS = 26 , MZ_ZIP_LDH_EXTRA_LEN_OFS = 28 , MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR = 1 << 3 , MZ_ZIP_ECDH_SIG_OFS = 0 ,
  MZ_ZIP_ECDH_NUM_THIS_DISK_OFS = 4 , MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS = 6 , MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 8 , MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS = 10 ,
  MZ_ZIP_ECDH_CDIR_SIZE_OFS = 12 , MZ_ZIP_ECDH_CDIR_OFS_OFS = 16 , MZ_ZIP_ECDH_COMMENT_SIZE_OFS = 20 , MZ_ZIP64_ECDL_SIG_OFS = 0 ,
  MZ_ZIP64_ECDL_NUM_DISK_CDIR_OFS = 4 , MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS = 8 , MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS = 16 , MZ_ZIP64_ECDH_SIG_OFS = 0 ,
  MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS = 4 , MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS = 12 , MZ_ZIP64_ECDH_VERSION_NEEDED_OFS = 14 , MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS = 16 ,
  MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS = 20 , MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 24 , MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS = 32 , MZ_ZIP64_ECDH_CDIR_SIZE_OFS = 40 ,
  MZ_ZIP64_ECDH_CDIR_OFS_OFS = 48 , MZ_ZIP_VERSION_MADE_BY_DOS_FILESYSTEM_ID = 0 , MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG = 0x10 , MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED = 1 ,
  MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG = 32 , MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION = 64 , MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED = 8192 , MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 = 1 << 11
}

Functions

void mz_free (void *p)
mz_ulong mz_adler32 (mz_ulong adler, const unsigned char *ptr, size_t buf_len)
mz_ulong mz_crc32 (mz_ulong crc, const unsigned char *ptr, size_t buf_len)
const char * mz_version (void)
int mz_deflateInit (mz_streamp pStream, int level)
int mz_deflateInit2 (mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
int mz_deflateReset (mz_streamp pStream)
int mz_deflate (mz_streamp pStream, int flush)
int mz_deflateEnd (mz_streamp pStream)
mz_ulong mz_deflateBound (mz_streamp pStream, mz_ulong source_len)
int mz_compress (unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
int mz_compress2 (unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
mz_ulong mz_compressBound (mz_ulong source_len)
int mz_inflateInit (mz_streamp pStream)
int mz_inflateInit2 (mz_streamp pStream, int window_bits)
int mz_inflate (mz_streamp pStream, int flush)
int mz_inflateEnd (mz_streamp pStream)
int mz_uncompress (unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
const char * mz_error (int err)
void * miniz_def_alloc_func (void *opaque, size_t items, size_t size)
void miniz_def_free_func (void *opaque, void *address)
void * miniz_def_realloc_func (void *opaque, void *address, size_t items, size_t size)
void * tdefl_compress_mem_to_heap (const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
size_t tdefl_compress_mem_to_mem (void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
void * tdefl_write_image_to_png_file_in_memory_ex (const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip)
void * tdefl_write_image_to_png_file_in_memory (const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
mz_bool tdefl_compress_mem_to_output (const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
tdefl_status tdefl_init (tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
tdefl_status tdefl_compress (tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush)
tdefl_status tdefl_compress_buffer (tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush)
tdefl_status tdefl_get_prev_return_status (tdefl_compressor *d)
mz_uint32 tdefl_get_adler32 (tdefl_compressor *d)
mz_uint tdefl_create_comp_flags_from_zip_params (int level, int window_bits, int strategy)
tdefl_compressor * tdefl_compressor_alloc ()
void tdefl_compressor_free (tdefl_compressor *pComp)
void * tinfl_decompress_mem_to_heap (const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
size_t tinfl_decompress_mem_to_mem (void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
int tinfl_decompress_mem_to_callback (const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
tinfl_decompressor * tinfl_decompressor_alloc ()
void tinfl_decompressor_free (tinfl_decompressor *pDecomp)
tinfl_status tinfl_decompress (tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags)
mz_bool mz_zip_reader_init (mz_zip_archive *pZip, mz_uint64 size, mz_uint flags)
mz_bool mz_zip_reader_init_mem (mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags)
mz_bool mz_zip_reader_end (mz_zip_archive *pZip)
void mz_zip_zero_struct (mz_zip_archive *pZip)
mz_zip_mode mz_zip_get_mode (mz_zip_archive *pZip)
mz_zip_type mz_zip_get_type (mz_zip_archive *pZip)
mz_uint mz_zip_reader_get_num_files (mz_zip_archive *pZip)
mz_uint64 mz_zip_get_archive_size (mz_zip_archive *pZip)
mz_uint64 mz_zip_get_archive_file_start_offset (mz_zip_archive *pZip)
MZ_FILE * mz_zip_get_cfile (mz_zip_archive *pZip)
size_t mz_zip_read_archive_data (mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n)
mz_zip_error mz_zip_set_last_error (mz_zip_archive *pZip, mz_zip_error err_num)
mz_zip_error mz_zip_peek_last_error (mz_zip_archive *pZip)
mz_zip_error mz_zip_clear_last_error (mz_zip_archive *pZip)
mz_zip_error mz_zip_get_last_error (mz_zip_archive *pZip)
const char * mz_zip_get_error_string (mz_zip_error mz_err)
mz_bool mz_zip_reader_is_file_a_directory (mz_zip_archive *pZip, mz_uint file_index)
mz_bool mz_zip_reader_is_file_encrypted (mz_zip_archive *pZip, mz_uint file_index)
mz_bool mz_zip_reader_is_file_supported (mz_zip_archive *pZip, mz_uint file_index)
mz_uint mz_zip_reader_get_filename (mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size)
int mz_zip_reader_locate_file (mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags)
int mz_zip_reader_locate_file_v2 (mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index)
mz_bool mz_zip_reader_file_stat (mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat)
mz_bool mz_zip_is_zip64 (mz_zip_archive *pZip)
size_t mz_zip_get_central_dir_size (mz_zip_archive *pZip)
mz_bool mz_zip_reader_extract_to_mem_no_alloc (mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
mz_bool mz_zip_reader_extract_file_to_mem_no_alloc (mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
mz_bool mz_zip_reader_extract_to_mem (mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags)
mz_bool mz_zip_reader_extract_file_to_mem (mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags)
void * mz_zip_reader_extract_to_heap (mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags)
void * mz_zip_reader_extract_file_to_heap (mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags)
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)
mz_bool mz_zip_reader_extract_file_to_callback (mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_iter_new (mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_file_iter_new (mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
size_t mz_zip_reader_extract_iter_read (mz_zip_reader_extract_iter_state *pState, void *pvBuf, size_t buf_size)
mz_bool mz_zip_reader_extract_iter_free (mz_zip_reader_extract_iter_state *pState)
mz_bool mz_zip_validate_file (mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
mz_bool mz_zip_validate_archive (mz_zip_archive *pZip, mz_uint flags)
mz_bool mz_zip_validate_mem_archive (const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr)
mz_bool mz_zip_validate_file_archive (const char *pFilename, mz_uint flags, mz_zip_error *pErr)
mz_bool mz_zip_end (mz_zip_archive *pZip)
mz_bool mz_zip_writer_init (mz_zip_archive *pZip, mz_uint64 existing_size)
mz_bool mz_zip_writer_init_v2 (mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags)
mz_bool mz_zip_writer_init_heap (mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size)
mz_bool mz_zip_writer_init_heap_v2 (mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags)
mz_bool mz_zip_writer_init_from_reader (mz_zip_archive *pZip, const char *pFilename)
mz_bool mz_zip_writer_init_from_reader_v2 (mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
mz_bool mz_zip_writer_add_mem (mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags)
mz_bool mz_zip_writer_add_mem_ex (mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
mz_bool mz_zip_writer_add_mem_ex_v2 (mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, 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)
mz_bool mz_zip_writer_add_from_zip_reader (mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index)
mz_bool mz_zip_writer_finalize_archive (mz_zip_archive *pZip)
mz_bool mz_zip_writer_finalize_heap_archive (mz_zip_archive *pZip, void **ppBuf, size_t *pSize)
mz_bool mz_zip_writer_end (mz_zip_archive *pZip)
mz_bool mz_zip_add_mem_to_archive_file_in_place (const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2 (const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr)
void * mz_zip_extract_archive_file_to_heap (const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags)
void * mz_zip_extract_archive_file_to_heap_v2 (const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr)
static tdefl_sym_freq * tdefl_radix_sort_syms (mz_uint num_syms, tdefl_sym_freq *pSyms0, tdefl_sym_freq *pSyms1)
static void tdefl_calculate_minimum_redundancy (tdefl_sym_freq *A, int n)
static void tdefl_huffman_enforce_max_code_size (int *pNum_codes, int code_list_len, int max_code_size)
static void tdefl_optimize_huffman_table (tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
static void tdefl_start_dynamic_block (tdefl_compressor *d)
static void tdefl_start_static_block (tdefl_compressor *d)
static mz_bool tdefl_compress_lz_codes (tdefl_compressor *d)
static mz_bool tdefl_compress_block (tdefl_compressor *d, mz_bool static_block)
static int tdefl_flush_block (tdefl_compressor *d, int flush)
static MZ_FORCEINLINE void tdefl_find_match (tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
static MZ_FORCEINLINE void tdefl_record_literal (tdefl_compressor *d, mz_uint8 lit)
static MZ_FORCEINLINE void tdefl_record_match (tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
static mz_bool tdefl_compress_normal (tdefl_compressor *d)
static tdefl_status tdefl_flush_output_buffer (tdefl_compressor *d)
static mz_bool tdefl_output_buffer_putter (const void *pBuf, int len, void *pUser)
static MZ_FORCEINLINE mz_uint mz_zip_array_range_check (const mz_zip_array *pArray, mz_uint index)
static MZ_FORCEINLINE void mz_zip_array_init (mz_zip_array *pArray, mz_uint32 element_size)
static MZ_FORCEINLINE void mz_zip_array_clear (mz_zip_archive *pZip, mz_zip_array *pArray)
static mz_bool mz_zip_array_ensure_capacity (mz_zip_archive *pZip, mz_zip_array *pArray, size_t min_new_capacity, mz_uint growing)
static MZ_FORCEINLINE mz_bool mz_zip_array_reserve (mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing)
static MZ_FORCEINLINE mz_bool mz_zip_array_resize (mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing)
static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room (mz_zip_archive *pZip, mz_zip_array *pArray, size_t n)
static MZ_FORCEINLINE mz_bool mz_zip_array_push_back (mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n)
static MZ_FORCEINLINE mz_bool mz_zip_set_error (mz_zip_archive *pZip, mz_zip_error err_num)
static mz_bool mz_zip_reader_init_internal (mz_zip_archive *pZip, mz_uint flags)
static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less (const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index)
static void mz_zip_reader_sort_central_dir_offsets_by_filename (mz_zip_archive *pZip)
static mz_bool mz_zip_reader_locate_header_sig (mz_zip_archive *pZip, mz_uint32 record_sig, mz_uint32 record_size, mz_int64 *pOfs)
static mz_bool mz_zip_reader_read_central_dir (mz_zip_archive *pZip, mz_uint flags)
static mz_bool mz_zip_reader_end_internal (mz_zip_archive *pZip, mz_bool set_last_error)
static size_t mz_zip_mem_read_func (void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
static MZ_FORCEINLINE const mz_uint8 * mz_zip_get_cdh (mz_zip_archive *pZip, mz_uint file_index)
static mz_bool mz_zip_file_stat_internal (mz_zip_archive *pZip, mz_uint file_index, const mz_uint8 *pCentral_dir_header, mz_zip_archive_file_stat *pStat, mz_bool *pFound_zip64_extra_data)
static MZ_FORCEINLINE mz_bool mz_zip_string_equal (const char *pA, const char *pB, mz_uint len, mz_uint flags)
static MZ_FORCEINLINE int mz_zip_filename_compare (const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len)
static mz_bool mz_zip_locate_file_binary_search (mz_zip_archive *pZip, const char *pFilename, mz_uint32 *pIndex)
static size_t mz_zip_compute_crc32_callback (void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
static MZ_FORCEINLINE void mz_write_le16 (mz_uint8 *p, mz_uint16 v)
static MZ_FORCEINLINE void mz_write_le32 (mz_uint8 *p, mz_uint32 v)
static MZ_FORCEINLINE void mz_write_le64 (mz_uint8 *p, mz_uint64 v)
static size_t mz_zip_heap_write_func (void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
static mz_bool mz_zip_writer_end_internal (mz_zip_archive *pZip, mz_bool set_last_error)
static mz_bool mz_zip_writer_add_put_buf_callback (const void *pBuf, int len, void *pUser)
static mz_uint32 mz_zip_writer_create_zip64_extra_data (mz_uint8 *pBuf, mz_uint64 *pUncomp_size, mz_uint64 *pComp_size, mz_uint64 *pLocal_header_ofs)
static mz_bool mz_zip_writer_create_local_dir_header (mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date)
static mz_bool mz_zip_writer_create_central_dir_header (mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
static mz_bool mz_zip_writer_add_to_central_dir (mz_zip_archive *pZip, const char *pFilename, mz_uint16 filename_size, const void *pExtra, mz_uint16 extra_size, const void *pComment, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes, const char *user_extra_data, mz_uint user_extra_data_len)
static mz_bool mz_zip_writer_validate_archive_name (const char *pArchive_name)
static mz_uint mz_zip_writer_compute_padding_needed_for_file_alignment (mz_zip_archive *pZip)
static mz_bool mz_zip_writer_write_zeros (mz_zip_archive *pZip, mz_uint64 cur_file_ofs, mz_uint32 n)
static mz_bool mz_zip_writer_update_zip64_extension_block (mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, uint32_t ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start)

Variables

static const mz_uint16 s_tdefl_len_sym [256]
static const mz_uint8 s_tdefl_len_extra [256]
static const mz_uint8 s_tdefl_small_dist_sym [512]
static const mz_uint8 s_tdefl_small_dist_extra [512]
static const mz_uint8 s_tdefl_large_dist_sym [128]
static const mz_uint8 s_tdefl_large_dist_extra [128]
static mz_uint8 s_tdefl_packed_code_size_syms_swizzle [] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }
static const mz_uint mz_bitmasks [17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }
static const mz_uint s_tdefl_num_probes [11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }

Detailed Description

Copyright 2013-2014 RAD Game Tools and Valve Software Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
76030{ MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };

◆ anonymous enum

anonymous enum
76042 {
76043 MZ_NO_COMPRESSION = 0,
76044 MZ_BEST_SPEED = 1,
76045 MZ_BEST_COMPRESSION = 9,
76046 MZ_UBER_COMPRESSION = 10,
76047 MZ_DEFAULT_LEVEL = 6,
76048 MZ_DEFAULT_COMPRESSION = -1
76049};

◆ anonymous enum

anonymous enum
76061{ MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };

◆ anonymous enum

anonymous enum
76064 {
76065 MZ_OK = 0,
76066 MZ_STREAM_END = 1,
76067 MZ_NEED_DICT = 2,
76068 MZ_ERRNO = -1,
76069 MZ_STREAM_ERROR = -2,
76070 MZ_DATA_ERROR = -3,
76071 MZ_MEM_ERROR = -4,
76072 MZ_BUF_ERROR = -5,
76073 MZ_VERSION_ERROR = -6,
76074 MZ_PARAM_ERROR = -10000
76075};

◆ anonymous enum

anonymous enum
76374{
76375 TDEFL_HUFFMAN_ONLY = 0,
76376 TDEFL_DEFAULT_MAX_PROBES = 128,
76377 TDEFL_MAX_PROBES_MASK = 0xFFF
76378};

◆ anonymous enum

anonymous enum
76390{
76391 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
76392 TDEFL_COMPUTE_ADLER32 = 0x02000,
76393 TDEFL_GREEDY_PARSING_FLAG = 0x04000,
76394 TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
76395 TDEFL_RLE_MATCHES = 0x10000,
76396 TDEFL_FILTER_MATCHES = 0x20000,
76397 TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
76398 TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
76399};

◆ anonymous enum

anonymous enum
76436{
76437 TDEFL_MAX_HUFF_TABLES = 3,
76438 TDEFL_MAX_HUFF_SYMBOLS_0 = 288,
76439 TDEFL_MAX_HUFF_SYMBOLS_1 = 32,
76440 TDEFL_MAX_HUFF_SYMBOLS_2 = 19,
76441 TDEFL_LZ_DICT_SIZE = 32768,
76442 TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1,
76443 TDEFL_MIN_MATCH_LEN = 3,
76444 TDEFL_MAX_MATCH_LEN = 258
76445};

◆ anonymous enum

anonymous enum
76461{
76462 TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024,
76463 TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
76464 TDEFL_MAX_HUFF_SYMBOLS = 288,
76465 TDEFL_LZ_HASH_BITS = 15,
76466 TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
76467 TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3,
76468 TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
76469};

◆ tdefl_status

enum duckdb_miniz::tdefl_status
76473 {
76474 TDEFL_STATUS_BAD_PARAM = -2,
76475 TDEFL_STATUS_PUT_BUF_FAILED = -1,
76476 TDEFL_STATUS_OKAY = 0,
76477 TDEFL_STATUS_DONE = 1
76478} tdefl_status;

◆ tdefl_flush

enum duckdb_miniz::tdefl_flush
76481 {
76482 TDEFL_NO_FLUSH = 0,
76483 TDEFL_SYNC_FLUSH = 2,
76484 TDEFL_FULL_FLUSH = 3,
76485 TDEFL_FINISH = 4
76486} tdefl_flush;

◆ anonymous enum

anonymous enum
76557{
76558 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
76559 TINFL_FLAG_HAS_MORE_INPUT = 2,
76560 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
76561 TINFL_FLAG_COMPUTE_ADLER32 = 8
76562};

◆ tinfl_status

enum duckdb_miniz::tinfl_status
76598 {
76599 /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
76600 /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
76601 /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
76602 TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
76603
76604 /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
76605 TINFL_STATUS_BAD_PARAM = -3,
76606
76607 /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
76608 TINFL_STATUS_ADLER32_MISMATCH = -2,
76609
76610 /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
76611 TINFL_STATUS_FAILED = -1,
76612
76613 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
76614
76615 /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
76616 /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
76617 TINFL_STATUS_DONE = 0,
76618
76619 /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
76620 /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
76621 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
76622 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
76623
76624 /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
76625 /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
76626 /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
76627 /* so I may need to add some code to address this. */
76628 TINFL_STATUS_HAS_MORE_OUTPUT = 2
76629} tinfl_status;

◆ anonymous enum

anonymous enum
76646{
76647 TINFL_MAX_HUFF_TABLES = 3,
76648 TINFL_MAX_HUFF_SYMBOLS_0 = 288,
76649 TINFL_MAX_HUFF_SYMBOLS_1 = 32,
76650 TINFL_MAX_HUFF_SYMBOLS_2 = 19,
76651 TINFL_FAST_LOOKUP_BITS = 10,
76652 TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
76653};

◆ anonymous enum

anonymous enum
76695{
76696 /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
76697 MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
76698 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
76699 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
76700};

◆ mz_zip_mode

enum duckdb_miniz::mz_zip_mode
76765 {
76766 MZ_ZIP_MODE_INVALID = 0,
76767 MZ_ZIP_MODE_READING = 1,
76768 MZ_ZIP_MODE_WRITING = 2,
76769 MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
76770} mz_zip_mode;

◆ mz_zip_flags

enum duckdb_miniz::mz_zip_flags
76772 {
76773 MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
76774 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
76775 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
76776 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
76777 MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */
76778 MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */
76779 MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */
76780 MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
76781 MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000
76782} mz_zip_flags;

◆ mz_zip_type

enum duckdb_miniz::mz_zip_type
76784 {
76785 MZ_ZIP_TYPE_INVALID = 0,
76786 MZ_ZIP_TYPE_USER,
76787 MZ_ZIP_TYPE_MEMORY,
76788 MZ_ZIP_TYPE_HEAP,
76789 MZ_ZIP_TYPE_FILE,
76790 MZ_ZIP_TYPE_CFILE,
76791 MZ_ZIP_TOTAL_TYPES
76792} mz_zip_type;

◆ mz_zip_error

enum duckdb_miniz::mz_zip_error
76795 {
76796 MZ_ZIP_NO_ERROR = 0,
76797 MZ_ZIP_UNDEFINED_ERROR,
76798 MZ_ZIP_TOO_MANY_FILES,
76799 MZ_ZIP_FILE_TOO_LARGE,
76800 MZ_ZIP_UNSUPPORTED_METHOD,
76801 MZ_ZIP_UNSUPPORTED_ENCRYPTION,
76802 MZ_ZIP_UNSUPPORTED_FEATURE,
76803 MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
76804 MZ_ZIP_NOT_AN_ARCHIVE,
76805 MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
76806 MZ_ZIP_UNSUPPORTED_MULTIDISK,
76807 MZ_ZIP_DECOMPRESSION_FAILED,
76808 MZ_ZIP_COMPRESSION_FAILED,
76809 MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
76810 MZ_ZIP_CRC_CHECK_FAILED,
76811 MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
76812 MZ_ZIP_ALLOC_FAILED,
76813 MZ_ZIP_FILE_OPEN_FAILED,
76814 MZ_ZIP_FILE_CREATE_FAILED,
76815 MZ_ZIP_FILE_WRITE_FAILED,
76816 MZ_ZIP_FILE_READ_FAILED,
76817 MZ_ZIP_FILE_CLOSE_FAILED,
76818 MZ_ZIP_FILE_SEEK_FAILED,
76819 MZ_ZIP_FILE_STAT_FAILED,
76820 MZ_ZIP_INVALID_PARAMETER,
76821 MZ_ZIP_INVALID_FILENAME,
76822 MZ_ZIP_BUF_TOO_SMALL,
76823 MZ_ZIP_INTERNAL_ERROR,
76824 MZ_ZIP_FILE_NOT_FOUND,
76825 MZ_ZIP_ARCHIVE_TOO_LARGE,
76826 MZ_ZIP_VALIDATION_FAILED,
76827 MZ_ZIP_WRITE_CALLBACK_FAILED,
76828 MZ_ZIP_TOTAL_ERRORS
76829} mz_zip_error;

◆ anonymous enum

anonymous enum
452077{
452078 TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32
452079};

◆ anonymous enum

anonymous enum
454329{
454330 /* ZIP archive identifiers and record sizes */
454331 MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06054b50,
454332 MZ_ZIP_CENTRAL_DIR_HEADER_SIG = 0x02014b50,
454333 MZ_ZIP_LOCAL_DIR_HEADER_SIG = 0x04034b50,
454334 MZ_ZIP_LOCAL_DIR_HEADER_SIZE = 30,
454335 MZ_ZIP_CENTRAL_DIR_HEADER_SIZE = 46,
454336 MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE = 22,
454337
454338 /* ZIP64 archive identifier and record sizes */
454339 MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06064b50,
454340 MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 0x07064b50,
454341 MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE = 56,
454342 MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE = 20,
454343 MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID = 0x0001,
454344 MZ_ZIP_DATA_DESCRIPTOR_ID = 0x08074b50,
454345 MZ_ZIP_DATA_DESCRIPTER_SIZE64 = 24,
454346 MZ_ZIP_DATA_DESCRIPTER_SIZE32 = 16,
454347
454348 /* Central directory header record offsets */
454349 MZ_ZIP_CDH_SIG_OFS = 0,
454350 MZ_ZIP_CDH_VERSION_MADE_BY_OFS = 4,
454351 MZ_ZIP_CDH_VERSION_NEEDED_OFS = 6,
454352 MZ_ZIP_CDH_BIT_FLAG_OFS = 8,
454353 MZ_ZIP_CDH_METHOD_OFS = 10,
454354 MZ_ZIP_CDH_FILE_TIME_OFS = 12,
454355 MZ_ZIP_CDH_FILE_DATE_OFS = 14,
454356 MZ_ZIP_CDH_CRC32_OFS = 16,
454357 MZ_ZIP_CDH_COMPRESSED_SIZE_OFS = 20,
454358 MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS = 24,
454359 MZ_ZIP_CDH_FILENAME_LEN_OFS = 28,
454360 MZ_ZIP_CDH_EXTRA_LEN_OFS = 30,
454361 MZ_ZIP_CDH_COMMENT_LEN_OFS = 32,
454362 MZ_ZIP_CDH_DISK_START_OFS = 34,
454363 MZ_ZIP_CDH_INTERNAL_ATTR_OFS = 36,
454364 MZ_ZIP_CDH_EXTERNAL_ATTR_OFS = 38,
454365 MZ_ZIP_CDH_LOCAL_HEADER_OFS = 42,
454366
454367 /* Local directory header offsets */
454368 MZ_ZIP_LDH_SIG_OFS = 0,
454369 MZ_ZIP_LDH_VERSION_NEEDED_OFS = 4,
454370 MZ_ZIP_LDH_BIT_FLAG_OFS = 6,
454371 MZ_ZIP_LDH_METHOD_OFS = 8,
454372 MZ_ZIP_LDH_FILE_TIME_OFS = 10,
454373 MZ_ZIP_LDH_FILE_DATE_OFS = 12,
454374 MZ_ZIP_LDH_CRC32_OFS = 14,
454375 MZ_ZIP_LDH_COMPRESSED_SIZE_OFS = 18,
454376 MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22,
454377 MZ_ZIP_LDH_FILENAME_LEN_OFS = 26,
454378 MZ_ZIP_LDH_EXTRA_LEN_OFS = 28,
454379 MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR = 1 << 3,
454380
454381 /* End of central directory offsets */
454382 MZ_ZIP_ECDH_SIG_OFS = 0,
454383 MZ_ZIP_ECDH_NUM_THIS_DISK_OFS = 4,
454384 MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS = 6,
454385 MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 8,
454386 MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS = 10,
454387 MZ_ZIP_ECDH_CDIR_SIZE_OFS = 12,
454388 MZ_ZIP_ECDH_CDIR_OFS_OFS = 16,
454389 MZ_ZIP_ECDH_COMMENT_SIZE_OFS = 20,
454390
454391 /* ZIP64 End of central directory locator offsets */
454392 MZ_ZIP64_ECDL_SIG_OFS = 0, /* 4 bytes */
454393 MZ_ZIP64_ECDL_NUM_DISK_CDIR_OFS = 4, /* 4 bytes */
454394 MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS = 8, /* 8 bytes */
454395 MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS = 16, /* 4 bytes */
454396
454397 /* ZIP64 End of central directory header offsets */
454398 MZ_ZIP64_ECDH_SIG_OFS = 0, /* 4 bytes */
454399 MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS = 4, /* 8 bytes */
454400 MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS = 12, /* 2 bytes */
454401 MZ_ZIP64_ECDH_VERSION_NEEDED_OFS = 14, /* 2 bytes */
454402 MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS = 16, /* 4 bytes */
454403 MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS = 20, /* 4 bytes */
454404 MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 24, /* 8 bytes */
454405 MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS = 32, /* 8 bytes */
454406 MZ_ZIP64_ECDH_CDIR_SIZE_OFS = 40, /* 8 bytes */
454407 MZ_ZIP64_ECDH_CDIR_OFS_OFS = 48, /* 8 bytes */
454408 MZ_ZIP_VERSION_MADE_BY_DOS_FILESYSTEM_ID = 0,
454409 MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG = 0x10,
454410 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED = 1,
454411 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG = 32,
454412 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION = 64,
454413 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED = 8192,
454414 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 = 1 << 11
454415};

Function Documentation

◆ mz_free()

void duckdb_miniz::mz_free ( void * p)
451445{
451446 MZ_FREE(p);
451447}

◆ mz_adler32()

mz_ulong duckdb_miniz::mz_adler32 ( mz_ulong adler,
const unsigned char * ptr,
size_t buf_len )
451329{
451330 mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16);
451331 size_t block_len = buf_len % 5552;
451332 if (!ptr)
451333 return MZ_ADLER32_INIT;
451334 while (buf_len)
451335 {
451336 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
451337 {
451338 s1 += ptr[0], s2 += s1;
451339 s1 += ptr[1], s2 += s1;
451340 s1 += ptr[2], s2 += s1;
451341 s1 += ptr[3], s2 += s1;
451342 s1 += ptr[4], s2 += s1;
451343 s1 += ptr[5], s2 += s1;
451344 s1 += ptr[6], s2 += s1;
451345 s1 += ptr[7], s2 += s1;
451346 }
451347 for (; i < block_len; ++i)
451348 s1 += *ptr++, s2 += s1;
451349 s1 %= 65521U, s2 %= 65521U;
451350 buf_len -= block_len;
451351 block_len = 5552;
451352 }
451353 return (s2 << 16) + s1;
451354}

◆ mz_crc32()

mz_ulong duckdb_miniz::mz_crc32 ( mz_ulong crc,
const unsigned char * ptr,
size_t buf_len )
451378{
451379 static const mz_uint32 s_crc_table[256] =
451380 {
451381 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
451382 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
451383 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
451384 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
451385 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
451386 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
451387 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC,
451388 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
451389 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
451390 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
451391 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB,
451392 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
451393 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA,
451394 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE,
451395 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
451396 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
451397 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409,
451398 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
451399 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739,
451400 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
451401 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268,
451402 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0,
451403 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
451404 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
451405 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
451406 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
451407 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
451408 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
451409 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE,
451410 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
451411 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6,
451412 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
451413 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D,
451414 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
451415 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
451416 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
451417 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
451418 };
451419
451420 mz_uint32 crc32 = (mz_uint32)crc ^ 0xFFFFFFFF;
451421 const mz_uint8 *pByte_buf = (const mz_uint8 *)ptr;
451422
451423 while (buf_len >= 4)
451424 {
451425 crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[0]) & 0xFF];
451426 crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[1]) & 0xFF];
451427 crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[2]) & 0xFF];
451428 crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[3]) & 0xFF];
451429 pByte_buf += 4;
451430 buf_len -= 4;
451431 }
451432
451433 while (buf_len)
451434 {
451435 crc32 = (crc32 >> 8) ^ s_crc_table[(crc32 ^ pByte_buf[0]) & 0xFF];
451436 ++pByte_buf;
451437 --buf_len;
451438 }
451439
451440 return ~crc32;
451441}

◆ mz_version()

const char * duckdb_miniz::mz_version ( void )
451466{
451467 return MZ_VERSION;
451468}

◆ mz_deflateInit()

int duckdb_miniz::mz_deflateInit ( mz_streamp pStream,
int level )
451473{
451474 return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
451475}

◆ mz_deflateInit2()

int duckdb_miniz::mz_deflateInit2 ( mz_streamp pStream,
int level,
int method,
int window_bits,
int mem_level,
int strategy )
451478{
451479 tdefl_compressor *pComp;
451480 mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy);
451481
451482 if (!pStream)
451483 return MZ_STREAM_ERROR;
451484 if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)))
451485 return MZ_PARAM_ERROR;
451486
451487 pStream->data_type = 0;
451488 pStream->adler = MZ_ADLER32_INIT;
451489 pStream->msg = NULL;
451490 pStream->reserved = 0;
451491 pStream->total_in = 0;
451492 pStream->total_out = 0;
451493 if (!pStream->zalloc)
451494 pStream->zalloc = miniz_def_alloc_func;
451495 if (!pStream->zfree)
451496 pStream->zfree = miniz_def_free_func;
451497
451498 pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor));
451499 if (!pComp)
451500 return MZ_MEM_ERROR;
451501
451502 pStream->state = (struct mz_internal_state *)pComp;
451503
451504 if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
451505 {
451506 mz_deflateEnd(pStream);
451507 return MZ_PARAM_ERROR;
451508 }
451509
451510 return MZ_OK;
451511}
Definition duckdb.cpp:76490

◆ mz_deflateReset()

int duckdb_miniz::mz_deflateReset ( mz_streamp pStream)
451514{
451515 if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree))
451516 return MZ_STREAM_ERROR;
451517 pStream->total_in = pStream->total_out = 0;
451518 tdefl_init((tdefl_compressor *)pStream->state, NULL, NULL, ((tdefl_compressor *)pStream->state)->m_flags);
451519 return MZ_OK;
451520}

◆ mz_deflate()

int duckdb_miniz::mz_deflate ( mz_streamp pStream,
int flush )
451523{
451524 size_t in_bytes, out_bytes;
451525 mz_ulong orig_total_in, orig_total_out;
451526 int mz_status = MZ_OK;
451527
451528 if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out))
451529 return MZ_STREAM_ERROR;
451530 if (!pStream->avail_out)
451531 return MZ_BUF_ERROR;
451532
451533 if (flush == MZ_PARTIAL_FLUSH)
451534 flush = MZ_SYNC_FLUSH;
451535
451536 if (((tdefl_compressor *)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE)
451537 return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR;
451538
451539 orig_total_in = pStream->total_in;
451540 orig_total_out = pStream->total_out;
451541 for (;;)
451542 {
451543 tdefl_status defl_status;
451544 in_bytes = pStream->avail_in;
451545 out_bytes = pStream->avail_out;
451546
451547 defl_status = tdefl_compress((tdefl_compressor *)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush);
451548 pStream->next_in += (mz_uint)in_bytes;
451549 pStream->avail_in -= (mz_uint)in_bytes;
451550 pStream->total_in += (mz_uint)in_bytes;
451551 pStream->adler = tdefl_get_adler32((tdefl_compressor *)pStream->state);
451552
451553 pStream->next_out += (mz_uint)out_bytes;
451554 pStream->avail_out -= (mz_uint)out_bytes;
451555 pStream->total_out += (mz_uint)out_bytes;
451556
451557 if (defl_status < 0)
451558 {
451559 mz_status = MZ_STREAM_ERROR;
451560 break;
451561 }
451562 else if (defl_status == TDEFL_STATUS_DONE)
451563 {
451564 mz_status = MZ_STREAM_END;
451565 break;
451566 }
451567 else if (!pStream->avail_out)
451568 break;
451569 else if ((!pStream->avail_in) && (flush != MZ_FINISH))
451570 {
451571 if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out))
451572 break;
451573 return MZ_BUF_ERROR; /* Can't make forward progress without some input.
451574 */
451575 }
451576 }
451577 return mz_status;
451578}

◆ mz_deflateEnd()

int duckdb_miniz::mz_deflateEnd ( mz_streamp pStream)
451581{
451582 if (!pStream)
451583 return MZ_STREAM_ERROR;
451584 if (pStream->state)
451585 {
451586 pStream->zfree(pStream->opaque, pStream->state);
451587 pStream->state = NULL;
451588 }
451589 return MZ_OK;
451590}

◆ mz_deflateBound()

mz_ulong duckdb_miniz::mz_deflateBound ( mz_streamp pStream,
mz_ulong source_len )
451593{
451594 (void)pStream;
451595 /* This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) */
451596 return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
451597}

◆ mz_compress()

int duckdb_miniz::mz_compress ( unsigned char * pDest,
mz_ulong * pDest_len,
const unsigned char * pSource,
mz_ulong source_len )
451630{
451631 return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION);
451632}

◆ mz_compress2()

int duckdb_miniz::mz_compress2 ( unsigned char * pDest,
mz_ulong * pDest_len,
const unsigned char * pSource,
mz_ulong source_len,
int level )
451600{
451601 int status;
451602 mz_stream stream;
451603 memset(&stream, 0, sizeof(stream));
451604
451605 /* In case mz_ulong is 64-bits (argh I hate longs). */
451606 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
451607 return MZ_PARAM_ERROR;
451608
451609 stream.next_in = pSource;
451610 stream.avail_in = (mz_uint32)source_len;
451611 stream.next_out = pDest;
451612 stream.avail_out = (mz_uint32)*pDest_len;
451613
451614 status = mz_deflateInit(&stream, level);
451615 if (status != MZ_OK)
451616 return status;
451617
451618 status = mz_deflate(&stream, MZ_FINISH);
451619 if (status != MZ_STREAM_END)
451620 {
451621 mz_deflateEnd(&stream);
451622 return (status == MZ_OK) ? MZ_BUF_ERROR : status;
451623 }
451624
451625 *pDest_len = stream.total_out;
451626 return mz_deflateEnd(&stream);
451627}

◆ mz_compressBound()

mz_ulong duckdb_miniz::mz_compressBound ( mz_ulong source_len)
451635{
451636 return mz_deflateBound(NULL, source_len);
451637}

◆ mz_inflateInit()

int duckdb_miniz::mz_inflateInit ( mz_streamp pStream)
451685{
451686 return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
451687}

◆ mz_inflateInit2()

int duckdb_miniz::mz_inflateInit2 ( mz_streamp pStream,
int window_bits )
451649{
451650 inflate_state *pDecomp;
451651 if (!pStream)
451652 return MZ_STREAM_ERROR;
451653 if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))
451654 return MZ_PARAM_ERROR;
451655
451656 pStream->data_type = 0;
451657 pStream->adler = 0;
451658 pStream->msg = NULL;
451659 pStream->total_in = 0;
451660 pStream->total_out = 0;
451661 pStream->reserved = 0;
451662 if (!pStream->zalloc)
451663 pStream->zalloc = miniz_def_alloc_func;
451664 if (!pStream->zfree)
451665 pStream->zfree = miniz_def_free_func;
451666
451667 pDecomp = (inflate_state *)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));
451668 if (!pDecomp)
451669 return MZ_MEM_ERROR;
451670
451671 pStream->state = (struct mz_internal_state *)pDecomp;
451672
451673 tinfl_init(&pDecomp->m_decomp);
451674 pDecomp->m_dict_ofs = 0;
451675 pDecomp->m_dict_avail = 0;
451676 pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
451677 pDecomp->m_first_call = 1;
451678 pDecomp->m_has_flushed = 0;
451679 pDecomp->m_window_bits = window_bits;
451680
451681 return MZ_OK;
451682}
Definition duckdb.cpp:451640

◆ mz_inflate()

int duckdb_miniz::mz_inflate ( mz_streamp pStream,
int flush )
451690{
451691 inflate_state *pState;
451692 mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
451693 size_t in_bytes, out_bytes, orig_avail_in;
451694 tinfl_status status;
451695
451696 if ((!pStream) || (!pStream->state))
451697 return MZ_STREAM_ERROR;
451698 if (flush == MZ_PARTIAL_FLUSH)
451699 flush = MZ_SYNC_FLUSH;
451700 if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH))
451701 return MZ_STREAM_ERROR;
451702
451703 pState = (inflate_state *)pStream->state;
451704 if (pState->m_window_bits > 0)
451705 decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
451706 orig_avail_in = pStream->avail_in;
451707
451708 first_call = pState->m_first_call;
451709 pState->m_first_call = 0;
451710 if (pState->m_last_status < 0)
451711 return MZ_DATA_ERROR;
451712
451713 if (pState->m_has_flushed && (flush != MZ_FINISH))
451714 return MZ_STREAM_ERROR;
451715 pState->m_has_flushed |= (flush == MZ_FINISH);
451716
451717 if ((flush == MZ_FINISH) && (first_call))
451718 {
451719 /* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */
451720 decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
451721 in_bytes = pStream->avail_in;
451722 out_bytes = pStream->avail_out;
451723 status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
451724 pState->m_last_status = status;
451725 pStream->next_in += (mz_uint)in_bytes;
451726 pStream->avail_in -= (mz_uint)in_bytes;
451727 pStream->total_in += (mz_uint)in_bytes;
451728 pStream->adler = tinfl_get_adler32(&pState->m_decomp);
451729 pStream->next_out += (mz_uint)out_bytes;
451730 pStream->avail_out -= (mz_uint)out_bytes;
451731 pStream->total_out += (mz_uint)out_bytes;
451732
451733 if (status < 0)
451734 return MZ_DATA_ERROR;
451735 else if (status != TINFL_STATUS_DONE)
451736 {
451737 pState->m_last_status = TINFL_STATUS_FAILED;
451738 return MZ_BUF_ERROR;
451739 }
451740 return MZ_STREAM_END;
451741 }
451742 /* flush != MZ_FINISH then we must assume there's more input. */
451743 if (flush != MZ_FINISH)
451744 decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
451745
451746 if (pState->m_dict_avail)
451747 {
451748 n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
451749 memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
451750 pStream->next_out += n;
451751 pStream->avail_out -= n;
451752 pStream->total_out += n;
451753 pState->m_dict_avail -= n;
451754 pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
451755 return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
451756 }
451757
451758 for (;;)
451759 {
451760 in_bytes = pStream->avail_in;
451761 out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
451762
451763 status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
451764 pState->m_last_status = status;
451765
451766 pStream->next_in += (mz_uint)in_bytes;
451767 pStream->avail_in -= (mz_uint)in_bytes;
451768 pStream->total_in += (mz_uint)in_bytes;
451769 pStream->adler = tinfl_get_adler32(&pState->m_decomp);
451770
451771 pState->m_dict_avail = (mz_uint)out_bytes;
451772
451773 n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
451774 memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
451775 pStream->next_out += n;
451776 pStream->avail_out -= n;
451777 pStream->total_out += n;
451778 pState->m_dict_avail -= n;
451779 pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
451780
451781 if (status < 0)
451782 return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */
451783 else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
451784 return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */
451785 else if (flush == MZ_FINISH)
451786 {
451787 /* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */
451788 if (status == TINFL_STATUS_DONE)
451789 return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
451790 /* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */
451791 else if (!pStream->avail_out)
451792 return MZ_BUF_ERROR;
451793 }
451794 else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
451795 break;
451796 }
451797
451798 return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
451799}

◆ mz_inflateEnd()

int duckdb_miniz::mz_inflateEnd ( mz_streamp pStream)
451802{
451803 if (!pStream)
451804 return MZ_STREAM_ERROR;
451805 if (pStream->state)
451806 {
451807 pStream->zfree(pStream->opaque, pStream->state);
451808 pStream->state = NULL;
451809 }
451810 return MZ_OK;
451811}

◆ mz_uncompress()

int duckdb_miniz::mz_uncompress ( unsigned char * pDest,
mz_ulong * pDest_len,
const unsigned char * pSource,
mz_ulong source_len )
451814{
451815 mz_stream stream;
451816 int status;
451817 memset(&stream, 0, sizeof(stream));
451818
451819 /* In case mz_ulong is 64-bits (argh I hate longs). */
451820 if ((source_len | *pDest_len) > 0xFFFFFFFFU)
451821 return MZ_PARAM_ERROR;
451822
451823 stream.next_in = pSource;
451824 stream.avail_in = (mz_uint32)source_len;
451825 stream.next_out = pDest;
451826 stream.avail_out = (mz_uint32)*pDest_len;
451827
451828 status = mz_inflateInit(&stream);
451829 if (status != MZ_OK)
451830 return status;
451831
451832 status = mz_inflate(&stream, MZ_FINISH);
451833 if (status != MZ_STREAM_END)
451834 {
451835 mz_inflateEnd(&stream);
451836 return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
451837 }
451838 *pDest_len = stream.total_out;
451839
451840 return mz_inflateEnd(&stream);
451841}

◆ mz_error()

const char * duckdb_miniz::mz_error ( int err)
451844{
451845 static struct
451846 {
451847 int m_err;
451848 const char *m_pDesc;
451849 } s_error_descs[] =
451850 {
451851 { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
451852 };
451853 mz_uint i;
451854 for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i)
451855 if (s_error_descs[i].m_err == err)
451856 return s_error_descs[i].m_pDesc;
451857 return NULL;
451858}

◆ miniz_def_alloc_func()

void * duckdb_miniz::miniz_def_alloc_func ( void * opaque,
size_t items,
size_t size )
extern
451450{
451451 (void)opaque, (void)items, (void)size;
451452 return MZ_MALLOC(items * size);
451453}
GOpaque< Size > size(const GMat &src)

◆ miniz_def_free_func()

void duckdb_miniz::miniz_def_free_func ( void * opaque,
void * address )
extern
451455{
451456 (void)opaque, (void)address;
451457 MZ_FREE(address);
451458}

◆ miniz_def_realloc_func()

void * duckdb_miniz::miniz_def_realloc_func ( void * opaque,
void * address,
size_t items,
size_t size )
extern
451460{
451461 (void)opaque, (void)address, (void)items, (void)size;
451462 return MZ_REALLOC(address, items * size);
451463}

◆ tdefl_compress_mem_to_heap()

void * duckdb_miniz::tdefl_compress_mem_to_heap ( const void * pSrc_buf,
size_t src_buf_len,
size_t * pOut_len,
int flags )
453284{
453285 tdefl_output_buffer out_buf;
453286 MZ_CLEAR_OBJ(out_buf);
453287 if (!pOut_len)
453288 return MZ_FALSE;
453289 else
453290 *pOut_len = 0;
453291 out_buf.m_expandable = MZ_TRUE;
453292 if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags))
453293 return NULL;
453294 *pOut_len = out_buf.m_size;
453295 return out_buf.m_pBuf;
453296}
Definition duckdb.cpp:453252

◆ tdefl_compress_mem_to_mem()

size_t duckdb_miniz::tdefl_compress_mem_to_mem ( void * pOut_buf,
size_t out_buf_len,
const void * pSrc_buf,
size_t src_buf_len,
int flags )
453299{
453300 tdefl_output_buffer out_buf;
453301 MZ_CLEAR_OBJ(out_buf);
453302 if (!pOut_buf)
453303 return 0;
453304 out_buf.m_pBuf = (mz_uint8 *)pOut_buf;
453305 out_buf.m_capacity = out_buf_len;
453306 if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags))
453307 return 0;
453308 return out_buf.m_size;
453309}

◆ tdefl_write_image_to_png_file_in_memory_ex()

void * duckdb_miniz::tdefl_write_image_to_png_file_in_memory_ex ( const void * pImage,
int w,
int h,
int num_chans,
size_t * pLen_out,
mz_uint level,
mz_bool flip )
453343{
453344 /* Using a local copy of this array here in case MINIZ_NO_ZLIB_APIS was defined. */
453345 static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
453346 tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor));
453347 tdefl_output_buffer out_buf;
453348 int i, bpl = w * num_chans, y, z;
453349 mz_uint32 c;
453350 *pLen_out = 0;
453351 if (!pComp)
453352 return NULL;
453353 MZ_CLEAR_OBJ(out_buf);
453354 out_buf.m_expandable = MZ_TRUE;
453355 out_buf.m_capacity = 57 + MZ_MAX(64, (1 + bpl) * h);
453356 if (NULL == (out_buf.m_pBuf = (mz_uint8 *)MZ_MALLOC(out_buf.m_capacity)))
453357 {
453358 MZ_FREE(pComp);
453359 return NULL;
453360 }
453361 /* write dummy header */
453362 for (z = 41; z; --z)
453363 tdefl_output_buffer_putter(&z, 1, &out_buf);
453364 /* compress image data */
453365 tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, s_tdefl_png_num_probes[MZ_MIN(10, level)] | TDEFL_WRITE_ZLIB_HEADER);
453366 for (y = 0; y < h; ++y)
453367 {
453368 tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH);
453369 tdefl_compress_buffer(pComp, (mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH);
453370 }
453371 if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE)
453372 {
453373 MZ_FREE(pComp);
453374 MZ_FREE(out_buf.m_pBuf);
453375 return NULL;
453376 }
453377 /* write real header */
453378 *pLen_out = out_buf.m_size - 41;
453379 {
453380 static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
453381 mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d,
453382 0x0a, 0x1a, 0x0a, 0x00, 0x00,
453383 0x00, 0x0d, 0x49, 0x48, 0x44,
453384 0x52, 0x00, 0x00, 0x00, 0x00,
453385 0x00, 0x00, 0x00, 0x00, 0x08,
453386 0x00, 0x00, 0x00, 0x00, 0x00,
453387 0x00, 0x00, 0x00, 0x00, 0x00,
453388 0x00, 0x00, 0x49, 0x44, 0x41,
453389 0x54 };
453390 pnghdr[18] = (mz_uint8)(w >> 8);
453391 pnghdr[19] = (mz_uint8)w;
453392 pnghdr[22] = (mz_uint8)(h >> 8);
453393 pnghdr[23] = (mz_uint8)h;
453394 pnghdr[25] = chans[num_chans];
453395 pnghdr[33] = (mz_uint8)(*pLen_out >> 24);
453396 pnghdr[34] = (mz_uint8)(*pLen_out >> 16);
453397 pnghdr[35] = (mz_uint8)(*pLen_out >> 8);
453398 pnghdr[36] = (mz_uint8)*pLen_out;
453399 c = (mz_uint32)mz_crc32(MZ_CRC32_INIT, pnghdr + 12, 17);
453400 for (i = 0; i < 4; ++i, c <<= 8)
453401 ((mz_uint8 *)(pnghdr + 29))[i] = (mz_uint8)(c >> 24);
453402 memcpy(out_buf.m_pBuf, pnghdr, 41);
453403 }
453404 /* write footer (IDAT CRC-32, followed by IEND chunk) */
453405 if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf))
453406 {
453407 *pLen_out = 0;
453408 MZ_FREE(pComp);
453409 MZ_FREE(out_buf.m_pBuf);
453410 return NULL;
453411 }
453412 c = (mz_uint32)mz_crc32(MZ_CRC32_INIT, out_buf.m_pBuf + 41 - 4, *pLen_out + 4);
453413 for (i = 0; i < 4; ++i, c <<= 8)
453414 (out_buf.m_pBuf + out_buf.m_size - 16)[i] = (mz_uint8)(c >> 24);
453415 /* compute final size of file, grab compressed data buffer and return */
453416 *pLen_out += 57;
453417 MZ_FREE(pComp);
453418 return out_buf.m_pBuf;
453419}
z

◆ tdefl_write_image_to_png_file_in_memory()

void * duckdb_miniz::tdefl_write_image_to_png_file_in_memory ( const void * pImage,
int w,
int h,
int num_chans,
size_t * pLen_out )
453421{
453422 /* Level 6 corresponds to TDEFL_DEFAULT_MAX_PROBES or MZ_DEFAULT_LEVEL (but we can't depend on MZ_DEFAULT_LEVEL being available in case the zlib API's where #defined out) */
453423 return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE);
453424}

◆ tdefl_compress_mem_to_output()

mz_bool duckdb_miniz::tdefl_compress_mem_to_output ( const void * pBuf,
size_t buf_len,
tdefl_put_buf_func_ptr pPut_buf_func,
void * pPut_buf_user,
int flags )
453237{
453238 tdefl_compressor *pComp;
453239 mz_bool succeeded;
453240 if (((buf_len) && (!pBuf)) || (!pPut_buf_func))
453241 return MZ_FALSE;
453242 pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor));
453243 if (!pComp)
453244 return MZ_FALSE;
453245 succeeded = (tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY);
453246 succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE);
453247 MZ_FREE(pComp);
453248 return succeeded;
453249}

◆ tdefl_init()

tdefl_status duckdb_miniz::tdefl_init ( tdefl_compressor * d,
tdefl_put_buf_func_ptr pPut_buf_func,
void * pPut_buf_user,
int flags )
453192{
453193 d->m_pPut_buf_func = pPut_buf_func;
453194 d->m_pPut_buf_user = pPut_buf_user;
453195 d->m_flags = (mz_uint)(flags);
453196 d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3;
453197 d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0;
453198 d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
453199 if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG))
453200 MZ_CLEAR_OBJ(d->m_hash);
453201 d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0;
453202 d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0;
453203 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
453204 d->m_pLZ_flags = d->m_lz_code_buf;
453205 d->m_num_flags_left = 8;
453206 d->m_pOutput_buf = d->m_output_buf;
453207 d->m_pOutput_buf_end = d->m_output_buf;
453208 d->m_prev_return_status = TDEFL_STATUS_OKAY;
453209 d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0;
453210 d->m_adler32 = 1;
453211 d->m_pIn_buf = NULL;
453212 d->m_pOut_buf = NULL;
453213 d->m_pIn_buf_size = NULL;
453214 d->m_pOut_buf_size = NULL;
453215 d->m_flush = TDEFL_NO_FLUSH;
453216 d->m_pSrc = NULL;
453217 d->m_src_buf_left = 0;
453218 d->m_out_buf_ofs = 0;
453219 if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG))
453220 MZ_CLEAR_OBJ(d->m_dict);
453221 memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
453222 memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
453223 return TDEFL_STATUS_OKAY;
453224}

◆ tdefl_compress()

tdefl_status duckdb_miniz::tdefl_compress ( tdefl_compressor * d,
const void * pIn_buf,
size_t * pIn_buf_size,
void * pOut_buf,
size_t * pOut_buf_size,
tdefl_flush flush )
453118{
453119 if (!d)
453120 {
453121 if (pIn_buf_size)
453122 *pIn_buf_size = 0;
453123 if (pOut_buf_size)
453124 *pOut_buf_size = 0;
453125 return TDEFL_STATUS_BAD_PARAM;
453126 }
453127
453128 d->m_pIn_buf = pIn_buf;
453129 d->m_pIn_buf_size = pIn_buf_size;
453130 d->m_pOut_buf = pOut_buf;
453131 d->m_pOut_buf_size = pOut_buf_size;
453132 d->m_pSrc = (const mz_uint8 *)(pIn_buf);
453133 d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0;
453134 d->m_out_buf_ofs = 0;
453135 d->m_flush = flush;
453136
453137 if (((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) ||
453138 (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf))
453139 {
453140 if (pIn_buf_size)
453141 *pIn_buf_size = 0;
453142 if (pOut_buf_size)
453143 *pOut_buf_size = 0;
453144 return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM);
453145 }
453146 d->m_wants_to_finish |= (flush == TDEFL_FINISH);
453147
453148 if ((d->m_output_flush_remaining) || (d->m_finished))
453149 return (d->m_prev_return_status = tdefl_flush_output_buffer(d));
453150
453151#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
453152 if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) &&
453153 ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) &&
453154 ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0))
453155 {
453156 if (!tdefl_compress_fast(d))
453157 return d->m_prev_return_status;
453158 }
453159 else
453160#endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN */
453161 {
453162 if (!tdefl_compress_normal(d))
453163 return d->m_prev_return_status;
453164 }
453165
453166 if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf))
453167 d->m_adler32 = (mz_uint32)mz_adler32(d->m_adler32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf);
453168
453169 if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining))
453170 {
453171 if (tdefl_flush_block(d, flush) < 0)
453172 return d->m_prev_return_status;
453173 d->m_finished = (flush == TDEFL_FINISH);
453174 if (flush == TDEFL_FULL_FLUSH)
453175 {
453176 MZ_CLEAR_OBJ(d->m_hash);
453177 MZ_CLEAR_OBJ(d->m_next);
453178 d->m_dict_size = 0;
453179 }
453180 }
453181
453182 return (d->m_prev_return_status = tdefl_flush_output_buffer(d));
453183}

◆ tdefl_compress_buffer()

tdefl_status duckdb_miniz::tdefl_compress_buffer ( tdefl_compressor * d,
const void * pIn_buf,
size_t in_buf_size,
tdefl_flush flush )
453186{
453187 MZ_ASSERT(d->m_pPut_buf_func);
453188 return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush);
453189}

◆ tdefl_get_prev_return_status()

tdefl_status duckdb_miniz::tdefl_get_prev_return_status ( tdefl_compressor * d)
453227{
453228 return d->m_prev_return_status;
453229}

◆ tdefl_get_adler32()

mz_uint32 duckdb_miniz::tdefl_get_adler32 ( tdefl_compressor * d)
453232{
453233 return d->m_adler32;
453234}

◆ tdefl_create_comp_flags_from_zip_params()

mz_uint duckdb_miniz::tdefl_create_comp_flags_from_zip_params ( int level,
int window_bits,
int strategy )
453315{
453316 mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
453317 if (window_bits > 0)
453318 comp_flags |= TDEFL_WRITE_ZLIB_HEADER;
453319
453320 if (!level)
453321 comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
453322 else if (strategy == MZ_FILTERED)
453323 comp_flags |= TDEFL_FILTER_MATCHES;
453324 else if (strategy == MZ_HUFFMAN_ONLY)
453325 comp_flags &= ~TDEFL_MAX_PROBES_MASK;
453326 else if (strategy == MZ_FIXED)
453327 comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS;
453328 else if (strategy == MZ_RLE)
453329 comp_flags |= TDEFL_RLE_MATCHES;
453330
453331 return comp_flags;
453332}

◆ tdefl_compressor_alloc()

tdefl_compressor * duckdb_miniz::tdefl_compressor_alloc ( )
453430{
453431 return (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor));
453432}

◆ tdefl_compressor_free()

void duckdb_miniz::tdefl_compressor_free ( tdefl_compressor * pComp)
453435{
453436 MZ_FREE(pComp);
453437}

◆ tinfl_decompress_mem_to_heap()

void * duckdb_miniz::tinfl_decompress_mem_to_heap ( const void * pSrc_buf,
size_t src_buf_len,
size_t * pOut_len,
int flags )
454083{
454084 tinfl_decompressor decomp;
454085 void *pBuf = NULL, *pNew_buf;
454086 size_t src_buf_ofs = 0, out_buf_capacity = 0;
454087 *pOut_len = 0;
454088 tinfl_init(&decomp);
454089 for (;;)
454090 {
454091 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
454092 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8 *)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8 *)pBuf, pBuf ? (mz_uint8 *)pBuf + *pOut_len : NULL, &dst_buf_size,
454093 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
454094 if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
454095 {
454096 MZ_FREE(pBuf);
454097 *pOut_len = 0;
454098 return NULL;
454099 }
454100 src_buf_ofs += src_buf_size;
454101 *pOut_len += dst_buf_size;
454102 if (status == TINFL_STATUS_DONE)
454103 break;
454104 new_out_buf_capacity = out_buf_capacity * 2;
454105 if (new_out_buf_capacity < 128)
454106 new_out_buf_capacity = 128;
454107 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
454108 if (!pNew_buf)
454109 {
454110 MZ_FREE(pBuf);
454111 *pOut_len = 0;
454112 return NULL;
454113 }
454114 pBuf = pNew_buf;
454115 out_buf_capacity = new_out_buf_capacity;
454116 }
454117 return pBuf;
454118}

◆ tinfl_decompress_mem_to_mem()

size_t duckdb_miniz::tinfl_decompress_mem_to_mem ( void * pOut_buf,
size_t out_buf_len,
const void * pSrc_buf,
size_t src_buf_len,
int flags )
454121{
454122 tinfl_decompressor decomp;
454123 tinfl_status status;
454124 tinfl_init(&decomp);
454125 status = tinfl_decompress(&decomp, (const mz_uint8 *)pSrc_buf, &src_buf_len, (mz_uint8 *)pOut_buf, (mz_uint8 *)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
454126 return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
454127}

◆ tinfl_decompress_mem_to_callback()

int duckdb_miniz::tinfl_decompress_mem_to_callback ( const void * pIn_buf,
size_t * pIn_buf_size,
tinfl_put_buf_func_ptr pPut_buf_func,
void * pPut_buf_user,
int flags )
454130{
454131 int result = 0;
454132 tinfl_decompressor decomp;
454133 mz_uint8 *pDict = (mz_uint8 *)MZ_MALLOC(TINFL_LZ_DICT_SIZE);
454134 size_t in_buf_ofs = 0, dict_ofs = 0;
454135 if (!pDict)
454136 return TINFL_STATUS_FAILED;
454137 tinfl_init(&decomp);
454138 for (;;)
454139 {
454140 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
454141 tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8 *)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
454142 (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
454143 in_buf_ofs += in_buf_size;
454144 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user)))
454145 break;
454146 if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
454147 {
454148 result = (status == TINFL_STATUS_DONE);
454149 break;
454150 }
454151 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
454152 }
454153 MZ_FREE(pDict);
454154 *pIn_buf_size = in_buf_ofs;
454155 return result;
454156}

◆ tinfl_decompressor_alloc()

tinfl_decompressor * duckdb_miniz::tinfl_decompressor_alloc ( )
454159{
454160 tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor));
454161 if (pDecomp)
454162 tinfl_init(pDecomp);
454163 return pDecomp;
454164}

◆ tinfl_decompressor_free()

void duckdb_miniz::tinfl_decompressor_free ( tinfl_decompressor * pDecomp)
454167{
454168 MZ_FREE(pDecomp);
454169}

◆ tinfl_decompress()

tinfl_status duckdb_miniz::tinfl_decompress ( tinfl_decompressor * r,
const mz_uint8 * pIn_buf_next,
size_t * pIn_buf_size,
mz_uint8 * pOut_buf_start,
mz_uint8 * pOut_buf_next,
size_t * pOut_buf_size,
const mz_uint32 decomp_flags )
453614{
453615 static const int s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
453616 static const int s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 };
453617 static const int s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 };
453618 static const int s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 };
453619 static const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
453620 static const int s_min_table_sizes[3] = { 257, 1, 4 };
453621
453622 tinfl_status status = TINFL_STATUS_FAILED;
453623 mz_uint32 num_bits, dist, counter, num_extra;
453624 tinfl_bit_buf_t bit_buf;
453625 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
453626 mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
453627 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
453628
453629 /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */
453630 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start))
453631 {
453632 *pIn_buf_size = *pOut_buf_size = 0;
453633 return TINFL_STATUS_BAD_PARAM;
453634 }
453635
453636 num_bits = r->m_num_bits;
453637 bit_buf = r->m_bit_buf;
453638 dist = r->m_dist;
453639 counter = r->m_counter;
453640 num_extra = r->m_num_extra;
453641 dist_from_out_buf_start = r->m_dist_from_out_buf_start;
453642 TINFL_CR_BEGIN
453643
453644 bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0;
453645 r->m_z_adler32 = r->m_check_adler32 = 1;
453646 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
453647 {
453648 TINFL_GET_BYTE(1, r->m_zhdr0);
453649 TINFL_GET_BYTE(2, r->m_zhdr1);
453650 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
453651 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
453652 counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
453653 if (counter)
453654 {
453655 TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED);
453656 }
453657 }
453658
453659 do
453660 {
453661 TINFL_GET_BITS(3, r->m_final, 3);
453662 r->m_type = r->m_final >> 1;
453663 if (r->m_type == 0)
453664 {
453665 TINFL_SKIP_BITS(5, num_bits & 7);
453666 for (counter = 0; counter < 4; ++counter)
453667 {
453668 if (num_bits)
453669 TINFL_GET_BITS(6, r->m_raw_header[counter], 8);
453670 else
453671 TINFL_GET_BYTE(7, r->m_raw_header[counter]);
453672 }
453673 if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8))))
453674 {
453675 TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED);
453676 }
453677 while ((counter) && (num_bits))
453678 {
453679 TINFL_GET_BITS(51, dist, 8);
453680 while (pOut_buf_cur >= pOut_buf_end)
453681 {
453682 TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT);
453683 }
453684 *pOut_buf_cur++ = (mz_uint8)dist;
453685 counter--;
453686 }
453687 while (counter)
453688 {
453689 size_t n;
453690 while (pOut_buf_cur >= pOut_buf_end)
453691 {
453692 TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT);
453693 }
453694 while (pIn_buf_cur >= pIn_buf_end)
453695 {
453696 TINFL_CR_RETURN(38, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS);
453697 }
453698 n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter);
453699 TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n);
453700 pIn_buf_cur += n;
453701 pOut_buf_cur += n;
453702 counter -= (mz_uint)n;
453703 }
453704 }
453705 else if (r->m_type == 3)
453706 {
453707 TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
453708 }
453709 else
453710 {
453711 if (r->m_type == 1)
453712 {
453713 mz_uint8 *p = r->m_tables[0].m_code_size;
453714 mz_uint i;
453715 r->m_table_sizes[0] = 288;
453716 r->m_table_sizes[1] = 32;
453717 TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
453718 for (i = 0; i <= 143; ++i)
453719 *p++ = 8;
453720 for (; i <= 255; ++i)
453721 *p++ = 9;
453722 for (; i <= 279; ++i)
453723 *p++ = 7;
453724 for (; i <= 287; ++i)
453725 *p++ = 8;
453726 }
453727 else
453728 {
453729 for (counter = 0; counter < 3; counter++)
453730 {
453731 TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]);
453732 r->m_table_sizes[counter] += s_min_table_sizes[counter];
453733 }
453734 MZ_CLEAR_OBJ(r->m_tables[2].m_code_size);
453735 for (counter = 0; counter < r->m_table_sizes[2]; counter++)
453736 {
453737 mz_uint s;
453738 TINFL_GET_BITS(14, s, 3);
453739 r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s;
453740 }
453741 r->m_table_sizes[2] = 19;
453742 }
453743 for (; (int)r->m_type >= 0; r->m_type--)
453744 {
453745 int tree_next, tree_cur;
453746 tinfl_huff_table *pTable;
453747 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16];
453748 pTable = &r->m_tables[r->m_type];
453749 MZ_CLEAR_OBJ(total_syms);
453750 MZ_CLEAR_OBJ(pTable->m_look_up);
453751 MZ_CLEAR_OBJ(pTable->m_tree);
453752 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i)
453753 total_syms[pTable->m_code_size[i]]++;
453754 used_syms = 0, total = 0;
453755 next_code[0] = next_code[1] = 0;
453756 for (i = 1; i <= 15; ++i)
453757 {
453758 used_syms += total_syms[i];
453759 next_code[i + 1] = (total = ((total + total_syms[i]) << 1));
453760 }
453761 if ((65536 != total) && (used_syms > 1))
453762 {
453763 TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
453764 }
453765 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
453766 {
453767 mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index];
453768 if (!code_size)
453769 continue;
453770 cur_code = next_code[code_size]++;
453771 for (l = code_size; l > 0; l--, cur_code >>= 1)
453772 rev_code = (rev_code << 1) | (cur_code & 1);
453773 if (code_size <= TINFL_FAST_LOOKUP_BITS)
453774 {
453775 mz_int16 k = (mz_int16)((code_size << 9) | sym_index);
453776 while (rev_code < TINFL_FAST_LOOKUP_SIZE)
453777 {
453778 pTable->m_look_up[rev_code] = k;
453779 rev_code += (1 << code_size);
453780 }
453781 continue;
453782 }
453783 if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)]))
453784 {
453785 pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next;
453786 tree_cur = tree_next;
453787 tree_next -= 2;
453788 }
453789 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
453790 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
453791 {
453792 tree_cur -= ((rev_code >>= 1) & 1);
453793 if (!pTable->m_tree[-tree_cur - 1])
453794 {
453795 pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next;
453796 tree_cur = tree_next;
453797 tree_next -= 2;
453798 }
453799 else
453800 tree_cur = pTable->m_tree[-tree_cur - 1];
453801 }
453802 tree_cur -= ((rev_code >>= 1) & 1);
453803 pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
453804 }
453805 if (r->m_type == 2)
453806 {
453807 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);)
453808 {
453809 mz_uint s;
453810 TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]);
453811 if (dist < 16)
453812 {
453813 r->m_len_codes[counter++] = (mz_uint8)dist;
453814 continue;
453815 }
453816 if ((dist == 16) && (!counter))
453817 {
453818 TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED);
453819 }
453820 num_extra = "\02\03\07"[dist - 16];
453821 TINFL_GET_BITS(18, s, num_extra);
453822 s += "\03\03\013"[dist - 16];
453823 TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s);
453824 counter += s;
453825 }
453826 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
453827 {
453828 TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
453829 }
453830 TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]);
453831 TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
453832 }
453833 }
453834 for (;;)
453835 {
453836 mz_uint8 *pSrc;
453837 for (;;)
453838 {
453839 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
453840 {
453841 TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
453842 if (counter >= 256)
453843 break;
453844 while (pOut_buf_cur >= pOut_buf_end)
453845 {
453846 TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT);
453847 }
453848 *pOut_buf_cur++ = (mz_uint8)counter;
453849 }
453850 else
453851 {
453852 int sym2;
453853 mz_uint code_len;
453854#if TINFL_USE_64BIT_BITBUF
453855 if (num_bits < 30)
453856 {
453857 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits);
453858 pIn_buf_cur += 4;
453859 num_bits += 32;
453860 }
453861#else
453862 if (num_bits < 15)
453863 {
453864 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
453865 pIn_buf_cur += 2;
453866 num_bits += 16;
453867 }
453868#endif
453869 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
453870 code_len = sym2 >> 9;
453871 else
453872 {
453873 code_len = TINFL_FAST_LOOKUP_BITS;
453874 do
453875 {
453876 sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
453877 } while (sym2 < 0);
453878 }
453879 counter = sym2;
453880 bit_buf >>= code_len;
453881 num_bits -= code_len;
453882 if (counter & 256)
453883 break;
453884
453885#if !TINFL_USE_64BIT_BITBUF
453886 if (num_bits < 15)
453887 {
453888 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
453889 pIn_buf_cur += 2;
453890 num_bits += 16;
453891 }
453892#endif
453893 if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
453894 code_len = sym2 >> 9;
453895 else
453896 {
453897 code_len = TINFL_FAST_LOOKUP_BITS;
453898 do
453899 {
453900 sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
453901 } while (sym2 < 0);
453902 }
453903 bit_buf >>= code_len;
453904 num_bits -= code_len;
453905
453906 pOut_buf_cur[0] = (mz_uint8)counter;
453907 if (sym2 & 256)
453908 {
453909 pOut_buf_cur++;
453910 counter = sym2;
453911 break;
453912 }
453913 pOut_buf_cur[1] = (mz_uint8)sym2;
453914 pOut_buf_cur += 2;
453915 }
453916 }
453917 if ((counter &= 511) == 256)
453918 break;
453919
453920 num_extra = s_length_extra[counter - 257];
453921 counter = s_length_base[counter - 257];
453922 if (num_extra)
453923 {
453924 mz_uint extra_bits;
453925 TINFL_GET_BITS(25, extra_bits, num_extra);
453926 counter += extra_bits;
453927 }
453928
453929 TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
453930 num_extra = s_dist_extra[dist];
453931 dist = s_dist_base[dist];
453932 if (num_extra)
453933 {
453934 mz_uint extra_bits;
453935 TINFL_GET_BITS(27, extra_bits, num_extra);
453936 dist += extra_bits;
453937 }
453938
453939 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
453940 if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
453941 {
453942 TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED);
453943 }
453944
453945 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
453946
453947 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
453948 {
453949 while (counter--)
453950 {
453951 while (pOut_buf_cur >= pOut_buf_end)
453952 {
453953 TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT);
453954 }
453955 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
453956 }
453957 continue;
453958 }
453959#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
453960 else if ((counter >= 9) && (counter <= dist))
453961 {
453962 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
453963 do
453964 {
453965 ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0];
453966 ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1];
453967 pOut_buf_cur += 8;
453968 } while ((pSrc += 8) < pSrc_end);
453969 if ((counter &= 7) < 3)
453970 {
453971 if (counter)
453972 {
453973 pOut_buf_cur[0] = pSrc[0];
453974 if (counter > 1)
453975 pOut_buf_cur[1] = pSrc[1];
453976 pOut_buf_cur += counter;
453977 }
453978 continue;
453979 }
453980 }
453981#endif
453982 while(counter>2)
453983 {
453984 pOut_buf_cur[0] = pSrc[0];
453985 pOut_buf_cur[1] = pSrc[1];
453986 pOut_buf_cur[2] = pSrc[2];
453987 pOut_buf_cur += 3;
453988 pSrc += 3;
453989 counter -= 3;
453990 }
453991 if (counter > 0)
453992 {
453993 pOut_buf_cur[0] = pSrc[0];
453994 if (counter > 1)
453995 pOut_buf_cur[1] = pSrc[1];
453996 pOut_buf_cur += counter;
453997 }
453998 }
453999 }
454000 } while (!(r->m_final & 1));
454001
454002 /* Ensure byte alignment and put back any bytes from the bitbuf if we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */
454003 /* I'm being super conservative here. A number of simplifications can be made to the byte alignment part, and the Adler32 check shouldn't ever need to worry about reading from the bitbuf now. */
454004 TINFL_SKIP_BITS(32, num_bits & 7);
454005 while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
454006 {
454007 --pIn_buf_cur;
454008 num_bits -= 8;
454009 }
454010 bit_buf &= (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1);
454011 MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with following data (such as gzip streams). */
454012
454013 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
454014 {
454015 for (counter = 0; counter < 4; ++counter)
454016 {
454017 mz_uint s;
454018 if (num_bits)
454019 TINFL_GET_BITS(41, s, 8);
454020 else
454021 TINFL_GET_BYTE(42, s);
454022 r->m_z_adler32 = (r->m_z_adler32 << 8) | s;
454023 }
454024 }
454025 TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE);
454026
454027 TINFL_CR_FINISH
454028
454029common_exit:
454030 /* As long as we aren't telling the caller that we NEED more input to make forward progress: */
454031 /* Put back any bytes from the bitbuf in case we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */
454032 /* We need to be very careful here to NOT push back any bytes we definitely know we need to make forward progress, though, or we'll lock the caller up into an inf loop. */
454033 if ((status != TINFL_STATUS_NEEDS_MORE_INPUT) && (status != TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS))
454034 {
454035 while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
454036 {
454037 --pIn_buf_cur;
454038 num_bits -= 8;
454039 }
454040 }
454041 r->m_num_bits = num_bits;
454042 r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1);
454043 r->m_dist = dist;
454044 r->m_counter = counter;
454045 r->m_num_extra = num_extra;
454046 r->m_dist_from_out_buf_start = dist_from_out_buf_start;
454047 *pIn_buf_size = pIn_buf_cur - pIn_buf_next;
454048 *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
454049 if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
454050 {
454051 const mz_uint8 *ptr = pOut_buf_next;
454052 size_t buf_len = *pOut_buf_size;
454053 mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16;
454054 size_t block_len = buf_len % 5552;
454055 while (buf_len)
454056 {
454057 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
454058 {
454059 s1 += ptr[0], s2 += s1;
454060 s1 += ptr[1], s2 += s1;
454061 s1 += ptr[2], s2 += s1;
454062 s1 += ptr[3], s2 += s1;
454063 s1 += ptr[4], s2 += s1;
454064 s1 += ptr[5], s2 += s1;
454065 s1 += ptr[6], s2 += s1;
454066 s1 += ptr[7], s2 += s1;
454067 }
454068 for (; i < block_len; ++i)
454069 s1 += *ptr++, s2 += s1;
454070 s1 %= 65521U, s2 %= 65521U;
454071 buf_len -= block_len;
454072 block_len = 5552;
454073 }
454074 r->m_check_adler32 = (s2 << 16) + s1;
454075 if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32))
454076 status = TINFL_STATUS_ADLER32_MISMATCH;
454077 }
454078 return status;
454079}
#define TINFL_MEMCPY(d, s, l)
Definition duckdb.cpp:453474
Definition duckdb.cpp:76656

◆ mz_zip_reader_init()

mz_bool duckdb_miniz::mz_zip_reader_init ( mz_zip_archive * pZip,
mz_uint64 size,
mz_uint flags )
455044{
455045 if ((!pZip) || (!pZip->m_pRead))
455046 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455047
455048 if (!mz_zip_reader_init_internal(pZip, flags))
455049 return MZ_FALSE;
455050
455051 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
455052 pZip->m_archive_size = size;
455053
455054 if (!mz_zip_reader_read_central_dir(pZip, flags))
455055 {
455056 mz_zip_reader_end_internal(pZip, MZ_FALSE);
455057 return MZ_FALSE;
455058 }
455059
455060 return MZ_TRUE;
455061}

◆ mz_zip_reader_init_mem()

mz_bool duckdb_miniz::mz_zip_reader_init_mem ( mz_zip_archive * pZip,
const void * pMem,
size_t size,
mz_uint flags )
455072{
455073 if (!pMem)
455074 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455075
455076 if (size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
455077 return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
455078
455079 if (!mz_zip_reader_init_internal(pZip, flags))
455080 return MZ_FALSE;
455081
455082 pZip->m_zip_type = MZ_ZIP_TYPE_MEMORY;
455083 pZip->m_archive_size = size;
455084 pZip->m_pRead = mz_zip_mem_read_func;
455085 pZip->m_pIO_opaque = pZip;
455086 pZip->m_pNeeds_keepalive = NULL;
455087
455088#ifdef __cplusplus
455089 pZip->m_pState->m_pMem = const_cast<void *>(pMem);
455090#else
455091 pZip->m_pState->m_pMem = (void *)pMem;
455092#endif
455093
455094 pZip->m_pState->m_mem_size = size;
455095
455096 if (!mz_zip_reader_read_central_dir(pZip, flags))
455097 {
455098 mz_zip_reader_end_internal(pZip, MZ_FALSE);
455099 return MZ_FALSE;
455100 }
455101
455102 return MZ_TRUE;
455103}

◆ mz_zip_reader_end()

mz_bool duckdb_miniz::mz_zip_reader_end ( mz_zip_archive * pZip)
455040{
455041 return mz_zip_reader_end_internal(pZip, MZ_TRUE);
455042}

◆ mz_zip_zero_struct()

void duckdb_miniz::mz_zip_zero_struct ( mz_zip_archive * pZip)
454987{
454988 if (pZip)
454989 MZ_CLEAR_OBJ(*pZip);
454990}

◆ mz_zip_get_mode()

mz_zip_mode duckdb_miniz::mz_zip_get_mode ( mz_zip_archive * pZip)
458616{
458617 return pZip ? pZip->m_zip_mode : MZ_ZIP_MODE_INVALID;
458618}

◆ mz_zip_get_type()

mz_zip_type duckdb_miniz::mz_zip_get_type ( mz_zip_archive * pZip)
458621{
458622 return pZip ? pZip->m_zip_type : MZ_ZIP_TYPE_INVALID;
458623}

◆ mz_zip_reader_get_num_files()

mz_uint duckdb_miniz::mz_zip_reader_get_num_files ( mz_zip_archive * pZip)
458757{
458758 return pZip ? pZip->m_total_files : 0;
458759}

◆ mz_zip_get_archive_size()

mz_uint64 duckdb_miniz::mz_zip_get_archive_size ( mz_zip_archive * pZip)
458762{
458763 if (!pZip)
458764 return 0;
458765 return pZip->m_archive_size;
458766}

◆ mz_zip_get_archive_file_start_offset()

mz_uint64 duckdb_miniz::mz_zip_get_archive_file_start_offset ( mz_zip_archive * pZip)
458769{
458770 if ((!pZip) || (!pZip->m_pState))
458771 return 0;
458772 return pZip->m_pState->m_file_archive_start_ofs;
458773}

◆ mz_zip_get_cfile()

MZ_FILE * duckdb_miniz::mz_zip_get_cfile ( mz_zip_archive * pZip)
458776{
458777 if ((!pZip) || (!pZip->m_pState))
458778 return 0;
458779 return pZip->m_pState->m_pFile;
458780}

◆ mz_zip_read_archive_data()

size_t duckdb_miniz::mz_zip_read_archive_data ( mz_zip_archive * pZip,
mz_uint64 file_ofs,
void * pBuf,
size_t n )
458783{
458784 if ((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pZip->m_pRead))
458785 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458786
458787 return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n);
458788}

◆ mz_zip_set_last_error()

mz_zip_error duckdb_miniz::mz_zip_set_last_error ( mz_zip_archive * pZip,
mz_zip_error err_num )
458626{
458627 mz_zip_error prev_err;
458628
458629 if (!pZip)
458630 return MZ_ZIP_INVALID_PARAMETER;
458631
458632 prev_err = pZip->m_last_error;
458633
458634 pZip->m_last_error = err_num;
458635 return prev_err;
458636}

◆ mz_zip_peek_last_error()

mz_zip_error duckdb_miniz::mz_zip_peek_last_error ( mz_zip_archive * pZip)
458639{
458640 if (!pZip)
458641 return MZ_ZIP_INVALID_PARAMETER;
458642
458643 return pZip->m_last_error;
458644}

◆ mz_zip_clear_last_error()

mz_zip_error duckdb_miniz::mz_zip_clear_last_error ( mz_zip_archive * pZip)
458647{
458648 return mz_zip_set_last_error(pZip, MZ_ZIP_NO_ERROR);
458649}

◆ mz_zip_get_last_error()

mz_zip_error duckdb_miniz::mz_zip_get_last_error ( mz_zip_archive * pZip)
458652{
458653 mz_zip_error prev_err;
458654
458655 if (!pZip)
458656 return MZ_ZIP_INVALID_PARAMETER;
458657
458658 prev_err = pZip->m_last_error;
458659
458660 pZip->m_last_error = MZ_ZIP_NO_ERROR;
458661 return prev_err;
458662}

◆ mz_zip_get_error_string()

const char * duckdb_miniz::mz_zip_get_error_string ( mz_zip_error mz_err)
458665{
458666 switch (mz_err)
458667 {
458668 case MZ_ZIP_NO_ERROR:
458669 return "no error";
458670 case MZ_ZIP_UNDEFINED_ERROR:
458671 return "undefined error";
458672 case MZ_ZIP_TOO_MANY_FILES:
458673 return "too many files";
458674 case MZ_ZIP_FILE_TOO_LARGE:
458675 return "file too large";
458676 case MZ_ZIP_UNSUPPORTED_METHOD:
458677 return "unsupported method";
458678 case MZ_ZIP_UNSUPPORTED_ENCRYPTION:
458679 return "unsupported encryption";
458680 case MZ_ZIP_UNSUPPORTED_FEATURE:
458681 return "unsupported feature";
458682 case MZ_ZIP_FAILED_FINDING_CENTRAL_DIR:
458683 return "failed finding central directory";
458684 case MZ_ZIP_NOT_AN_ARCHIVE:
458685 return "not a ZIP archive";
458686 case MZ_ZIP_INVALID_HEADER_OR_CORRUPTED:
458687 return "invalid header or archive is corrupted";
458688 case MZ_ZIP_UNSUPPORTED_MULTIDISK:
458689 return "unsupported multidisk archive";
458690 case MZ_ZIP_DECOMPRESSION_FAILED:
458691 return "decompression failed or archive is corrupted";
458692 case MZ_ZIP_COMPRESSION_FAILED:
458693 return "compression failed";
458694 case MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE:
458695 return "unexpected decompressed size";
458696 case MZ_ZIP_CRC_CHECK_FAILED:
458697 return "CRC-32 check failed";
458698 case MZ_ZIP_UNSUPPORTED_CDIR_SIZE:
458699 return "unsupported central directory size";
458700 case MZ_ZIP_ALLOC_FAILED:
458701 return "allocation failed";
458702 case MZ_ZIP_FILE_OPEN_FAILED:
458703 return "file open failed";
458704 case MZ_ZIP_FILE_CREATE_FAILED:
458705 return "file create failed";
458706 case MZ_ZIP_FILE_WRITE_FAILED:
458707 return "file write failed";
458708 case MZ_ZIP_FILE_READ_FAILED:
458709 return "file read failed";
458710 case MZ_ZIP_FILE_CLOSE_FAILED:
458711 return "file close failed";
458712 case MZ_ZIP_FILE_SEEK_FAILED:
458713 return "file seek failed";
458714 case MZ_ZIP_FILE_STAT_FAILED:
458715 return "file stat failed";
458716 case MZ_ZIP_INVALID_PARAMETER:
458717 return "invalid parameter";
458718 case MZ_ZIP_INVALID_FILENAME:
458719 return "invalid filename";
458720 case MZ_ZIP_BUF_TOO_SMALL:
458721 return "buffer too small";
458722 case MZ_ZIP_INTERNAL_ERROR:
458723 return "internal error";
458724 case MZ_ZIP_FILE_NOT_FOUND:
458725 return "file not found";
458726 case MZ_ZIP_ARCHIVE_TOO_LARGE:
458727 return "archive is too large";
458728 case MZ_ZIP_VALIDATION_FAILED:
458729 return "validation failed";
458730 case MZ_ZIP_WRITE_CALLBACK_FAILED:
458731 return "write calledback failed";
458732 default:
458733 break;
458734 }
458735
458736 return "unknown error";
458737}

◆ mz_zip_reader_is_file_a_directory()

mz_bool duckdb_miniz::mz_zip_reader_is_file_a_directory ( mz_zip_archive * pZip,
mz_uint file_index )
455278{
455279 mz_uint filename_len, attribute_mapping_id, external_attr;
455280 const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
455281 if (!p)
455282 {
455283 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455284 return MZ_FALSE;
455285 }
455286
455287 filename_len = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
455288 if (filename_len)
455289 {
455290 if (*(p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_len - 1) == '/')
455291 return MZ_TRUE;
455292 }
455293
455294 /* Bugfix: This code was also checking if the internal attribute was non-zero, which wasn't correct. */
455295 /* Most/all zip writers (hopefully) set DOS file/directory attributes in the low 16-bits, so check for the DOS directory flag and ignore the source OS ID in the created by field. */
455296 /* FIXME: Remove this check? Is it necessary - we already check the filename. */
455297 attribute_mapping_id = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS) >> 8;
455298 (void)attribute_mapping_id;
455299
455300 external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS);
455301 if ((external_attr & MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG) != 0)
455302 {
455303 return MZ_TRUE;
455304 }
455305
455306 return MZ_FALSE;
455307}

◆ mz_zip_reader_is_file_encrypted()

mz_bool duckdb_miniz::mz_zip_reader_is_file_encrypted ( mz_zip_archive * pZip,
mz_uint file_index )
455228{
455229 mz_uint m_bit_flag;
455230 const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
455231 if (!p)
455232 {
455233 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455234 return MZ_FALSE;
455235 }
455236
455237 m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
455238 return (m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION)) != 0;
455239}

◆ mz_zip_reader_is_file_supported()

mz_bool duckdb_miniz::mz_zip_reader_is_file_supported ( mz_zip_archive * pZip,
mz_uint file_index )
455242{
455243 mz_uint bit_flag;
455244 mz_uint method;
455245
455246 const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
455247 if (!p)
455248 {
455249 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455250 return MZ_FALSE;
455251 }
455252
455253 method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS);
455254 bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
455255
455256 if ((method != 0) && (method != MZ_DEFLATED))
455257 {
455258 mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
455259 return MZ_FALSE;
455260 }
455261
455262 if (bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION))
455263 {
455264 mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
455265 return MZ_FALSE;
455266 }
455267
455268 if (bit_flag & MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG)
455269 {
455270 mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
455271 return MZ_FALSE;
455272 }
455273
455274 return MZ_TRUE;
455275}

◆ mz_zip_reader_get_filename()

mz_uint duckdb_miniz::mz_zip_reader_get_filename ( mz_zip_archive * pZip,
mz_uint file_index,
char * pFilename,
mz_uint filename_buf_size )
458791{
458792 mz_uint n;
458793 const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
458794 if (!p)
458795 {
458796 if (filename_buf_size)
458797 pFilename[0] = '\0';
458798 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458799 return 0;
458800 }
458801 n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
458802 if (filename_buf_size)
458803 {
458804 n = MZ_MIN(n, filename_buf_size - 1);
458805 memcpy(pFilename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n);
458806 pFilename[n] = '\0';
458807 }
458808 return n + 1;
458809}

◆ mz_zip_reader_locate_file()

int duckdb_miniz::mz_zip_reader_locate_file ( mz_zip_archive * pZip,
const char * pName,
const char * pComment,
mz_uint flags )
455498{
455499 mz_uint32 index;
455500 if (!mz_zip_reader_locate_file_v2(pZip, pName, pComment, flags, &index))
455501 return -1;
455502 else
455503 return (int)index;
455504}
index

◆ mz_zip_reader_locate_file_v2()

mz_bool duckdb_miniz::mz_zip_reader_locate_file_v2 ( mz_zip_archive * pZip,
const char * pName,
const char * pComment,
mz_uint flags,
mz_uint32 * file_index )
455507{
455508 mz_uint file_index;
455509 size_t name_len, comment_len;
455510
455511 if (pIndex)
455512 *pIndex = 0;
455513
455514 if ((!pZip) || (!pZip->m_pState) || (!pName))
455515 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455516
455517 /* See if we can use a binary search */
455518 if (((pZip->m_pState->m_init_flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0) &&
455519 (pZip->m_zip_mode == MZ_ZIP_MODE_READING) &&
455520 ((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size))
455521 {
455522 return mz_zip_locate_file_binary_search(pZip, pName, pIndex);
455523 }
455524
455525 /* Locate the entry by scanning the entire central directory */
455526 name_len = strlen(pName);
455527 if (name_len > MZ_UINT16_MAX)
455528 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455529
455530 comment_len = pComment ? strlen(pComment) : 0;
455531 if (comment_len > MZ_UINT16_MAX)
455532 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455533
455534 for (file_index = 0; file_index < pZip->m_total_files; file_index++)
455535 {
455536 const mz_uint8 *pHeader = &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index));
455537 mz_uint filename_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_FILENAME_LEN_OFS);
455538 const char *pFilename = (const char *)pHeader + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
455539 if (filename_len < name_len)
455540 continue;
455541 if (comment_len)
455542 {
455543 mz_uint file_extra_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_EXTRA_LEN_OFS), file_comment_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_COMMENT_LEN_OFS);
455544 const char *pFile_comment = pFilename + filename_len + file_extra_len;
455545 if ((file_comment_len != comment_len) || (!mz_zip_string_equal(pComment, pFile_comment, file_comment_len, flags)))
455546 continue;
455547 }
455548 if ((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len))
455549 {
455550 int ofs = filename_len - 1;
455551 do
455552 {
455553 if ((pFilename[ofs] == '/') || (pFilename[ofs] == '\\') || (pFilename[ofs] == ':'))
455554 break;
455555 } while (--ofs >= 0);
455556 ofs++;
455557 pFilename += ofs;
455558 filename_len -= ofs;
455559 }
455560 if ((filename_len == name_len) && (mz_zip_string_equal(pName, pFilename, filename_len, flags)))
455561 {
455562 if (pIndex)
455563 *pIndex = file_index;
455564 return MZ_TRUE;
455565 }
455566 }
455567
455568 return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
455569}

◆ mz_zip_reader_file_stat()

mz_bool duckdb_miniz::mz_zip_reader_file_stat ( mz_zip_archive * pZip,
mz_uint file_index,
mz_zip_archive_file_stat * pStat )
458812{
458813 return mz_zip_file_stat_internal(pZip, file_index, mz_zip_get_cdh(pZip, file_index), pStat, NULL);
458814}

◆ mz_zip_is_zip64()

mz_bool duckdb_miniz::mz_zip_is_zip64 ( mz_zip_archive * pZip)
458741{
458742 if ((!pZip) || (!pZip->m_pState))
458743 return MZ_FALSE;
458744
458745 return pZip->m_pState->m_zip64;
458746}

◆ mz_zip_get_central_dir_size()

size_t duckdb_miniz::mz_zip_get_central_dir_size ( mz_zip_archive * pZip)
458749{
458750 if ((!pZip) || (!pZip->m_pState))
458751 return 0;
458752
458753 return pZip->m_pState->m_central_dir.m_size;
458754}

◆ mz_zip_reader_extract_to_mem_no_alloc()

mz_bool duckdb_miniz::mz_zip_reader_extract_to_mem_no_alloc ( mz_zip_archive * pZip,
mz_uint file_index,
void * pBuf,
size_t buf_size,
mz_uint flags,
void * pUser_read_buf,
size_t user_read_buf_size )
455572{
455573 int status = TINFL_STATUS_DONE;
455574 mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
455575 mz_zip_archive_file_stat file_stat;
455576 void *pRead_buf;
455577 mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
455578 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
455579 tinfl_decompressor inflator;
455580
455581 if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
455582 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455583
455584 if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
455585 return MZ_FALSE;
455586
455587 /* A directory or zero length file */
455588 if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
455589 return MZ_TRUE;
455590
455591 /* Encryption and patch files are not supported. */
455592 if (file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG))
455593 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
455594
455595 /* This function only supports decompressing stored and deflate. */
455596 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
455597 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
455598
455599 /* Ensure supplied output buffer is large enough. */
455600 needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
455601 if (buf_size < needed_size)
455602 return mz_zip_set_error(pZip, MZ_ZIP_BUF_TOO_SMALL);
455603
455604 /* Read and parse the local directory entry. */
455605 cur_file_ofs = file_stat.m_local_header_ofs;
455606 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
455607 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
455608
455609 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
455610 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455611
455612 cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
455613 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
455614 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455615
455616 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
455617 {
455618 /* The file is stored or the caller has requested the compressed data. */
455619 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size)
455620 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
455621
455622#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455623 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) == 0)
455624 {
455625 if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
455626 return mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED);
455627 }
455628#endif
455629
455630 return MZ_TRUE;
455631 }
455632
455633 /* Decompress the file either directly from memory or from a file input buffer. */
455634 tinfl_init(&inflator);
455635
455636 if (pZip->m_pState->m_pMem)
455637 {
455638 /* Read directly from the archive in memory. */
455639 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
455640 read_buf_size = read_buf_avail = file_stat.m_comp_size;
455641 comp_remaining = 0;
455642 }
455643 else if (pUser_read_buf)
455644 {
455645 /* Use a user provided read buffer. */
455646 if (!user_read_buf_size)
455647 return MZ_FALSE;
455648 pRead_buf = (mz_uint8 *)pUser_read_buf;
455649 read_buf_size = user_read_buf_size;
455650 read_buf_avail = 0;
455651 comp_remaining = file_stat.m_comp_size;
455652 }
455653 else
455654 {
455655 /* Temporarily allocate a read buffer. */
455656 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
455657 if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
455658 return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
455659
455660 if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
455661 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
455662
455663 read_buf_avail = 0;
455664 comp_remaining = file_stat.m_comp_size;
455665 }
455666
455667 do
455668 {
455669 /* The size_t cast here should be OK because we've verified that the output buffer is >= file_stat.m_uncomp_size above */
455670 size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs);
455671 if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
455672 {
455673 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
455674 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
455675 {
455676 status = TINFL_STATUS_FAILED;
455677 mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
455678 break;
455679 }
455680 cur_file_ofs += read_buf_avail;
455681 comp_remaining -= read_buf_avail;
455682 read_buf_ofs = 0;
455683 }
455684 in_buf_size = (size_t)read_buf_avail;
455685 status = tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0));
455686 read_buf_avail -= in_buf_size;
455687 read_buf_ofs += in_buf_size;
455688 out_buf_ofs += out_buf_size;
455689 } while (status == TINFL_STATUS_NEEDS_MORE_INPUT);
455690
455691 if (status == TINFL_STATUS_DONE)
455692 {
455693 /* Make sure the entire file was decompressed, and check its CRC. */
455694 if (out_buf_ofs != file_stat.m_uncomp_size)
455695 {
455696 mz_zip_set_error(pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE);
455697 status = TINFL_STATUS_FAILED;
455698 }
455699#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455700 else if (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
455701 {
455702 mz_zip_set_error(pZip, MZ_ZIP_CRC_CHECK_FAILED);
455703 status = TINFL_STATUS_FAILED;
455704 }
455705#endif
455706 }
455707
455708 if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf))
455709 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
455710
455711 return status == TINFL_STATUS_DONE;
455712}
Definition duckdb.cpp:76703

◆ mz_zip_reader_extract_file_to_mem_no_alloc()

mz_bool duckdb_miniz::mz_zip_reader_extract_file_to_mem_no_alloc ( mz_zip_archive * pZip,
const char * pFilename,
void * pBuf,
size_t buf_size,
mz_uint flags,
void * pUser_read_buf,
size_t user_read_buf_size )
455715{
455716 mz_uint32 file_index;
455717 if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
455718 return MZ_FALSE;
455719 return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size);
455720}

◆ mz_zip_reader_extract_to_mem()

mz_bool duckdb_miniz::mz_zip_reader_extract_to_mem ( mz_zip_archive * pZip,
mz_uint file_index,
void * pBuf,
size_t buf_size,
mz_uint flags )
455723{
455724 return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0);
455725}

◆ mz_zip_reader_extract_file_to_mem()

mz_bool duckdb_miniz::mz_zip_reader_extract_file_to_mem ( mz_zip_archive * pZip,
const char * pFilename,
void * pBuf,
size_t buf_size,
mz_uint flags )
455728{
455729 return mz_zip_reader_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0);
455730}

◆ mz_zip_reader_extract_to_heap()

void * duckdb_miniz::mz_zip_reader_extract_to_heap ( mz_zip_archive * pZip,
mz_uint file_index,
size_t * pSize,
mz_uint flags )
455733{
455734 mz_uint64 comp_size, uncomp_size, alloc_size;
455735 const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
455736 void *pBuf;
455737
455738 if (pSize)
455739 *pSize = 0;
455740
455741 if (!p)
455742 {
455743 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455744 return NULL;
455745 }
455746
455747 comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
455748 uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
455749
455750 alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
455751 if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
455752 {
455753 mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
455754 return NULL;
455755 }
455756
455757 if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size)))
455758 {
455759 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
455760 return NULL;
455761 }
455762
455763 if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags))
455764 {
455765 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
455766 return NULL;
455767 }
455768
455769 if (pSize)
455770 *pSize = (size_t)alloc_size;
455771 return pBuf;
455772}

◆ mz_zip_reader_extract_file_to_heap()

void * duckdb_miniz::mz_zip_reader_extract_file_to_heap ( mz_zip_archive * pZip,
const char * pFilename,
size_t * pSize,
mz_uint flags )
455775{
455776 mz_uint32 file_index;
455777 if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
455778 {
455779 if (pSize)
455780 *pSize = 0;
455781 return MZ_FALSE;
455782 }
455783 return mz_zip_reader_extract_to_heap(pZip, file_index, pSize, flags);
455784}

◆ mz_zip_reader_extract_to_callback()

mz_bool duckdb_miniz::mz_zip_reader_extract_to_callback ( mz_zip_archive * pZip,
mz_uint file_index,
mz_file_write_func pCallback,
void * pOpaque,
mz_uint flags )
455787{
455788 int status = TINFL_STATUS_DONE;
455789 mz_uint file_crc32 = MZ_CRC32_INIT;
455790 mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
455791 mz_zip_archive_file_stat file_stat;
455792 void *pRead_buf = NULL;
455793 void *pWrite_buf = NULL;
455794 mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
455795 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
455796
455797 if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead))
455798 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455799
455800 if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
455801 return MZ_FALSE;
455802
455803 /* A directory or zero length file */
455804 if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
455805 return MZ_TRUE;
455806
455807 /* Encryption and patch files are not supported. */
455808 if (file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG))
455809 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
455810
455811 /* This function only supports decompressing stored and deflate. */
455812 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
455813 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
455814
455815 /* Read and do some minimal validation of the local directory entry (this doesn't crack the zip64 stuff, which we already have from the central dir) */
455816 cur_file_ofs = file_stat.m_local_header_ofs;
455817 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
455818 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
455819
455820 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
455821 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455822
455823 cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
455824 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
455825 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455826
455827 /* Decompress the file either directly from memory or from a file input buffer. */
455828 if (pZip->m_pState->m_pMem)
455829 {
455830 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
455831 read_buf_size = read_buf_avail = file_stat.m_comp_size;
455832 comp_remaining = 0;
455833 }
455834 else
455835 {
455836 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
455837 if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size)))
455838 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
455839
455840 read_buf_avail = 0;
455841 comp_remaining = file_stat.m_comp_size;
455842 }
455843
455844 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
455845 {
455846 /* The file is stored or the caller has requested the compressed data. */
455847 if (pZip->m_pState->m_pMem)
455848 {
455849 if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX))
455850 return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
455851
455852 if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
455853 {
455854 mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
455855 status = TINFL_STATUS_FAILED;
455856 }
455857 else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
455858 {
455859#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455860 file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size);
455861#endif
455862 }
455863
455864 cur_file_ofs += file_stat.m_comp_size;
455865 out_buf_ofs += file_stat.m_comp_size;
455866 comp_remaining = 0;
455867 }
455868 else
455869 {
455870 while (comp_remaining)
455871 {
455872 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
455873 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
455874 {
455875 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
455876 status = TINFL_STATUS_FAILED;
455877 break;
455878 }
455879
455880#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455881 if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
455882 {
455883 file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)read_buf_avail);
455884 }
455885#endif
455886
455887 if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
455888 {
455889 mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
455890 status = TINFL_STATUS_FAILED;
455891 break;
455892 }
455893
455894 cur_file_ofs += read_buf_avail;
455895 out_buf_ofs += read_buf_avail;
455896 comp_remaining -= read_buf_avail;
455897 }
455898 }
455899 }
455900 else
455901 {
455902 tinfl_decompressor inflator;
455903 tinfl_init(&inflator);
455904
455905 if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
455906 {
455907 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
455908 status = TINFL_STATUS_FAILED;
455909 }
455910 else
455911 {
455912 do
455913 {
455914 mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
455915 size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
455916 if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
455917 {
455918 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
455919 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail)
455920 {
455921 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
455922 status = TINFL_STATUS_FAILED;
455923 break;
455924 }
455925 cur_file_ofs += read_buf_avail;
455926 comp_remaining -= read_buf_avail;
455927 read_buf_ofs = 0;
455928 }
455929
455930 in_buf_size = (size_t)read_buf_avail;
455931 status = tinfl_decompress(&inflator, (const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
455932 read_buf_avail -= in_buf_size;
455933 read_buf_ofs += in_buf_size;
455934
455935 if (out_buf_size)
455936 {
455937 if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
455938 {
455939 mz_zip_set_error(pZip, MZ_ZIP_WRITE_CALLBACK_FAILED);
455940 status = TINFL_STATUS_FAILED;
455941 break;
455942 }
455943
455944#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455945 file_crc32 = (mz_uint32)mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size);
455946#endif
455947 if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size)
455948 {
455949 mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
455950 status = TINFL_STATUS_FAILED;
455951 break;
455952 }
455953 }
455954 } while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT));
455955 }
455956 }
455957
455958 if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
455959 {
455960 /* Make sure the entire file was decompressed, and check its CRC. */
455961 if (out_buf_ofs != file_stat.m_uncomp_size)
455962 {
455963 mz_zip_set_error(pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE);
455964 status = TINFL_STATUS_FAILED;
455965 }
455966#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
455967 else if (file_crc32 != file_stat.m_crc32)
455968 {
455969 mz_zip_set_error(pZip, MZ_ZIP_DECOMPRESSION_FAILED);
455970 status = TINFL_STATUS_FAILED;
455971 }
455972#endif
455973 }
455974
455975 if (!pZip->m_pState->m_pMem)
455976 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
455977
455978 if (pWrite_buf)
455979 pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf);
455980
455981 return status == TINFL_STATUS_DONE;
455982}

◆ mz_zip_reader_extract_file_to_callback()

mz_bool duckdb_miniz::mz_zip_reader_extract_file_to_callback ( mz_zip_archive * pZip,
const char * pFilename,
mz_file_write_func pCallback,
void * pOpaque,
mz_uint flags )
455985{
455986 mz_uint32 file_index;
455987 if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
455988 return MZ_FALSE;
455989
455990 return mz_zip_reader_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags);
455991}

◆ mz_zip_reader_extract_iter_new()

mz_zip_reader_extract_iter_state * duckdb_miniz::mz_zip_reader_extract_iter_new ( mz_zip_archive * pZip,
mz_uint file_index,
mz_uint flags )
455994{
455996 mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
455997 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
455998
455999 /* Argument sanity check */
456000 if ((!pZip) || (!pZip->m_pState))
456001 return NULL;
456002
456003 /* Allocate an iterator status structure */
456004 pState = (mz_zip_reader_extract_iter_state*)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_reader_extract_iter_state));
456005 if (!pState)
456006 {
456007 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456008 return NULL;
456009 }
456010
456011 /* Fetch file details */
456012 if (!mz_zip_reader_file_stat(pZip, file_index, &pState->file_stat))
456013 {
456014 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456015 return NULL;
456016 }
456017
456018 /* Encryption and patch files are not supported. */
456019 if (pState->file_stat.m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG))
456020 {
456021 mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
456022 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456023 return NULL;
456024 }
456025
456026 /* This function only supports decompressing stored and deflate. */
456027 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (pState->file_stat.m_method != 0) && (pState->file_stat.m_method != MZ_DEFLATED))
456028 {
456029 mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
456030 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456031 return NULL;
456032 }
456033
456034 /* Init state - save args */
456035 pState->pZip = pZip;
456036 pState->flags = flags;
456037
456038 /* Init state - reset variables to defaults */
456039 pState->status = TINFL_STATUS_DONE;
456040#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
456041 pState->file_crc32 = MZ_CRC32_INIT;
456042#endif
456043 pState->read_buf_ofs = 0;
456044 pState->out_buf_ofs = 0;
456045 pState->pRead_buf = NULL;
456046 pState->pWrite_buf = NULL;
456047 pState->out_blk_remain = 0;
456048
456049 /* Read and parse the local directory entry. */
456050 pState->cur_file_ofs = pState->file_stat.m_local_header_ofs;
456051 if (pZip->m_pRead(pZip->m_pIO_opaque, pState->cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
456052 {
456053 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
456054 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456055 return NULL;
456056 }
456057
456058 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
456059 {
456060 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456061 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456062 return NULL;
456063 }
456064
456065 pState->cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
456066 if ((pState->cur_file_ofs + pState->file_stat.m_comp_size) > pZip->m_archive_size)
456067 {
456068 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456069 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456070 return NULL;
456071 }
456072
456073 /* Decompress the file either directly from memory or from a file input buffer. */
456074 if (pZip->m_pState->m_pMem)
456075 {
456076 pState->pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + pState->cur_file_ofs;
456077 pState->read_buf_size = pState->read_buf_avail = pState->file_stat.m_comp_size;
456078 pState->comp_remaining = pState->file_stat.m_comp_size;
456079 }
456080 else
456081 {
456082 if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
456083 {
456084 /* Decompression required, therefore intermediate read buffer required */
456085 pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, int(MZ_ZIP_MAX_IO_BUF_SIZE));
456086 if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)pState->read_buf_size)))
456087 {
456088 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456089 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456090 return NULL;
456091 }
456092 }
456093 else
456094 {
456095 /* Decompression not required - we will be reading directly into user buffer, no temp buf required */
456096 pState->read_buf_size = 0;
456097 }
456098 pState->read_buf_avail = 0;
456099 pState->comp_remaining = pState->file_stat.m_comp_size;
456100 }
456101
456102 if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
456103 {
456104 /* Decompression required, init decompressor */
456105 tinfl_init( &pState->inflator );
456106
456107 /* Allocate write buffer */
456108 if (NULL == (pState->pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
456109 {
456110 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456111 if (pState->pRead_buf)
456112 pZip->m_pFree(pZip->m_pAlloc_opaque, pState->pRead_buf);
456113 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456114 return NULL;
456115 }
456116 }
456117
456118 return pState;
456119}

◆ mz_zip_reader_extract_file_iter_new()

mz_zip_reader_extract_iter_state * duckdb_miniz::mz_zip_reader_extract_file_iter_new ( mz_zip_archive * pZip,
const char * pFilename,
mz_uint flags )
456122{
456123 mz_uint32 file_index;
456124
456125 /* Locate file index by name */
456126 if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
456127 return NULL;
456128
456129 /* Construct iterator */
456130 return mz_zip_reader_extract_iter_new(pZip, file_index, flags);
456131}

◆ mz_zip_reader_extract_iter_read()

size_t duckdb_miniz::mz_zip_reader_extract_iter_read ( mz_zip_reader_extract_iter_state * pState,
void * pvBuf,
size_t buf_size )
456134{
456135 size_t copied_to_caller = 0;
456136
456137 /* Argument sanity check */
456138 if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState) || (!pvBuf))
456139 return 0;
456140
456141 if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))
456142 {
456143 /* The file is stored or the caller has requested the compressed data, calc amount to return. */
456144 copied_to_caller = MZ_MIN( buf_size, pState->comp_remaining );
456145
456146 /* Zip is in memory....or requires reading from a file? */
456147 if (pState->pZip->m_pState->m_pMem)
456148 {
456149 /* Copy data to caller's buffer */
456150 memcpy( pvBuf, pState->pRead_buf, copied_to_caller );
456151 pState->pRead_buf = ((mz_uint8*)pState->pRead_buf) + copied_to_caller;
456152 }
456153 else
456154 {
456155 /* Read directly into caller's buffer */
456156 if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pvBuf, copied_to_caller) != copied_to_caller)
456157 {
456158 /* Failed to read all that was asked for, flag failure and alert user */
456159 mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED);
456160 pState->status = TINFL_STATUS_FAILED;
456161 copied_to_caller = 0;
456162 }
456163 }
456164
456165#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
456166 /* Compute CRC if not returning compressed data only */
456167 if (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
456168 pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, (const mz_uint8 *)pvBuf, copied_to_caller);
456169#endif
456170
456171 /* Advance offsets, dec counters */
456172 pState->cur_file_ofs += copied_to_caller;
456173 pState->out_buf_ofs += copied_to_caller;
456174 pState->comp_remaining -= copied_to_caller;
456175 }
456176 else
456177 {
456178 do
456179 {
456180 /* Calc ptr to write buffer - given current output pos and block size */
456181 mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pState->pWrite_buf + (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
456182
456183 /* Calc max output size - given current output pos and block size */
456184 size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
456185
456186 if (!pState->out_blk_remain)
456187 {
456188 /* Read more data from file if none available (and reading from file) */
456189 if ((!pState->read_buf_avail) && (!pState->pZip->m_pState->m_pMem))
456190 {
456191 /* Calc read size */
456192 pState->read_buf_avail = MZ_MIN(pState->read_buf_size, pState->comp_remaining);
456193 if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pState->pRead_buf, (size_t)pState->read_buf_avail) != pState->read_buf_avail)
456194 {
456195 mz_zip_set_error(pState->pZip, MZ_ZIP_FILE_READ_FAILED);
456196 pState->status = TINFL_STATUS_FAILED;
456197 break;
456198 }
456199
456200 /* Advance offsets, dec counters */
456201 pState->cur_file_ofs += pState->read_buf_avail;
456202 pState->comp_remaining -= pState->read_buf_avail;
456203 pState->read_buf_ofs = 0;
456204 }
456205
456206 /* Perform decompression */
456207 in_buf_size = (size_t)pState->read_buf_avail;
456208 pState->status = tinfl_decompress(&pState->inflator, (const mz_uint8 *)pState->pRead_buf + pState->read_buf_ofs, &in_buf_size, (mz_uint8 *)pState->pWrite_buf, pWrite_buf_cur, &out_buf_size, pState->comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
456209 pState->read_buf_avail -= in_buf_size;
456210 pState->read_buf_ofs += in_buf_size;
456211
456212 /* Update current output block size remaining */
456213 pState->out_blk_remain = out_buf_size;
456214 }
456215
456216 if (pState->out_blk_remain)
456217 {
456218 /* Calc amount to return. */
456219 size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain );
456220
456221 /* Copy data to caller's buffer */
456222 memcpy( (uint8_t*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy );
456223
456224#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
456225 /* Perform CRC */
456226 pState->file_crc32 = (mz_uint32)mz_crc32(pState->file_crc32, pWrite_buf_cur, to_copy);
456227#endif
456228
456229 /* Decrement data consumed from block */
456230 pState->out_blk_remain -= to_copy;
456231
456232 /* Inc output offset, while performing sanity check */
456233 if ((pState->out_buf_ofs += to_copy) > pState->file_stat.m_uncomp_size)
456234 {
456235 mz_zip_set_error(pState->pZip, MZ_ZIP_DECOMPRESSION_FAILED);
456236 pState->status = TINFL_STATUS_FAILED;
456237 break;
456238 }
456239
456240 /* Increment counter of data copied to caller */
456241 copied_to_caller += to_copy;
456242 }
456243 } while ( (copied_to_caller < buf_size) && ((pState->status == TINFL_STATUS_NEEDS_MORE_INPUT) || (pState->status == TINFL_STATUS_HAS_MORE_OUTPUT)) );
456244 }
456245
456246 /* Return how many bytes were copied into user buffer */
456247 return copied_to_caller;
456248}

◆ mz_zip_reader_extract_iter_free()

mz_bool duckdb_miniz::mz_zip_reader_extract_iter_free ( mz_zip_reader_extract_iter_state * pState)
456251{
456252 int status;
456253
456254 /* Argument sanity check */
456255 if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState))
456256 return MZ_FALSE;
456257
456258 /* Was decompression completed and requested? */
456259 if ((pState->status == TINFL_STATUS_DONE) && (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
456260 {
456261 /* Make sure the entire file was decompressed, and check its CRC. */
456262 if (pState->out_buf_ofs != pState->file_stat.m_uncomp_size)
456263 {
456264 mz_zip_set_error(pState->pZip, MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE);
456265 pState->status = TINFL_STATUS_FAILED;
456266 }
456267#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
456268 else if (pState->file_crc32 != pState->file_stat.m_crc32)
456269 {
456270 mz_zip_set_error(pState->pZip, MZ_ZIP_DECOMPRESSION_FAILED);
456271 pState->status = TINFL_STATUS_FAILED;
456272 }
456273#endif
456274 }
456275
456276 /* Free buffers */
456277 if (!pState->pZip->m_pState->m_pMem)
456278 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pRead_buf);
456279 if (pState->pWrite_buf)
456280 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pWrite_buf);
456281
456282 /* Save status */
456283 status = pState->status;
456284
456285 /* Free context */
456286 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState);
456287
456288 return status == TINFL_STATUS_DONE;
456289}

◆ mz_zip_validate_file()

mz_bool duckdb_miniz::mz_zip_validate_file ( mz_zip_archive * pZip,
mz_uint file_index,
mz_uint flags )
456374{
456375 mz_zip_archive_file_stat file_stat;
456376 mz_zip_internal_state *pState;
456377 const mz_uint8 *pCentral_dir_header;
456378 mz_bool found_zip64_ext_data_in_cdir = MZ_FALSE;
456379 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
456380 mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
456381 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
456382 mz_uint64 local_header_ofs = 0;
456383 mz_uint32 local_header_filename_len, local_header_extra_len, local_header_crc32;
456384 mz_uint64 local_header_comp_size, local_header_uncomp_size;
456385 mz_uint32 uncomp_crc32 = MZ_CRC32_INIT;
456386 mz_bool has_data_descriptor;
456387 mz_uint32 local_header_bit_flags;
456388
456389 mz_zip_array file_data_array;
456390 mz_zip_array_init(&file_data_array, 1);
456391
456392 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
456393 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456394
456395 if (file_index > pZip->m_total_files)
456396 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456397
456398 pState = pZip->m_pState;
456399
456400 pCentral_dir_header = mz_zip_get_cdh(pZip, file_index);
456401
456402 if (!mz_zip_file_stat_internal(pZip, file_index, pCentral_dir_header, &file_stat, &found_zip64_ext_data_in_cdir))
456403 return MZ_FALSE;
456404
456405 /* A directory or zero length file */
456406 if ((file_stat.m_is_directory) || (!file_stat.m_uncomp_size))
456407 return MZ_TRUE;
456408
456409 /* Encryption and patch files are not supported. */
456410 if (file_stat.m_is_encrypted)
456411 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
456412
456413 /* This function only supports stored and deflate. */
456414 if ((file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED))
456415 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_METHOD);
456416
456417 if (!file_stat.m_is_supported)
456418 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
456419
456420 /* Read and parse the local directory entry. */
456421 local_header_ofs = file_stat.m_local_header_ofs;
456422 if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
456423 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
456424
456425 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
456426 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456427
456428 local_header_filename_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS);
456429 local_header_extra_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
456430 local_header_comp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS);
456431 local_header_uncomp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS);
456432 local_header_crc32 = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_CRC32_OFS);
456433 local_header_bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS);
456434 has_data_descriptor = (local_header_bit_flags & 8) != 0;
456435
456436 if (local_header_filename_len != strlen(file_stat.m_filename))
456437 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456438
456439 if ((local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size) > pZip->m_archive_size)
456440 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456441
456442 if (!mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE))
456443 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456444
456445 if (local_header_filename_len)
456446 {
456447 if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE, file_data_array.m_p, local_header_filename_len) != local_header_filename_len)
456448 {
456449 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
456450 goto handle_failure;
456451 }
456452
456453 /* I've seen 1 archive that had the same pathname, but used backslashes in the local dir and forward slashes in the central dir. Do we care about this? For now, this case will fail validation. */
456454 if (memcmp(file_stat.m_filename, file_data_array.m_p, local_header_filename_len) != 0)
456455 {
456456 mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED);
456457 goto handle_failure;
456458 }
456459 }
456460
456461 if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
456462 {
456463 mz_uint32 extra_size_remaining = local_header_extra_len;
456464 const mz_uint8 *pExtra_data = (const mz_uint8 *)file_data_array.m_p;
456465
456466 if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len, file_data_array.m_p, local_header_extra_len) != local_header_extra_len)
456467 {
456468 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
456469 goto handle_failure;
456470 }
456471
456472 do
456473 {
456474 mz_uint32 field_id, field_data_size, field_total_size;
456475
456476 if (extra_size_remaining < (sizeof(mz_uint16) * 2))
456477 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456478
456479 field_id = MZ_READ_LE16(pExtra_data);
456480 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
456481 field_total_size = field_data_size + sizeof(mz_uint16) * 2;
456482
456483 if (field_total_size > extra_size_remaining)
456484 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456485
456486 if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
456487 {
456488 const mz_uint8 *pSrc_field_data = pExtra_data + sizeof(mz_uint32);
456489
456490 if (field_data_size < sizeof(mz_uint64) * 2)
456491 {
456492 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
456493 goto handle_failure;
456494 }
456495
456496 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
456497 local_header_comp_size = MZ_READ_LE64(pSrc_field_data + sizeof(mz_uint64));
456498
456499 found_zip64_ext_data_in_ldir = MZ_TRUE;
456500 break;
456501 }
456502
456503 pExtra_data += field_total_size;
456504 extra_size_remaining -= field_total_size;
456505 } while (extra_size_remaining);
456506 }
456507
456508 /* TODO: parse local header extra data when local_header_comp_size is 0xFFFFFFFF! (big_descriptor.zip) */
456509 /* I've seen zips in the wild with the data descriptor bit set, but proper local header values and bogus data descriptors */
456510 if ((has_data_descriptor) && (!local_header_comp_size) && (!local_header_crc32))
456511 {
456512 mz_uint8 descriptor_buf[32];
456513 mz_bool has_id;
456514 const mz_uint8 *pSrc;
456515 mz_uint32 file_crc32;
456516 mz_uint64 comp_size = 0, uncomp_size = 0;
456517
456518 mz_uint32 num_descriptor_uint32s = ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) ? 6 : 4;
456519
456520 if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size, descriptor_buf, sizeof(mz_uint32) * num_descriptor_uint32s) != (sizeof(mz_uint32) * num_descriptor_uint32s))
456521 {
456522 mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
456523 goto handle_failure;
456524 }
456525
456526 has_id = (MZ_READ_LE32(descriptor_buf) == MZ_ZIP_DATA_DESCRIPTOR_ID);
456527 pSrc = has_id ? (descriptor_buf + sizeof(mz_uint32)) : descriptor_buf;
456528
456529 file_crc32 = MZ_READ_LE32(pSrc);
456530
456531 if ((pState->m_zip64) || (found_zip64_ext_data_in_ldir))
456532 {
456533 comp_size = MZ_READ_LE64(pSrc + sizeof(mz_uint32));
456534 uncomp_size = MZ_READ_LE64(pSrc + sizeof(mz_uint32) + sizeof(mz_uint64));
456535 }
456536 else
456537 {
456538 comp_size = MZ_READ_LE32(pSrc + sizeof(mz_uint32));
456539 uncomp_size = MZ_READ_LE32(pSrc + sizeof(mz_uint32) + sizeof(mz_uint32));
456540 }
456541
456542 if ((file_crc32 != file_stat.m_crc32) || (comp_size != file_stat.m_comp_size) || (uncomp_size != file_stat.m_uncomp_size))
456543 {
456544 mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED);
456545 goto handle_failure;
456546 }
456547 }
456548 else
456549 {
456550 if ((local_header_crc32 != file_stat.m_crc32) || (local_header_comp_size != file_stat.m_comp_size) || (local_header_uncomp_size != file_stat.m_uncomp_size))
456551 {
456552 mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED);
456553 goto handle_failure;
456554 }
456555 }
456556
456557 mz_zip_array_clear(pZip, &file_data_array);
456558
456559 if ((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0)
456560 {
456561 if (!mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_compute_crc32_callback, &uncomp_crc32, 0))
456562 return MZ_FALSE;
456563
456564 /* 1 more check to be sure, although the extract checks too. */
456565 if (uncomp_crc32 != file_stat.m_crc32)
456566 {
456567 mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED);
456568 return MZ_FALSE;
456569 }
456570 }
456571
456572 return MZ_TRUE;
456573
456574handle_failure:
456575 mz_zip_array_clear(pZip, &file_data_array);
456576 return MZ_FALSE;
456577}
Definition duckdb.cpp:454418

◆ mz_zip_validate_archive()

mz_bool duckdb_miniz::mz_zip_validate_archive ( mz_zip_archive * pZip,
mz_uint flags )
456580{
456581 mz_zip_internal_state *pState;
456582 uint32_t i;
456583
456584 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
456585 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456586
456587 pState = pZip->m_pState;
456588
456589 /* Basic sanity checks */
456590 if (!pState->m_zip64)
456591 {
456592 if (pZip->m_total_files > MZ_UINT16_MAX)
456593 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
456594
456595 if (pZip->m_archive_size > MZ_UINT32_MAX)
456596 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
456597 }
456598 else
456599 {
456600 if (pZip->m_total_files >= MZ_UINT32_MAX)
456601 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
456602
456603 if (pState->m_central_dir.m_size >= MZ_UINT32_MAX)
456604 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
456605 }
456606
456607 for (i = 0; i < pZip->m_total_files; i++)
456608 {
456609 if (MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG & flags)
456610 {
456611 mz_uint32 found_index;
456613
456614 if (!mz_zip_reader_file_stat(pZip, i, &stat))
456615 return MZ_FALSE;
456616
456617 if (!mz_zip_reader_locate_file_v2(pZip, stat.m_filename, NULL, 0, &found_index))
456618 return MZ_FALSE;
456619
456620 /* This check can fail if there are duplicate filenames in the archive (which we don't check for when writing - that's up to the user) */
456621 if (found_index != i)
456622 return mz_zip_set_error(pZip, MZ_ZIP_VALIDATION_FAILED);
456623 }
456624
456625 if (!mz_zip_validate_file(pZip, i, flags))
456626 return MZ_FALSE;
456627 }
456628
456629 return MZ_TRUE;
456630}
::uint32_t uint32_t

◆ mz_zip_validate_mem_archive()

mz_bool duckdb_miniz::mz_zip_validate_mem_archive ( const void * pMem,
size_t size,
mz_uint flags,
mz_zip_error * pErr )
456633{
456634 mz_bool success = MZ_TRUE;
456635 mz_zip_archive zip;
456636 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
456637
456638 if ((!pMem) || (!size))
456639 {
456640 if (pErr)
456641 *pErr = MZ_ZIP_INVALID_PARAMETER;
456642 return MZ_FALSE;
456643 }
456644
456645 mz_zip_zero_struct(&zip);
456646
456647 if (!mz_zip_reader_init_mem(&zip, pMem, size, flags))
456648 {
456649 if (pErr)
456650 *pErr = zip.m_last_error;
456651 return MZ_FALSE;
456652 }
456653
456654 if (!mz_zip_validate_archive(&zip, flags))
456655 {
456656 actual_err = zip.m_last_error;
456657 success = MZ_FALSE;
456658 }
456659
456660 if (!mz_zip_reader_end_internal(&zip, success))
456661 {
456662 if (!actual_err)
456663 actual_err = zip.m_last_error;
456664 success = MZ_FALSE;
456665 }
456666
456667 if (pErr)
456668 *pErr = actual_err;
456669
456670 return success;
456671}
Definition duckdb.cpp:76832

◆ mz_zip_end()

mz_bool duckdb_miniz::mz_zip_end ( mz_zip_archive * pZip)
458817{
458818 if (!pZip)
458819 return MZ_FALSE;
458820
458821 if (pZip->m_zip_mode == MZ_ZIP_MODE_READING)
458822 return mz_zip_reader_end(pZip);
458823#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
458824 else if ((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))
458825 return mz_zip_writer_end(pZip);
458826#endif
458827
458828 return MZ_FALSE;
458829}

◆ mz_zip_writer_init()

mz_bool duckdb_miniz::mz_zip_writer_init ( mz_zip_archive * pZip,
mz_uint64 existing_size )
456876{
456877 return mz_zip_writer_init_v2(pZip, existing_size, 0);
456878}

◆ mz_zip_writer_init_v2()

mz_bool duckdb_miniz::mz_zip_writer_init_v2 ( mz_zip_archive * pZip,
mz_uint64 existing_size,
mz_uint flags )
456827{
456828 mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0;
456829
456830 if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
456831 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456832
456833 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
456834 {
456835 if (!pZip->m_pRead)
456836 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456837 }
456838
456839 if (pZip->m_file_offset_alignment)
456840 {
456841 /* Ensure user specified file offset alignment is a power of 2. */
456842 if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1))
456843 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456844 }
456845
456846 if (!pZip->m_pAlloc)
456847 pZip->m_pAlloc = miniz_def_alloc_func;
456848 if (!pZip->m_pFree)
456849 pZip->m_pFree = miniz_def_free_func;
456850 if (!pZip->m_pRealloc)
456851 pZip->m_pRealloc = miniz_def_realloc_func;
456852
456853 pZip->m_archive_size = existing_size;
456854 pZip->m_central_directory_file_ofs = 0;
456855 pZip->m_total_files = 0;
456856
456857 if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state))))
456858 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456859
456860 memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state));
456861
456862 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8));
456863 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32));
456864 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32));
456865
456866 pZip->m_pState->m_zip64 = zip64;
456867 pZip->m_pState->m_zip64_has_extended_info_fields = zip64;
456868
456869 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
456870 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
456871
456872 return MZ_TRUE;
456873}

◆ mz_zip_writer_init_heap()

mz_bool duckdb_miniz::mz_zip_writer_init_heap ( mz_zip_archive * pZip,
size_t size_to_reserve_at_beginning,
size_t initial_allocation_size )
456909{
456910 return mz_zip_writer_init_heap_v2(pZip, size_to_reserve_at_beginning, initial_allocation_size, 0);
456911}

◆ mz_zip_writer_init_heap_v2()

mz_bool duckdb_miniz::mz_zip_writer_init_heap_v2 ( mz_zip_archive * pZip,
size_t size_to_reserve_at_beginning,
size_t initial_allocation_size,
mz_uint flags )
456881{
456882 pZip->m_pWrite = mz_zip_heap_write_func;
456883 pZip->m_pNeeds_keepalive = NULL;
456884
456885 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
456886 pZip->m_pRead = mz_zip_mem_read_func;
456887
456888 pZip->m_pIO_opaque = pZip;
456889
456890 if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags))
456891 return MZ_FALSE;
456892
456893 pZip->m_zip_type = MZ_ZIP_TYPE_HEAP;
456894
456895 if (0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning)))
456896 {
456897 if (NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size)))
456898 {
456899 mz_zip_writer_end_internal(pZip, MZ_FALSE);
456900 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456901 }
456902 pZip->m_pState->m_mem_capacity = initial_allocation_size;
456903 }
456904
456905 return MZ_TRUE;
456906}

◆ mz_zip_writer_init_from_reader()

mz_bool duckdb_miniz::mz_zip_writer_init_from_reader ( mz_zip_archive * pZip,
const char * pFilename )
457091{
457092 return mz_zip_writer_init_from_reader_v2(pZip, pFilename, 0);
457093}

◆ mz_zip_writer_init_from_reader_v2()

mz_bool duckdb_miniz::mz_zip_writer_init_from_reader_v2 ( mz_zip_archive * pZip,
const char * pFilename,
mz_uint flags )
457004{
457005 mz_zip_internal_state *pState;
457006
457007 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
457008 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457009
457010 if (flags & MZ_ZIP_FLAG_WRITE_ZIP64)
457011 {
457012 /* We don't support converting a non-zip64 file to zip64 - this seems like more trouble than it's worth. (What about the existing 32-bit data descriptors that could follow the compressed data?) */
457013 if (!pZip->m_pState->m_zip64)
457014 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457015 }
457016
457017 /* No sense in trying to write to an archive that's already at the support max size */
457018 if (pZip->m_pState->m_zip64)
457019 {
457020 if (pZip->m_total_files == MZ_UINT32_MAX)
457021 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
457022 }
457023 else
457024 {
457025 if (pZip->m_total_files == MZ_UINT16_MAX)
457026 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
457027
457028 if ((pZip->m_archive_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP_LOCAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX)
457029 return mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE);
457030 }
457031
457032 pState = pZip->m_pState;
457033
457034 if (pState->m_pFile)
457035 {
457036#ifdef MINIZ_NO_STDIO
457037 (void)pFilename;
457038 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457039#else
457040 if (pZip->m_pIO_opaque != pZip)
457041 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457042
457043 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
457044 {
457045 if (!pFilename)
457046 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457047
457048 /* Archive is being read from stdio and was originally opened only for reading. Try to reopen as writable. */
457049 if (NULL == (pState->m_pFile = MZ_FREOPEN(pFilename, "r+b", pState->m_pFile)))
457050 {
457051 /* The mz_zip_archive is now in a bogus state because pState->m_pFile is NULL, so just close it. */
457052 mz_zip_reader_end_internal(pZip, MZ_FALSE);
457053 return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
457054 }
457055 }
457056
457057 pZip->m_pWrite = mz_zip_file_write_func;
457058 pZip->m_pNeeds_keepalive = NULL;
457059#endif /* #ifdef MINIZ_NO_STDIO */
457060 }
457061 else if (pState->m_pMem)
457062 {
457063 /* Archive lives in a memory block. Assume it's from the heap that we can resize using the realloc callback. */
457064 if (pZip->m_pIO_opaque != pZip)
457065 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457066
457067 pState->m_mem_capacity = pState->m_mem_size;
457068 pZip->m_pWrite = mz_zip_heap_write_func;
457069 pZip->m_pNeeds_keepalive = NULL;
457070 }
457071 /* Archive is being read via a user provided read function - make sure the user has specified a write function too. */
457072 else if (!pZip->m_pWrite)
457073 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457074
457075 /* Start writing new files at the archive's current central directory location. */
457076 /* TODO: We could add a flag that lets the user start writing immediately AFTER the existing central dir - this would be safer. */
457077 pZip->m_archive_size = pZip->m_central_directory_file_ofs;
457078 pZip->m_central_directory_file_ofs = 0;
457079
457080 /* Clear the sorted central dir offsets, they aren't useful or maintained now. */
457081 /* Even though we're now in write mode, files can still be extracted and verified, but file locates will be slow. */
457082 /* TODO: We could easily maintain the sorted central directory offsets. */
457083 mz_zip_array_clear(pZip, &pZip->m_pState->m_sorted_central_dir_offsets);
457084
457085 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
457086
457087 return MZ_TRUE;
457088}

◆ mz_zip_writer_add_mem()

mz_bool duckdb_miniz::mz_zip_writer_add_mem ( mz_zip_archive * pZip,
const char * pArchive_name,
const void * pBuf,
size_t buf_size,
mz_uint level_and_flags )
457097{
457098 return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0);
457099}

◆ mz_zip_writer_add_mem_ex()

mz_bool duckdb_miniz::mz_zip_writer_add_mem_ex ( mz_zip_archive * pZip,
const char * pArchive_name,
const void * pBuf,
size_t buf_size,
const void * pComment,
mz_uint16 comment_size,
mz_uint level_and_flags,
mz_uint64 uncomp_size,
mz_uint32 uncomp_crc32 )
457283{
457284 return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0);
457285}

◆ mz_zip_writer_add_mem_ex_v2()

mz_bool duckdb_miniz::mz_zip_writer_add_mem_ex_v2 ( mz_zip_archive * pZip,
const char * pArchive_name,
const void * pBuf,
size_t buf_size,
const void * pComment,
mz_uint16 comment_size,
mz_uint level_and_flags,
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 )
457290{
457291 mz_uint16 method = 0, dos_time = 0, dos_date = 0;
457292 mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
457293 mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0;
457294 size_t archive_name_size;
457295 mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
457296 tdefl_compressor *pComp = NULL;
457297 mz_bool store_data_uncompressed;
457298 mz_zip_internal_state *pState;
457299 mz_uint8 *pExtra_data = NULL;
457300 mz_uint32 extra_size = 0;
457301 mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
457302 mz_uint16 bit_flags = 0;
457303
457304 if ((int)level_and_flags < 0)
457305 level_and_flags = MZ_DEFAULT_LEVEL;
457306
457307 if (uncomp_size || (buf_size && !(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
457308 bit_flags |= MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
457309
457310 if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME))
457311 bit_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
457312
457313 level = level_and_flags & 0xF;
457314 store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA));
457315
457316 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION))
457317 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457318
457319 pState = pZip->m_pState;
457320
457321 if (pState->m_zip64)
457322 {
457323 if (pZip->m_total_files == MZ_UINT32_MAX)
457324 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
457325 }
457326 else
457327 {
457328 if (pZip->m_total_files == MZ_UINT16_MAX)
457329 {
457330 pState->m_zip64 = MZ_TRUE;
457331 /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */
457332 }
457333 if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF))
457334 {
457335 pState->m_zip64 = MZ_TRUE;
457336 /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
457337 }
457338 }
457339
457340 if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size))
457341 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457342
457343 if (!mz_zip_writer_validate_archive_name(pArchive_name))
457344 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
457345
457346#ifndef MINIZ_NO_TIME
457347 if (last_modified != NULL)
457348 {
457349 mz_zip_time_t_to_dos_time(*last_modified, &dos_time, &dos_date);
457350 }
457351 else
457352 {
457353 MZ_TIME_T cur_time;
457354 time(&cur_time);
457355 mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
457356 }
457357#endif /* #ifndef MINIZ_NO_TIME */
457358
457359 if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
457360 {
457361 uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size);
457362 uncomp_size = buf_size;
457363 if (uncomp_size <= 3)
457364 {
457365 level = 0;
457366 store_data_uncompressed = MZ_TRUE;
457367 }
457368 }
457369
457370 archive_name_size = strlen(pArchive_name);
457371 if (archive_name_size > MZ_UINT16_MAX)
457372 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
457373
457374 num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip);
457375
457376 /* miniz doesn't support central dirs >= MZ_UINT32_MAX bytes yet */
457377 if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE + comment_size) >= MZ_UINT32_MAX)
457378 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
457379
457380 if (!pState->m_zip64)
457381 {
457382 /* Bail early if the archive would obviously become too large */
457383 if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
457384 + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
457385 pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len
457386 + MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
457387 {
457388 pState->m_zip64 = MZ_TRUE;
457389 /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
457390 }
457391 }
457392
457393 if ((archive_name_size) && (pArchive_name[archive_name_size - 1] == '/'))
457394 {
457395 /* Set DOS Subdirectory attribute bit. */
457396 ext_attributes |= MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG;
457397
457398 /* Subdirectories cannot contain data. */
457399 if ((buf_size) || (uncomp_size))
457400 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
457401 }
457402
457403 /* Try to do any allocations before writing to the archive, so if an allocation fails the file remains unmodified. (A good idea if we're doing an in-place modification.) */
457404 if ((!mz_zip_array_ensure_room(pZip, &pState->m_central_dir, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + (pState->m_zip64 ? MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE : 0))) || (!mz_zip_array_ensure_room(pZip, &pState->m_central_dir_offsets, 1)))
457405 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457406
457407 if ((!store_data_uncompressed) && (buf_size))
457408 {
457409 if (NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor))))
457410 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457411 }
457412
457413 if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes))
457414 {
457415 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457416 return MZ_FALSE;
457417 }
457418
457419 local_dir_header_ofs += num_alignment_padding_bytes;
457420 if (pZip->m_file_offset_alignment)
457421 {
457422 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
457423 }
457424 cur_archive_file_ofs += num_alignment_padding_bytes;
457425
457426 MZ_CLEAR_OBJ(local_dir_header);
457427
457428 if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
457429 {
457430 method = MZ_DEFLATED;
457431 }
457432
457433 if (pState->m_zip64)
457434 {
457435 if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
457436 {
457437 pExtra_data = extra_data;
457438 extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL,
457439 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
457440 }
457441
457442 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))
457443 return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
457444
457445 if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
457446 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457447
457448 cur_archive_file_ofs += sizeof(local_dir_header);
457449
457450 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
457451 {
457452 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457453 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457454 }
457455 cur_archive_file_ofs += archive_name_size;
457456
457457 if (pExtra_data != NULL)
457458 {
457459 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size)
457460 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457461
457462 cur_archive_file_ofs += extra_size;
457463 }
457464 }
457465 else
457466 {
457467 if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
457468 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
457469 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))
457470 return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
457471
457472 if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header))
457473 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457474
457475 cur_archive_file_ofs += sizeof(local_dir_header);
457476
457477 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
457478 {
457479 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457480 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457481 }
457482 cur_archive_file_ofs += archive_name_size;
457483 }
457484
457485 if (user_extra_data_len > 0)
457486 {
457487 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
457488 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457489
457490 cur_archive_file_ofs += user_extra_data_len;
457491 }
457492
457493 if (store_data_uncompressed)
457494 {
457495 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
457496 {
457497 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457498 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457499 }
457500
457501 cur_archive_file_ofs += buf_size;
457502 comp_size = buf_size;
457503 }
457504 else if (buf_size)
457505 {
457507
457508 state.m_pZip = pZip;
457509 state.m_cur_archive_file_ofs = cur_archive_file_ofs;
457510 state.m_comp_size = 0;
457511
457512 if ((tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) ||
457513 (tdefl_compress_buffer(pComp, pBuf, buf_size, TDEFL_FINISH) != TDEFL_STATUS_DONE))
457514 {
457515 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457516 return mz_zip_set_error(pZip, MZ_ZIP_COMPRESSION_FAILED);
457517 }
457518
457519 comp_size = state.m_comp_size;
457520 cur_archive_file_ofs = state.m_cur_archive_file_ofs;
457521 }
457522
457523 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
457524 pComp = NULL;
457525
457526 if (uncomp_size)
457527 {
457528 mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64];
457529 mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32;
457530
457531 MZ_ASSERT(bit_flags & MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR);
457532
457533 MZ_WRITE_LE32(local_dir_footer + 0, MZ_ZIP_DATA_DESCRIPTOR_ID);
457534 MZ_WRITE_LE32(local_dir_footer + 4, uncomp_crc32);
457535 if (pExtra_data == NULL)
457536 {
457537 if (comp_size > MZ_UINT32_MAX)
457538 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
457539
457540 MZ_WRITE_LE32(local_dir_footer + 8, comp_size);
457541 MZ_WRITE_LE32(local_dir_footer + 12, uncomp_size);
457542 }
457543 else
457544 {
457545 MZ_WRITE_LE64(local_dir_footer + 8, comp_size);
457546 MZ_WRITE_LE64(local_dir_footer + 16, uncomp_size);
457547 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE64;
457548 }
457549
457550 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size)
457551 return MZ_FALSE;
457552
457553 cur_archive_file_ofs += local_dir_footer_size;
457554 }
457555
457556 if (pExtra_data != NULL)
457557 {
457558 extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL,
457559 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
457560 }
457561
457562 if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment,
457563 comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
457564 user_extra_data_central, user_extra_data_central_len))
457565 return MZ_FALSE;
457566
457567 pZip->m_total_files++;
457568 pZip->m_archive_size = cur_archive_file_ofs;
457569
457570 return MZ_TRUE;
457571}
Definition duckdb.cpp:457102

◆ mz_zip_writer_add_from_zip_reader()

mz_bool duckdb_miniz::mz_zip_writer_add_from_zip_reader ( mz_zip_archive * pZip,
mz_zip_archive * pSource_zip,
mz_uint src_file_index )
457987{
457988 mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size;
457989 mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs;
457990 mz_uint64 cur_src_file_ofs, cur_dst_file_ofs;
457991 mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
457992 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
457993 mz_uint8 new_central_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE];
457994 size_t orig_central_dir_size;
457995 mz_zip_internal_state *pState;
457996 void *pBuf;
457997 const mz_uint8 *pSrc_central_header;
457998 mz_zip_archive_file_stat src_file_stat;
457999 mz_uint32 src_filename_len, src_comment_len, src_ext_len;
458000 mz_uint32 local_header_filename_size, local_header_extra_len;
458001 mz_uint64 local_header_comp_size, local_header_uncomp_size;
458002 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
458003
458004 /* Sanity checks */
458005 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pSource_zip->m_pRead))
458006 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458007
458008 pState = pZip->m_pState;
458009
458010 /* Don't support copying files from zip64 archives to non-zip64, even though in some cases this is possible */
458011 if ((pSource_zip->m_pState->m_zip64) && (!pZip->m_pState->m_zip64))
458012 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458013
458014 /* Get pointer to the source central dir header and crack it */
458015 if (NULL == (pSrc_central_header = mz_zip_get_cdh(pSource_zip, src_file_index)))
458016 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458017
458018 if (MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_SIG_OFS) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG)
458019 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
458020
458021 src_filename_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_FILENAME_LEN_OFS);
458022 src_comment_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_COMMENT_LEN_OFS);
458023 src_ext_len = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS);
458024 src_central_dir_following_data_size = src_filename_len + src_ext_len + src_comment_len;
458025
458026 /* TODO: We don't support central dir's >= MZ_UINT32_MAX bytes right now (+32 fudge factor in case we need to add more extra data) */
458027 if ((pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_central_dir_following_data_size + 32) >= MZ_UINT32_MAX)
458028 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
458029
458030 num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip);
458031
458032 if (!pState->m_zip64)
458033 {
458034 if (pZip->m_total_files == MZ_UINT16_MAX)
458035 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
458036 }
458037 else
458038 {
458039 /* TODO: Our zip64 support still has some 32-bit limits that may not be worth fixing. */
458040 if (pZip->m_total_files == MZ_UINT32_MAX)
458041 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
458042 }
458043
458044 if (!mz_zip_file_stat_internal(pSource_zip, src_file_index, pSrc_central_header, &src_file_stat, NULL))
458045 return MZ_FALSE;
458046
458047 cur_src_file_ofs = src_file_stat.m_local_header_ofs;
458048 cur_dst_file_ofs = pZip->m_archive_size;
458049
458050 /* Read the source archive's local dir header */
458051 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
458052 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
458053
458054 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
458055 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
458056
458057 cur_src_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE;
458058
458059 /* Compute the total size we need to copy (filename+extra data+compressed data) */
458060 local_header_filename_size = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS);
458061 local_header_extra_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
458062 local_header_comp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS);
458063 local_header_uncomp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS);
458064 src_archive_bytes_remaining = local_header_filename_size + local_header_extra_len + src_file_stat.m_comp_size;
458065
458066 /* Try to find a zip64 extended information field */
458067 if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
458068 {
458069 mz_zip_array file_data_array;
458070 const mz_uint8 *pExtra_data;
458071 mz_uint32 extra_size_remaining = local_header_extra_len;
458072
458073 mz_zip_array_init(&file_data_array, 1);
458074 if (!mz_zip_array_resize(pZip, &file_data_array, local_header_extra_len, MZ_FALSE))
458075 {
458076 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458077 }
458078
458079 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, src_file_stat.m_local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_size, file_data_array.m_p, local_header_extra_len) != local_header_extra_len)
458080 {
458081 mz_zip_array_clear(pZip, &file_data_array);
458082 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
458083 }
458084
458085 pExtra_data = (const mz_uint8 *)file_data_array.m_p;
458086
458087 do
458088 {
458089 mz_uint32 field_id, field_data_size, field_total_size;
458090
458091 if (extra_size_remaining < (sizeof(mz_uint16) * 2))
458092 {
458093 mz_zip_array_clear(pZip, &file_data_array);
458094 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
458095 }
458096
458097 field_id = MZ_READ_LE16(pExtra_data);
458098 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
458099 field_total_size = field_data_size + sizeof(mz_uint16) * 2;
458100
458101 if (field_total_size > extra_size_remaining)
458102 {
458103 mz_zip_array_clear(pZip, &file_data_array);
458104 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
458105 }
458106
458107 if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
458108 {
458109 const mz_uint8 *pSrc_field_data = pExtra_data + sizeof(mz_uint32);
458110
458111 if (field_data_size < sizeof(mz_uint64) * 2)
458112 {
458113 mz_zip_array_clear(pZip, &file_data_array);
458114 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
458115 }
458116
458117 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
458118 local_header_comp_size = MZ_READ_LE64(pSrc_field_data + sizeof(mz_uint64)); /* may be 0 if there's a descriptor */
458119
458120 found_zip64_ext_data_in_ldir = MZ_TRUE;
458121 break;
458122 }
458123
458124 pExtra_data += field_total_size;
458125 extra_size_remaining -= field_total_size;
458126 } while (extra_size_remaining);
458127
458128 mz_zip_array_clear(pZip, &file_data_array);
458129 }
458130
458131 if (!pState->m_zip64)
458132 {
458133 /* Try to detect if the new archive will most likely wind up too big and bail early (+(sizeof(mz_uint32) * 4) is for the optional descriptor which could be present, +64 is a fudge factor). */
458134 /* We also check when the archive is finalized so this doesn't need to be perfect. */
458135 mz_uint64 approx_new_archive_size = cur_dst_file_ofs + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + src_archive_bytes_remaining + (sizeof(mz_uint32) * 4) +
458136 pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_central_dir_following_data_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 64;
458137
458138 if (approx_new_archive_size >= MZ_UINT32_MAX)
458139 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
458140 }
458141
458142 /* Write dest archive padding */
458143 if (!mz_zip_writer_write_zeros(pZip, cur_dst_file_ofs, num_alignment_padding_bytes))
458144 return MZ_FALSE;
458145
458146 cur_dst_file_ofs += num_alignment_padding_bytes;
458147
458148 local_dir_header_ofs = cur_dst_file_ofs;
458149 if (pZip->m_file_offset_alignment)
458150 {
458151 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
458152 }
458153
458154 /* The original zip's local header+ext block doesn't change, even with zip64, so we can just copy it over to the dest zip */
458155 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE)
458156 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458157
458158 cur_dst_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE;
458159
458160 /* Copy over the source archive bytes to the dest archive, also ensure we have enough buf space to handle optional data descriptor */
458161 if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)MZ_MAX(32U, MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining)))))
458162 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458163
458164 while (src_archive_bytes_remaining)
458165 {
458166 n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining);
458167 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n)
458168 {
458169 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458170 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
458171 }
458172 cur_src_file_ofs += n;
458173
458174 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
458175 {
458176 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458177 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458178 }
458179 cur_dst_file_ofs += n;
458180
458181 src_archive_bytes_remaining -= n;
458182 }
458183
458184 /* Now deal with the optional data descriptor */
458185 bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS);
458186 if (bit_flags & 8)
458187 {
458188 /* Copy data descriptor */
458189 if ((pSource_zip->m_pState->m_zip64) || (found_zip64_ext_data_in_ldir))
458190 {
458191 /* src is zip64, dest must be zip64 */
458192
458193 /* name uint32_t's */
458194 /* id 1 (optional in zip64?) */
458195 /* crc 1 */
458196 /* comp_size 2 */
458197 /* uncomp_size 2 */
458198 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, (sizeof(mz_uint32) * 6)) != (sizeof(mz_uint32) * 6))
458199 {
458200 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458201 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
458202 }
458203
458204 n = sizeof(mz_uint32) * ((MZ_READ_LE32(pBuf) == MZ_ZIP_DATA_DESCRIPTOR_ID) ? 6 : 5);
458205 }
458206 else
458207 {
458208 /* src is NOT zip64 */
458209 mz_bool has_id;
458210
458211 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, sizeof(mz_uint32) * 4) != sizeof(mz_uint32) * 4)
458212 {
458213 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458214 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
458215 }
458216
458217 has_id = (MZ_READ_LE32(pBuf) == MZ_ZIP_DATA_DESCRIPTOR_ID);
458218
458219 if (pZip->m_pState->m_zip64)
458220 {
458221 /* dest is zip64, so upgrade the data descriptor */
458222 const mz_uint32 *pSrc_descriptor = (const mz_uint32 *)((const mz_uint8 *)pBuf + (has_id ? sizeof(mz_uint32) : 0));
458223 const mz_uint32 src_crc32 = pSrc_descriptor[0];
458224 const mz_uint64 src_comp_size = pSrc_descriptor[1];
458225 const mz_uint64 src_uncomp_size = pSrc_descriptor[2];
458226
458227 mz_write_le32((mz_uint8 *)pBuf, MZ_ZIP_DATA_DESCRIPTOR_ID);
458228 mz_write_le32((mz_uint8 *)pBuf + sizeof(mz_uint32) * 1, src_crc32);
458229 mz_write_le64((mz_uint8 *)pBuf + sizeof(mz_uint32) * 2, src_comp_size);
458230 mz_write_le64((mz_uint8 *)pBuf + sizeof(mz_uint32) * 4, src_uncomp_size);
458231
458232 n = sizeof(mz_uint32) * 6;
458233 }
458234 else
458235 {
458236 /* dest is NOT zip64, just copy it as-is */
458237 n = sizeof(mz_uint32) * (has_id ? 4 : 3);
458238 }
458239 }
458240
458241 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
458242 {
458243 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458244 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458245 }
458246
458247 cur_src_file_ofs += n;
458248 cur_dst_file_ofs += n;
458249 }
458250 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
458251
458252 /* Finally, add the new central dir header */
458253 orig_central_dir_size = pState->m_central_dir.m_size;
458254
458255 memcpy(new_central_header, pSrc_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE);
458256
458257 if (pState->m_zip64)
458258 {
458259 /* This is the painful part: We need to write a new central dir header + ext block with updated zip64 fields, and ensure the old fields (if any) are not included. */
458260 const mz_uint8 *pSrc_ext = pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_filename_len;
458261 mz_zip_array new_ext_block;
458262
458263 mz_zip_array_init(&new_ext_block, sizeof(mz_uint8));
458264
458265 MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, MZ_UINT32_MAX);
458266 MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, MZ_UINT32_MAX);
458267 MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, MZ_UINT32_MAX);
458268
458269 if (!mz_zip_writer_update_zip64_extension_block(&new_ext_block, pZip, pSrc_ext, src_ext_len, &src_file_stat.m_comp_size, &src_file_stat.m_uncomp_size, &local_dir_header_ofs, NULL))
458270 {
458271 mz_zip_array_clear(pZip, &new_ext_block);
458272 return MZ_FALSE;
458273 }
458274
458275 MZ_WRITE_LE16(new_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS, new_ext_block.m_size);
458276
458277 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE))
458278 {
458279 mz_zip_array_clear(pZip, &new_ext_block);
458280 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458281 }
458282
458283 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, src_filename_len))
458284 {
458285 mz_zip_array_clear(pZip, &new_ext_block);
458286 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458287 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458288 }
458289
458290 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_ext_block.m_p, new_ext_block.m_size))
458291 {
458292 mz_zip_array_clear(pZip, &new_ext_block);
458293 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458294 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458295 }
458296
458297 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + src_filename_len + src_ext_len, src_comment_len))
458298 {
458299 mz_zip_array_clear(pZip, &new_ext_block);
458300 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458301 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458302 }
458303
458304 mz_zip_array_clear(pZip, &new_ext_block);
458305 }
458306 else
458307 {
458308 /* sanity checks */
458309 if (cur_dst_file_ofs > MZ_UINT32_MAX)
458310 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
458311
458312 if (local_dir_header_ofs >= MZ_UINT32_MAX)
458313 return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
458314
458315 MZ_WRITE_LE32(new_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_dir_header_ofs);
458316
458317 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, new_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE))
458318 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458319
458320 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, src_central_dir_following_data_size))
458321 {
458322 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458323 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458324 }
458325 }
458326
458327 /* This shouldn't trigger unless we screwed up during the initial sanity checks */
458328 if (pState->m_central_dir.m_size >= MZ_UINT32_MAX)
458329 {
458330 /* TODO: Support central dirs >= 32-bits in size */
458331 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458332 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
458333 }
458334
458335 n = (mz_uint32)orig_central_dir_size;
458336 if (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &n, 1))
458337 {
458338 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
458339 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
458340 }
458341
458342 pZip->m_total_files++;
458343 pZip->m_archive_size = cur_dst_file_ofs;
458344
458345 return MZ_TRUE;
458346}

◆ mz_zip_writer_finalize_archive()

mz_bool duckdb_miniz::mz_zip_writer_finalize_archive ( mz_zip_archive * pZip)
458349{
458350 mz_zip_internal_state *pState;
458351 mz_uint64 central_dir_ofs, central_dir_size;
458352 mz_uint8 hdr[256];
458353
458354 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
458355 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458356
458357 pState = pZip->m_pState;
458358
458359 if (pState->m_zip64)
458360 {
458361 if ((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX))
458362 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
458363 }
458364 else
458365 {
458366 if ((pZip->m_total_files > MZ_UINT16_MAX) || ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX))
458367 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
458368 }
458369
458370 central_dir_ofs = 0;
458371 central_dir_size = 0;
458372 if (pZip->m_total_files)
458373 {
458374 /* Write central directory */
458375 central_dir_ofs = pZip->m_archive_size;
458376 central_dir_size = pState->m_central_dir.m_size;
458377 pZip->m_central_directory_file_ofs = central_dir_ofs;
458378 if (pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (size_t)central_dir_size) != central_dir_size)
458379 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458380
458381 pZip->m_archive_size += central_dir_size;
458382 }
458383
458384 if (pState->m_zip64)
458385 {
458386 /* Write zip64 end of central directory header */
458387 mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size;
458388
458389 MZ_CLEAR_OBJ(hdr);
458390 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG);
458391 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64));
458392 MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS, 0x031E); /* TODO: always Unix */
458393 MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_NEEDED_OFS, 0x002D);
458394 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, pZip->m_total_files);
458395 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS, pZip->m_total_files);
458396 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_SIZE_OFS, central_dir_size);
458397 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_CDIR_OFS_OFS, central_dir_ofs);
458398 if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)
458399 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458400
458401 pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE;
458402
458403 /* Write zip64 end of central directory locator */
458404 MZ_CLEAR_OBJ(hdr);
458405 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG);
458406 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr);
458407 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1);
458408 if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) != MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE)
458409 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458410
458411 pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE;
458412 }
458413
458414 /* Write end of central directory record */
458415 MZ_CLEAR_OBJ(hdr);
458416 MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG);
458417 MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
458418 MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
458419 MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_SIZE_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_size));
458420 MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_OFS_OFS, MZ_MIN(MZ_UINT32_MAX, central_dir_ofs));
458421
458422 if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
458423 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
458424
458425#ifndef MINIZ_NO_STDIO
458426 if ((pState->m_pFile) && (MZ_FFLUSH(pState->m_pFile) == EOF))
458427 return mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED);
458428#endif /* #ifndef MINIZ_NO_STDIO */
458429
458430 pZip->m_archive_size += MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE;
458431
458432 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED;
458433 return MZ_TRUE;
458434}

◆ mz_zip_writer_finalize_heap_archive()

mz_bool duckdb_miniz::mz_zip_writer_finalize_heap_archive ( mz_zip_archive * pZip,
void ** ppBuf,
size_t * pSize )
458437{
458438 if ((!ppBuf) || (!pSize))
458439 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458440
458441 *ppBuf = NULL;
458442 *pSize = 0;
458443
458444 if ((!pZip) || (!pZip->m_pState))
458445 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458446
458447 if (pZip->m_pWrite != mz_zip_heap_write_func)
458448 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
458449
458450 if (!mz_zip_writer_finalize_archive(pZip))
458451 return MZ_FALSE;
458452
458453 *ppBuf = pZip->m_pState->m_pMem;
458454 *pSize = pZip->m_pState->m_mem_size;
458455 pZip->m_pState->m_pMem = NULL;
458456 pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0;
458457
458458 return MZ_TRUE;
458459}

◆ mz_zip_writer_end()

mz_bool duckdb_miniz::mz_zip_writer_end ( mz_zip_archive * pZip)
458462{
458463 return mz_zip_writer_end_internal(pZip, MZ_TRUE);
458464}

◆ tdefl_radix_sort_syms()

tdefl_sym_freq * duckdb_miniz::tdefl_radix_sort_syms ( mz_uint num_syms,
tdefl_sym_freq * pSyms0,
tdefl_sym_freq * pSyms1 )
static
451987{
451988 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2];
451989 tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1;
451990 MZ_CLEAR_OBJ(hist);
451991 for (i = 0; i < num_syms; i++)
451992 {
451993 mz_uint freq = pSyms0[i].m_key;
451994 hist[freq & 0xFF]++;
451995 hist[256 + ((freq >> 8) & 0xFF)]++;
451996 }
451997 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256]))
451998 total_passes--;
451999 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
452000 {
452001 const mz_uint32 *pHist = &hist[pass << 8];
452002 mz_uint offsets[256], cur_ofs = 0;
452003 for (i = 0; i < 256; i++)
452004 {
452005 offsets[i] = cur_ofs;
452006 cur_ofs += pHist[i];
452007 }
452008 for (i = 0; i < num_syms; i++)
452009 pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
452010 {
452011 tdefl_sym_freq *t = pCur_syms;
452012 pCur_syms = pNew_syms;
452013 pNew_syms = t;
452014 }
452015 }
452016 return pCur_syms;
452017}
Definition duckdb.cpp:451983

◆ tdefl_calculate_minimum_redundancy()

void duckdb_miniz::tdefl_calculate_minimum_redundancy ( tdefl_sym_freq * A,
int n )
static
452021{
452022 int root, leaf, next, avbl, used, dpth;
452023 if (n == 0)
452024 return;
452025 else if (n == 1)
452026 {
452027 A[0].m_key = 1;
452028 return;
452029 }
452030 A[0].m_key += A[1].m_key;
452031 root = 0;
452032 leaf = 2;
452033 for (next = 1; next < n - 1; next++)
452034 {
452035 if (leaf >= n || A[root].m_key < A[leaf].m_key)
452036 {
452037 A[next].m_key = A[root].m_key;
452038 A[root++].m_key = (mz_uint16)next;
452039 }
452040 else
452041 A[next].m_key = A[leaf++].m_key;
452042 if (leaf >= n || (root < next && A[root].m_key < A[leaf].m_key))
452043 {
452044 A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key);
452045 A[root++].m_key = (mz_uint16)next;
452046 }
452047 else
452048 A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
452049 }
452050 A[n - 2].m_key = 0;
452051 for (next = n - 3; next >= 0; next--)
452052 A[next].m_key = A[A[next].m_key].m_key + 1;
452053 avbl = 1;
452054 used = dpth = 0;
452055 root = n - 2;
452056 next = n - 1;
452057 while (avbl > 0)
452058 {
452059 while (root >= 0 && (int)A[root].m_key == dpth)
452060 {
452061 used++;
452062 root--;
452063 }
452064 while (avbl > used)
452065 {
452066 A[next--].m_key = (mz_uint16)(dpth);
452067 avbl--;
452068 }
452069 avbl = 2 * used;
452070 dpth++;
452071 used = 0;
452072 }
452073}

◆ tdefl_huffman_enforce_max_code_size()

void duckdb_miniz::tdefl_huffman_enforce_max_code_size ( int * pNum_codes,
int code_list_len,
int max_code_size )
static
452081{
452082 int i;
452083 mz_uint32 total = 0;
452084 if (code_list_len <= 1)
452085 return;
452086 for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++)
452087 pNum_codes[max_code_size] += pNum_codes[i];
452088 for (i = max_code_size; i > 0; i--)
452089 total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
452090 while (total != (1UL << max_code_size))
452091 {
452092 pNum_codes[max_code_size]--;
452093 for (i = max_code_size - 1; i > 0; i--)
452094 if (pNum_codes[i])
452095 {
452096 pNum_codes[i]--;
452097 pNum_codes[i + 1] += 2;
452098 break;
452099 }
452100 total--;
452101 }
452102}
static int total(const MatShape &shape, int start=-1, int end=-1)

◆ tdefl_optimize_huffman_table()

void duckdb_miniz::tdefl_optimize_huffman_table ( tdefl_compressor * d,
int table_num,
int table_len,
int code_size_limit,
int static_table )
static
452105{
452106 int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE];
452107 mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1];
452108 MZ_CLEAR_OBJ(num_codes);
452109 if (static_table)
452110 {
452111 for (i = 0; i < table_len; i++)
452112 num_codes[d->m_huff_code_sizes[table_num][i]]++;
452113 }
452114 else
452115 {
452116 tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
452117 int num_used_syms = 0;
452118 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
452119 for (i = 0; i < table_len; i++)
452120 if (pSym_count[i])
452121 {
452122 syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i];
452123 syms0[num_used_syms++].m_sym_index = (mz_uint16)i;
452124 }
452125
452126 pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1);
452127 tdefl_calculate_minimum_redundancy(pSyms, num_used_syms);
452128
452129 for (i = 0; i < num_used_syms; i++)
452130 num_codes[pSyms[i].m_key]++;
452131
452132 tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
452133
452134 MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]);
452135 MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
452136 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
452137 for (l = num_codes[i]; l > 0; l--)
452138 d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
452139 }
452140
452141 next_code[1] = 0;
452142 for (j = 0, i = 2; i <= code_size_limit; i++)
452143 next_code[i] = j = ((j + num_codes[i - 1]) << 1);
452144
452145 for (i = 0; i < table_len; i++)
452146 {
452147 mz_uint rev_code = 0, code, code_size;
452148 if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0)
452149 continue;
452150 code = next_code[code_size]++;
452151 for (l = code_size; l > 0; l--, code >>= 1)
452152 rev_code = (rev_code << 1) | (code & 1);
452153 d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
452154 }
452155}

◆ tdefl_start_dynamic_block()

void duckdb_miniz::tdefl_start_dynamic_block ( tdefl_compressor * d)
static
452224{
452225 int num_lit_codes, num_dist_codes, num_bit_lengths;
452226 mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
452227 mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF;
452228
452229 d->m_huff_count[0][256] = 1;
452230
452231 tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE);
452232 tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE);
452233
452234 for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--)
452235 if (d->m_huff_code_sizes[0][num_lit_codes - 1])
452236 break;
452237 for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--)
452238 if (d->m_huff_code_sizes[1][num_dist_codes - 1])
452239 break;
452240
452241 memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
452242 memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
452243 total_code_sizes_to_pack = num_lit_codes + num_dist_codes;
452244 num_packed_code_sizes = 0;
452245 rle_z_count = 0;
452246 rle_repeat_count = 0;
452247
452248 memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
452249 for (i = 0; i < total_code_sizes_to_pack; i++)
452250 {
452251 mz_uint8 code_size = code_sizes_to_pack[i];
452252 if (!code_size)
452253 {
452254 TDEFL_RLE_PREV_CODE_SIZE();
452255 if (++rle_z_count == 138)
452256 {
452257 TDEFL_RLE_ZERO_CODE_SIZE();
452258 }
452259 }
452260 else
452261 {
452262 TDEFL_RLE_ZERO_CODE_SIZE();
452263 if (code_size != prev_code_size)
452264 {
452265 TDEFL_RLE_PREV_CODE_SIZE();
452266 d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1);
452267 packed_code_sizes[num_packed_code_sizes++] = code_size;
452268 }
452269 else if (++rle_repeat_count == 6)
452270 {
452271 TDEFL_RLE_PREV_CODE_SIZE();
452272 }
452273 }
452274 prev_code_size = code_size;
452275 }
452276 if (rle_repeat_count)
452277 {
452278 TDEFL_RLE_PREV_CODE_SIZE();
452279 }
452280 else
452281 {
452282 TDEFL_RLE_ZERO_CODE_SIZE();
452283 }
452284
452285 tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE);
452286
452287 TDEFL_PUT_BITS(2, 2);
452288
452289 TDEFL_PUT_BITS(num_lit_codes - 257, 5);
452290 TDEFL_PUT_BITS(num_dist_codes - 1, 5);
452291
452292 for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--)
452293 if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]])
452294 break;
452295 num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1));
452296 TDEFL_PUT_BITS(num_bit_lengths - 4, 4);
452297 for (i = 0; (int)i < num_bit_lengths; i++)
452298 TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3);
452299
452300 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes;)
452301 {
452302 mz_uint code = packed_code_sizes[packed_code_sizes_index++];
452303 MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
452304 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
452305 if (code >= 16)
452306 TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]);
452307 }
452308}

◆ tdefl_start_static_block()

void duckdb_miniz::tdefl_start_static_block ( tdefl_compressor * d)
static
452311{
452312 mz_uint i;
452313 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
452314
452315 for (i = 0; i <= 143; ++i)
452316 *p++ = 8;
452317 for (; i <= 255; ++i)
452318 *p++ = 9;
452319 for (; i <= 279; ++i)
452320 *p++ = 7;
452321 for (; i <= 287; ++i)
452322 *p++ = 8;
452323
452324 memset(d->m_huff_code_sizes[1], 5, 32);
452325
452326 tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE);
452327 tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE);
452328
452329 TDEFL_PUT_BITS(1, 2);
452330}

◆ tdefl_compress_lz_codes()

mz_bool duckdb_miniz::tdefl_compress_lz_codes ( tdefl_compressor * d)
static
452430{
452431 mz_uint flags;
452432 mz_uint8 *pLZ_codes;
452433
452434 flags = 1;
452435 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
452436 {
452437 if (flags == 1)
452438 flags = *pLZ_codes++ | 0x100;
452439 if (flags & 1)
452440 {
452441 mz_uint sym, num_extra_bits;
452442 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8));
452443 pLZ_codes += 3;
452444
452445 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
452446 TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
452447 TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]);
452448
452449 if (match_dist < 512)
452450 {
452451 sym = s_tdefl_small_dist_sym[match_dist];
452452 num_extra_bits = s_tdefl_small_dist_extra[match_dist];
452453 }
452454 else
452455 {
452456 sym = s_tdefl_large_dist_sym[match_dist >> 8];
452457 num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8];
452458 }
452459 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
452460 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
452461 TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits);
452462 }
452463 else
452464 {
452465 mz_uint lit = *pLZ_codes++;
452466 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
452467 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
452468 }
452469 }
452470
452471 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
452472
452473 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
452474}
static const mz_uint16 s_tdefl_len_sym[256]
Definition duckdb.cpp:451919

◆ tdefl_compress_block()

mz_bool duckdb_miniz::tdefl_compress_block ( tdefl_compressor * d,
mz_bool static_block )
static
452478{
452479 if (static_block)
452480 tdefl_start_static_block(d);
452481 else
452482 tdefl_start_dynamic_block(d);
452483 return tdefl_compress_lz_codes(d);
452484}

◆ tdefl_flush_block()

int duckdb_miniz::tdefl_flush_block ( tdefl_compressor * d,
int flush )
static
452487{
452488 mz_uint saved_bit_buf, saved_bits_in;
452489 mz_uint8 *pSaved_output_buf;
452490 mz_bool comp_block_succeeded = MZ_FALSE;
452491 int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
452492 mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
452493
452494 d->m_pOutput_buf = pOutput_buf_start;
452495 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
452496
452497 MZ_ASSERT(!d->m_output_flush_remaining);
452498 d->m_output_flush_ofs = 0;
452499 d->m_output_flush_remaining = 0;
452500
452501 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
452502 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
452503
452504 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
452505 {
452506 TDEFL_PUT_BITS(0x78, 8);
452507 TDEFL_PUT_BITS(0x01, 8);
452508 }
452509
452510 TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
452511
452512 pSaved_output_buf = d->m_pOutput_buf;
452513 saved_bit_buf = d->m_bit_buffer;
452514 saved_bits_in = d->m_bits_in;
452515
452516 if (!use_raw_block)
452517 comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
452518
452519 /* If the block gets expanded, forget the current contents of the output buffer and send a raw block instead. */
452520 if (((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
452521 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size))
452522 {
452523 mz_uint i;
452524 d->m_pOutput_buf = pSaved_output_buf;
452525 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
452526 TDEFL_PUT_BITS(0, 2);
452527 if (d->m_bits_in)
452528 {
452529 TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
452530 }
452531 for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
452532 {
452533 TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
452534 }
452535 for (i = 0; i < d->m_total_lz_bytes; ++i)
452536 {
452537 TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
452538 }
452539 }
452540 /* Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes. */
452541 else if (!comp_block_succeeded)
452542 {
452543 d->m_pOutput_buf = pSaved_output_buf;
452544 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
452545 tdefl_compress_block(d, MZ_TRUE);
452546 }
452547
452548 if (flush)
452549 {
452550 if (flush == TDEFL_FINISH)
452551 {
452552 if (d->m_bits_in)
452553 {
452554 TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
452555 }
452556 if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER)
452557 {
452558 mz_uint i, a = d->m_adler32;
452559 for (i = 0; i < 4; i++)
452560 {
452561 TDEFL_PUT_BITS((a >> 24) & 0xFF, 8);
452562 a <<= 8;
452563 }
452564 }
452565 }
452566 else
452567 {
452568 mz_uint i, z = 0;
452569 TDEFL_PUT_BITS(0, 3);
452570 if (d->m_bits_in)
452571 {
452572 TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
452573 }
452574 for (i = 2; i; --i, z ^= 0xFFFF)
452575 {
452576 TDEFL_PUT_BITS(z & 0xFFFF, 16);
452577 }
452578 }
452579 }
452580
452581 MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
452582
452583 memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
452584 memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
452585
452586 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
452587 d->m_pLZ_flags = d->m_lz_code_buf;
452588 d->m_num_flags_left = 8;
452589 d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes;
452590 d->m_total_lz_bytes = 0;
452591 d->m_block_index++;
452592
452593 if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
452594 {
452595 if (d->m_pPut_buf_func)
452596 {
452597 *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
452598 if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
452599 return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
452600 }
452601 else if (pOutput_buf_start == d->m_output_buf)
452602 {
452603 int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
452604 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
452605 d->m_out_buf_ofs += bytes_to_copy;
452606 if ((n -= bytes_to_copy) != 0)
452607 {
452608 d->m_output_flush_ofs = bytes_to_copy;
452609 d->m_output_flush_remaining = n;
452610 }
452611 }
452612 else
452613 {
452614 d->m_out_buf_ofs += n;
452615 }
452616 }
452617
452618 return d->m_output_flush_remaining;
452619}

◆ tdefl_find_match()

MZ_FORCEINLINE void duckdb_miniz::tdefl_find_match ( tdefl_compressor * d,
mz_uint lookahead_pos,
mz_uint max_dist,
mz_uint max_match_len,
mz_uint * pMatch_dist,
mz_uint * pMatch_len )
static
452693{
452694 mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
452695 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
452696 const mz_uint8 *s = d->m_dict + pos, *p, *q;
452697 mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
452698 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN);
452699 if (max_match_len <= match_len)
452700 return;
452701 for (;;)
452702 {
452703 for (;;)
452704 {
452705 if (--num_probes_left == 0)
452706 return;
452707#define TDEFL_PROBE \
452708 next_probe_pos = d->m_next[probe_pos]; \
452709 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \
452710 return; \
452711 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
452712 if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) \
452713 break;
452714 TDEFL_PROBE;
452715 TDEFL_PROBE;
452716 TDEFL_PROBE;
452717 }
452718 if (!dist)
452719 break;
452720 p = s;
452721 q = d->m_dict + probe_pos;
452722 for (probe_len = 0; probe_len < max_match_len; probe_len++)
452723 if (*p++ != *q++)
452724 break;
452725 if (probe_len > match_len)
452726 {
452727 *pMatch_dist = dist;
452728 if ((*pMatch_len = match_len = probe_len) == max_match_len)
452729 return;
452730 c0 = d->m_dict[pos + match_len];
452731 c1 = d->m_dict[pos + match_len - 1];
452732 }
452733 }
452734}

◆ tdefl_record_literal()

MZ_FORCEINLINE void duckdb_miniz::tdefl_record_literal ( tdefl_compressor * d,
mz_uint8 lit )
static
452909{
452910 d->m_total_lz_bytes++;
452911 *d->m_pLZ_code_buf++ = lit;
452912 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1);
452913 if (--d->m_num_flags_left == 0)
452914 {
452915 d->m_num_flags_left = 8;
452916 d->m_pLZ_flags = d->m_pLZ_code_buf++;
452917 }
452918 d->m_huff_count[0][lit]++;
452919}

◆ tdefl_record_match()

MZ_FORCEINLINE void duckdb_miniz::tdefl_record_match ( tdefl_compressor * d,
mz_uint match_len,
mz_uint match_dist )
static
452922{
452923 mz_uint32 s0, s1;
452924
452925 MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE));
452926
452927 d->m_total_lz_bytes += match_len;
452928
452929 d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN);
452930
452931 match_dist -= 1;
452932 d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF);
452933 d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8);
452934 d->m_pLZ_code_buf += 3;
452935
452936 *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80);
452937 if (--d->m_num_flags_left == 0)
452938 {
452939 d->m_num_flags_left = 8;
452940 d->m_pLZ_flags = d->m_pLZ_code_buf++;
452941 }
452942
452943 s0 = s_tdefl_small_dist_sym[match_dist & 511];
452944 s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127];
452945 d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
452946
452947 if (match_len >= TDEFL_MIN_MATCH_LEN)
452948 d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
452949}

◆ tdefl_compress_normal()

mz_bool duckdb_miniz::tdefl_compress_normal ( tdefl_compressor * d)
static
452952{
452953 const mz_uint8 *pSrc = d->m_pSrc;
452954 size_t src_buf_left = d->m_src_buf_left;
452955 tdefl_flush flush = d->m_flush;
452956
452957 while ((src_buf_left) || ((flush) && (d->m_lookahead_size)))
452958 {
452959 mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
452960 /* Update dictionary and hash chains. Keeps the lookahead size equal to TDEFL_MAX_MATCH_LEN. */
452961 if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1))
452962 {
452963 mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2;
452964 mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK];
452965 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size);
452966 const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process;
452967 src_buf_left -= num_bytes_to_process;
452968 d->m_lookahead_size += num_bytes_to_process;
452969 while (pSrc != pSrc_end)
452970 {
452971 mz_uint8 c = *pSrc++;
452972 d->m_dict[dst_pos] = c;
452973 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
452974 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
452975 hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
452976 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
452977 d->m_hash[hash] = (mz_uint16)(ins_pos);
452978 dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
452979 ins_pos++;
452980 }
452981 }
452982 else
452983 {
452984 while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
452985 {
452986 mz_uint8 c = *pSrc++;
452987 mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
452988 src_buf_left--;
452989 d->m_dict[dst_pos] = c;
452990 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
452991 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
452992 if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN)
452993 {
452994 mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2;
452995 mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
452996 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
452997 d->m_hash[hash] = (mz_uint16)(ins_pos);
452998 }
452999 }
453000 }
453001 d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size);
453002 if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
453003 break;
453004
453005 /* Simple lazy/greedy parsing state machine. */
453006 len_to_move = 1;
453007 cur_match_dist = 0;
453008 cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1);
453009 cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
453010 if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS))
453011 {
453012 if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS)))
453013 {
453014 mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK];
453015 cur_match_len = 0;
453016 while (cur_match_len < d->m_lookahead_size)
453017 {
453018 if (d->m_dict[cur_pos + cur_match_len] != c)
453019 break;
453020 cur_match_len++;
453021 }
453022 if (cur_match_len < TDEFL_MIN_MATCH_LEN)
453023 cur_match_len = 0;
453024 else
453025 cur_match_dist = 1;
453026 }
453027 }
453028 else
453029 {
453030 tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len);
453031 }
453032 if (((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5)))
453033 {
453034 cur_match_dist = cur_match_len = 0;
453035 }
453036 if (d->m_saved_match_len)
453037 {
453038 if (cur_match_len > d->m_saved_match_len)
453039 {
453040 tdefl_record_literal(d, (mz_uint8)d->m_saved_lit);
453041 if (cur_match_len >= 128)
453042 {
453043 tdefl_record_match(d, cur_match_len, cur_match_dist);
453044 d->m_saved_match_len = 0;
453045 len_to_move = cur_match_len;
453046 }
453047 else
453048 {
453049 d->m_saved_lit = d->m_dict[cur_pos];
453050 d->m_saved_match_dist = cur_match_dist;
453051 d->m_saved_match_len = cur_match_len;
453052 }
453053 }
453054 else
453055 {
453056 tdefl_record_match(d, d->m_saved_match_len, d->m_saved_match_dist);
453057 len_to_move = d->m_saved_match_len - 1;
453058 d->m_saved_match_len = 0;
453059 }
453060 }
453061 else if (!cur_match_dist)
453062 tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]);
453063 else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
453064 {
453065 tdefl_record_match(d, cur_match_len, cur_match_dist);
453066 len_to_move = cur_match_len;
453067 }
453068 else
453069 {
453070 d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)];
453071 d->m_saved_match_dist = cur_match_dist;
453072 d->m_saved_match_len = cur_match_len;
453073 }
453074 /* Move the lookahead forward by len_to_move bytes. */
453075 d->m_lookahead_pos += len_to_move;
453076 MZ_ASSERT(d->m_lookahead_size >= len_to_move);
453077 d->m_lookahead_size -= len_to_move;
453078 d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, (mz_uint)TDEFL_LZ_DICT_SIZE);
453079 /* Check if it's time to flush the current LZ codes to the internal output buffer. */
453080 if ((d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) ||
453081 ((d->m_total_lz_bytes > 31 * 1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))))
453082 {
453083 int n;
453084 d->m_pSrc = pSrc;
453085 d->m_src_buf_left = src_buf_left;
453086 if ((n = tdefl_flush_block(d, 0)) != 0)
453087 return (n < 0) ? MZ_FALSE : MZ_TRUE;
453088 }
453089 }
453090
453091 d->m_pSrc = pSrc;
453092 d->m_src_buf_left = src_buf_left;
453093 return MZ_TRUE;
453094}

◆ tdefl_flush_output_buffer()

tdefl_status duckdb_miniz::tdefl_flush_output_buffer ( tdefl_compressor * d)
static
453097{
453098 if (d->m_pIn_buf_size)
453099 {
453100 *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
453101 }
453102
453103 if (d->m_pOut_buf_size)
453104 {
453105 size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining);
453106 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n);
453107 d->m_output_flush_ofs += (mz_uint)n;
453108 d->m_output_flush_remaining -= (mz_uint)n;
453109 d->m_out_buf_ofs += n;
453110
453111 *d->m_pOut_buf_size = d->m_out_buf_ofs;
453112 }
453113
453114 return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY;
453115}

◆ tdefl_output_buffer_putter()

mz_bool duckdb_miniz::tdefl_output_buffer_putter ( const void * pBuf,
int len,
void * pUser )
static
453259{
453261 size_t new_size = p->m_size + len;
453262 if (new_size > p->m_capacity)
453263 {
453264 size_t new_capacity = p->m_capacity;
453265 mz_uint8 *pNew_buf;
453266 if (!p->m_expandable)
453267 return MZ_FALSE;
453268 do
453269 {
453270 new_capacity = MZ_MAX(128U, new_capacity << 1U);
453271 } while (new_size > new_capacity);
453272 pNew_buf = (mz_uint8 *)MZ_REALLOC(p->m_pBuf, new_capacity);
453273 if (!pNew_buf)
453274 return MZ_FALSE;
453275 p->m_pBuf = pNew_buf;
453276 p->m_capacity = new_capacity;
453277 }
453278 memcpy((mz_uint8 *)p->m_pBuf + p->m_size, pBuf, len);
453279 p->m_size = new_size;
453280 return MZ_TRUE;
453281}

◆ mz_zip_array_range_check()

MZ_FORCEINLINE mz_uint duckdb_miniz::mz_zip_array_range_check ( const mz_zip_array * pArray,
mz_uint index )
static
454452{
454453 MZ_ASSERT(index < pArray->m_size);
454454 return index;
454455}

◆ mz_zip_array_init()

MZ_FORCEINLINE void duckdb_miniz::mz_zip_array_init ( mz_zip_array * pArray,
mz_uint32 element_size )
static
454462{
454463 memset(pArray, 0, sizeof(mz_zip_array));
454464 pArray->m_element_size = element_size;
454465}

◆ mz_zip_array_clear()

MZ_FORCEINLINE void duckdb_miniz::mz_zip_array_clear ( mz_zip_archive * pZip,
mz_zip_array * pArray )
static
454468{
454469 pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p);
454470 memset(pArray, 0, sizeof(mz_zip_array));
454471}

◆ mz_zip_array_ensure_capacity()

mz_bool duckdb_miniz::mz_zip_array_ensure_capacity ( mz_zip_archive * pZip,
mz_zip_array * pArray,
size_t min_new_capacity,
mz_uint growing )
static
454474{
454475 void *pNew_p;
454476 size_t new_capacity = min_new_capacity;
454477 MZ_ASSERT(pArray->m_element_size);
454478 if (pArray->m_capacity >= min_new_capacity)
454479 return MZ_TRUE;
454480 if (growing)
454481 {
454482 new_capacity = MZ_MAX(1, pArray->m_capacity);
454483 while (new_capacity < min_new_capacity)
454484 new_capacity *= 2;
454485 }
454486 if (NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->m_p, pArray->m_element_size, new_capacity)))
454487 return MZ_FALSE;
454488 pArray->m_p = pNew_p;
454489 pArray->m_capacity = new_capacity;
454490 return MZ_TRUE;
454491}

◆ mz_zip_array_reserve()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_array_reserve ( mz_zip_archive * pZip,
mz_zip_array * pArray,
size_t new_capacity,
mz_uint growing )
static
454494{
454495 if (new_capacity > pArray->m_capacity)
454496 {
454497 if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing))
454498 return MZ_FALSE;
454499 }
454500 return MZ_TRUE;
454501}

◆ mz_zip_array_resize()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_array_resize ( mz_zip_archive * pZip,
mz_zip_array * pArray,
size_t new_size,
mz_uint growing )
static
454504{
454505 if (new_size > pArray->m_capacity)
454506 {
454507 if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing))
454508 return MZ_FALSE;
454509 }
454510 pArray->m_size = new_size;
454511 return MZ_TRUE;
454512}

◆ mz_zip_array_ensure_room()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_array_ensure_room ( mz_zip_archive * pZip,
mz_zip_array * pArray,
size_t n )
static
454515{
454516 return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE);
454517}

◆ mz_zip_array_push_back()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_array_push_back ( mz_zip_archive * pZip,
mz_zip_array * pArray,
const void * pElements,
size_t n )
static
454520{
454521 size_t orig_size = pArray->m_size;
454522 if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE))
454523 return MZ_FALSE;
454524 memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size);
454525 return MZ_TRUE;
454526}

◆ mz_zip_set_error()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_set_error ( mz_zip_archive * pZip,
mz_zip_error err_num )
static
454595{
454596 if (pZip)
454597 pZip->m_last_error = err_num;
454598 return MZ_FALSE;
454599}

◆ mz_zip_reader_init_internal()

mz_bool duckdb_miniz::mz_zip_reader_init_internal ( mz_zip_archive * pZip,
mz_uint flags )
static
454602{
454603 (void)flags;
454604 if ((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
454605 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
454606
454607 if (!pZip->m_pAlloc)
454608 pZip->m_pAlloc = miniz_def_alloc_func;
454609 if (!pZip->m_pFree)
454610 pZip->m_pFree = miniz_def_free_func;
454611 if (!pZip->m_pRealloc)
454612 pZip->m_pRealloc = miniz_def_realloc_func;
454613
454614 pZip->m_archive_size = 0;
454615 pZip->m_central_directory_file_ofs = 0;
454616 pZip->m_total_files = 0;
454617 pZip->m_last_error = MZ_ZIP_NO_ERROR;
454618
454619 if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state))))
454620 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
454621
454622 memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state));
454623 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8));
454624 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32));
454625 MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32));
454626 pZip->m_pState->m_init_flags = flags;
454627 pZip->m_pState->m_zip64 = MZ_FALSE;
454628 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_FALSE;
454629
454630 pZip->m_zip_mode = MZ_ZIP_MODE_READING;
454631
454632 return MZ_TRUE;
454633}

◆ mz_zip_reader_filename_less()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_reader_filename_less ( const mz_zip_array * pCentral_dir_array,
const mz_zip_array * pCentral_dir_offsets,
mz_uint l_index,
mz_uint r_index )
static
454636{
454637 const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
454638 const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index));
454639 mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS), r_len = MZ_READ_LE16(pR + MZ_ZIP_CDH_FILENAME_LEN_OFS);
454640 mz_uint8 l = 0, r = 0;
454641 pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
454642 pR += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
454643 pE = pL + MZ_MIN(l_len, r_len);
454644 while (pL < pE)
454645 {
454646 if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR)))
454647 break;
454648 pL++;
454649 pR++;
454650 }
454651 return (pL == pE) ? (l_len < r_len) : (l < r);
454652}

◆ mz_zip_reader_sort_central_dir_offsets_by_filename()

void duckdb_miniz::mz_zip_reader_sort_central_dir_offsets_by_filename ( mz_zip_archive * pZip)
static
454665{
454666 mz_zip_internal_state *pState = pZip->m_pState;
454667 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
454668 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
454669 mz_uint32 *pIndices;
454670 mz_uint32 start, end;
454671 const mz_uint32 size = pZip->m_total_files;
454672
454673 if (size <= 1U)
454674 return;
454675
454676 pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
454677
454678 start = (size - 2U) >> 1U;
454679 for (;;)
454680 {
454681 mz_uint64 child, root = start;
454682 for (;;)
454683 {
454684 if ((child = (root << 1U) + 1U) >= size)
454685 break;
454686 child += (((child + 1U) < size) && (mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U])));
454687 if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child]))
454688 break;
454689 MZ_SWAP_UINT32(pIndices[root], pIndices[child]);
454690 root = child;
454691 }
454692 if (!start)
454693 break;
454694 start--;
454695 }
454696
454697 end = size - 1;
454698 while (end > 0)
454699 {
454700 mz_uint64 child, root = 0;
454701 MZ_SWAP_UINT32(pIndices[end], pIndices[0]);
454702 for (;;)
454703 {
454704 if ((child = (root << 1U) + 1U) >= end)
454705 break;
454706 child += (((child + 1U) < end) && mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U]));
454707 if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child]))
454708 break;
454709 MZ_SWAP_UINT32(pIndices[root], pIndices[child]);
454710 root = child;
454711 }
454712 end--;
454713 }
454714}

◆ mz_zip_reader_locate_header_sig()

mz_bool duckdb_miniz::mz_zip_reader_locate_header_sig ( mz_zip_archive * pZip,
mz_uint32 record_sig,
mz_uint32 record_size,
mz_int64 * pOfs )
static
454717{
454718 mz_int64 cur_file_ofs;
454719 mz_uint32 buf_u32[4096 / sizeof(mz_uint32)];
454720 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
454721
454722 /* Basic sanity checks - reject files which are too small */
454723 if (pZip->m_archive_size < record_size)
454724 return MZ_FALSE;
454725
454726 /* Find the record by scanning the file from the end towards the beginning. */
454727 cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)sizeof(buf_u32), 0);
454728 for (;;)
454729 {
454730 int i, n = (int)MZ_MIN(sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs);
454731
454732 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n)
454733 return MZ_FALSE;
454734
454735 for (i = n - 4; i >= 0; --i)
454736 {
454737 mz_uint s = MZ_READ_LE32(pBuf + i);
454738 if (s == record_sig)
454739 {
454740 if ((pZip->m_archive_size - (cur_file_ofs + i)) >= record_size)
454741 break;
454742 }
454743 }
454744
454745 if (i >= 0)
454746 {
454747 cur_file_ofs += i;
454748 break;
454749 }
454750
454751 /* Give up if we've searched the entire file, or we've gone back "too far" (~64kb) */
454752 if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (MZ_UINT16_MAX + record_size)))
454753 return MZ_FALSE;
454754
454755 cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0);
454756 }
454757
454758 *pOfs = cur_file_ofs;
454759 return MZ_TRUE;
454760}

◆ mz_zip_reader_read_central_dir()

mz_bool duckdb_miniz::mz_zip_reader_read_central_dir ( mz_zip_archive * pZip,
mz_uint flags )
static
454763{
454764 mz_uint cdir_size = 0, cdir_entries_on_this_disk = 0, num_this_disk = 0, cdir_disk_index = 0;
454765 mz_uint64 cdir_ofs = 0;
454766 mz_int64 cur_file_ofs = 0;
454767 const mz_uint8 *p;
454768
454769 mz_uint32 buf_u32[4096 / sizeof(mz_uint32)];
454770 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
454771 mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0);
454772 mz_uint32 zip64_end_of_central_dir_locator_u32[(MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
454773 mz_uint8 *pZip64_locator = (mz_uint8 *)zip64_end_of_central_dir_locator_u32;
454774
454775 mz_uint32 zip64_end_of_central_dir_header_u32[(MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)];
454776 mz_uint8 *pZip64_end_of_central_dir = (mz_uint8 *)zip64_end_of_central_dir_header_u32;
454777
454778 mz_uint64 zip64_end_of_central_dir_ofs = 0;
454779
454780 /* Basic sanity checks - reject files which are too small, and check the first 4 bytes of the file to make sure a local header is there. */
454781 if (pZip->m_archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
454782 return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
454783
454784 if (!mz_zip_reader_locate_header_sig(pZip, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE, &cur_file_ofs))
454785 return mz_zip_set_error(pZip, MZ_ZIP_FAILED_FINDING_CENTRAL_DIR);
454786
454787 /* Read and verify the end of central directory record. */
454788 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
454789 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
454790
454791 if (MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_SIG_OFS) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG)
454792 return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
454793
454794 if (cur_file_ofs >= (MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE + MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE))
454795 {
454796 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs - MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE, pZip64_locator, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE)
454797 {
454798 if (MZ_READ_LE32(pZip64_locator + MZ_ZIP64_ECDL_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG)
454799 {
454800 zip64_end_of_central_dir_ofs = MZ_READ_LE64(pZip64_locator + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS);
454801 if (zip64_end_of_central_dir_ofs > (pZip->m_archive_size - MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE))
454802 return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
454803
454804 if (pZip->m_pRead(pZip->m_pIO_opaque, zip64_end_of_central_dir_ofs, pZip64_end_of_central_dir, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)
454805 {
454806 if (MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG)
454807 {
454808 pZip->m_pState->m_zip64 = MZ_TRUE;
454809 }
454810 }
454811 }
454812 }
454813 }
454814
454815 pZip->m_total_files = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS);
454816 cdir_entries_on_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS);
454817 num_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS);
454818 cdir_disk_index = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS);
454819 cdir_size = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_SIZE_OFS);
454820 cdir_ofs = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_OFS_OFS);
454821
454822 if (pZip->m_pState->m_zip64)
454823 {
454824 mz_uint32 zip64_total_num_of_disks = MZ_READ_LE32(pZip64_locator + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS);
454825 mz_uint64 zip64_cdir_total_entries = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS);
454826 mz_uint64 zip64_cdir_total_entries_on_this_disk = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS);
454827 mz_uint64 zip64_size_of_end_of_central_dir_record = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS);
454828 mz_uint64 zip64_size_of_central_directory = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_SIZE_OFS);
454829
454830 if (zip64_size_of_end_of_central_dir_record < (MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - 12))
454831 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454832
454833 if (zip64_total_num_of_disks != 1U)
454834 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);
454835
454836 /* Check for miniz's practical limits */
454837 if (zip64_cdir_total_entries > MZ_UINT32_MAX)
454838 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
454839
454840 pZip->m_total_files = (mz_uint32)zip64_cdir_total_entries;
454841
454842 if (zip64_cdir_total_entries_on_this_disk > MZ_UINT32_MAX)
454843 return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
454844
454845 cdir_entries_on_this_disk = (mz_uint32)zip64_cdir_total_entries_on_this_disk;
454846
454847 /* Check for miniz's current practical limits (sorry, this should be enough for millions of files) */
454848 if (zip64_size_of_central_directory > MZ_UINT32_MAX)
454849 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
454850
454851 cdir_size = (mz_uint32)zip64_size_of_central_directory;
454852
454853 num_this_disk = MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS);
454854
454855 cdir_disk_index = MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS);
454856
454857 cdir_ofs = MZ_READ_LE64(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_CDIR_OFS_OFS);
454858 }
454859
454860 if (pZip->m_total_files != cdir_entries_on_this_disk)
454861 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);
454862
454863 if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
454864 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);
454865
454866 if (cdir_size < pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)
454867 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454868
454869 if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
454870 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454871
454872 pZip->m_central_directory_file_ofs = cdir_ofs;
454873
454874 if (pZip->m_total_files)
454875 {
454876 mz_uint i, n;
454877 /* Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and possibly another to hold the sorted indices. */
454878 if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) ||
454879 (!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)))
454880 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
454881
454882 if (sort_central_dir)
454883 {
454884 if (!mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE))
454885 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
454886 }
454887
454888 if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size)
454889 return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
454890
454891 /* Now create an index into the central directory file records, do some basic sanity checking on each record */
454892 p = (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p;
454893 for (n = cdir_size, i = 0; i < pZip->m_total_files; ++i)
454894 {
454895 mz_uint total_header_size, disk_index, bit_flags, filename_size, ext_data_size;
454896 mz_uint64 comp_size, decomp_size, local_header_ofs;
454897
454898 if ((n < MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) || (MZ_READ_LE32(p) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG))
454899 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454900
454901 MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, i) = (mz_uint32)(p - (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p);
454902
454903 if (sort_central_dir)
454904 MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_sorted_central_dir_offsets, mz_uint32, i) = i;
454905
454906 comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
454907 decomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
454908 local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS);
454909 filename_size = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
454910 ext_data_size = MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS);
454911
454912 if ((!pZip->m_pState->m_zip64_has_extended_info_fields) &&
454913 (ext_data_size) &&
454914 (MZ_MAX(MZ_MAX(comp_size, decomp_size), local_header_ofs) == MZ_UINT32_MAX))
454915 {
454916 /* Attempt to find zip64 extended information field in the entry's extra data */
454917 mz_uint32 extra_size_remaining = ext_data_size;
454918
454919 if (extra_size_remaining)
454920 {
454921 const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size;
454922
454923 do
454924 {
454925 mz_uint32 field_id;
454926 mz_uint32 field_data_size;
454927
454928 if (extra_size_remaining < (sizeof(mz_uint16) * 2))
454929 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454930
454931 field_id = MZ_READ_LE16(pExtra_data);
454932 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
454933
454934 if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
454935 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454936
454937 if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
454938 {
454939 /* Ok, the archive didn't have any zip64 headers but it uses a zip64 extended information field so mark it as zip64 anyway (this can occur with infozip's zip util when it reads compresses files from stdin). */
454940 pZip->m_pState->m_zip64 = MZ_TRUE;
454941 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_TRUE;
454942 break;
454943 }
454944
454945 pExtra_data += sizeof(mz_uint16) * 2 + field_data_size;
454946 extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size;
454947 } while (extra_size_remaining);
454948 }
454949 }
454950
454951 /* I've seen archives that aren't marked as zip64 that uses zip64 ext data, argh */
454952 if ((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX))
454953 {
454954 if (((!MZ_READ_LE32(p + MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size))
454955 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454956 }
454957
454958 disk_index = MZ_READ_LE16(p + MZ_ZIP_CDH_DISK_START_OFS);
454959 if ((disk_index == MZ_UINT16_MAX) || ((disk_index != num_this_disk) && (disk_index != 1)))
454960 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);
454961
454962 if (comp_size != MZ_UINT32_MAX)
454963 {
454964 if (((mz_uint64)MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS) + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + comp_size) > pZip->m_archive_size)
454965 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454966 }
454967
454968 bit_flags = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
454969 if (bit_flags & MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED)
454970 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_ENCRYPTION);
454971
454972 if ((total_header_size = MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS)) > n)
454973 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
454974
454975 n -= total_header_size;
454976 p += total_header_size;
454977 }
454978 }
454979
454980 if (sort_central_dir)
454981 mz_zip_reader_sort_central_dir_offsets_by_filename(pZip);
454982
454983 return MZ_TRUE;
454984}

◆ mz_zip_reader_end_internal()

mz_bool duckdb_miniz::mz_zip_reader_end_internal ( mz_zip_archive * pZip,
mz_bool set_last_error )
static
454993{
454994 mz_bool status = MZ_TRUE;
454995
454996 if (!pZip)
454997 return MZ_FALSE;
454998
454999 if ((!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
455000 {
455001 if (set_last_error)
455002 pZip->m_last_error = MZ_ZIP_INVALID_PARAMETER;
455003
455004 return MZ_FALSE;
455005 }
455006
455007 if (pZip->m_pState)
455008 {
455009 mz_zip_internal_state *pState = pZip->m_pState;
455010 pZip->m_pState = NULL;
455011
455012 mz_zip_array_clear(pZip, &pState->m_central_dir);
455013 mz_zip_array_clear(pZip, &pState->m_central_dir_offsets);
455014 mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets);
455015
455016#ifndef MINIZ_NO_STDIO
455017 if (pState->m_pFile)
455018 {
455019 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
455020 {
455021 if (MZ_FCLOSE(pState->m_pFile) == EOF)
455022 {
455023 if (set_last_error)
455024 pZip->m_last_error = MZ_ZIP_FILE_CLOSE_FAILED;
455025 status = MZ_FALSE;
455026 }
455027 }
455028 pState->m_pFile = NULL;
455029 }
455030#endif /* #ifndef MINIZ_NO_STDIO */
455031
455032 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
455033 }
455034 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
455035
455036 return status;
455037}

◆ mz_zip_mem_read_func()

size_t duckdb_miniz::mz_zip_mem_read_func ( void * pOpaque,
mz_uint64 file_ofs,
void * pBuf,
size_t n )
static
455064{
455065 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
455066 size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n);
455067 memcpy(pBuf, (const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s);
455068 return s;
455069}

◆ mz_zip_get_cdh()

MZ_FORCEINLINE const mz_uint8 * duckdb_miniz::mz_zip_get_cdh ( mz_zip_archive * pZip,
mz_uint file_index )
static
455221{
455222 if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files))
455223 return NULL;
455224 return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index));
455225}

◆ mz_zip_file_stat_internal()

mz_bool duckdb_miniz::mz_zip_file_stat_internal ( mz_zip_archive * pZip,
mz_uint file_index,
const mz_uint8 * pCentral_dir_header,
mz_zip_archive_file_stat * pStat,
mz_bool * pFound_zip64_extra_data )
static
455310{
455311 mz_uint n;
455312 const mz_uint8 *p = pCentral_dir_header;
455313
455314 if (pFound_zip64_extra_data)
455315 *pFound_zip64_extra_data = MZ_FALSE;
455316
455317 if ((!p) || (!pStat))
455318 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
455319
455320 /* Extract fields from the central directory record. */
455321 pStat->m_file_index = file_index;
455322 pStat->m_central_dir_ofs = MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index);
455323 pStat->m_version_made_by = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS);
455324 pStat->m_version_needed = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_NEEDED_OFS);
455325 pStat->m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS);
455326 pStat->m_method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS);
455327#ifndef MINIZ_NO_TIME
455328 pStat->m_time = mz_zip_dos_to_time_t(MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_TIME_OFS), MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_DATE_OFS));
455329#endif
455330 pStat->m_crc32 = MZ_READ_LE32(p + MZ_ZIP_CDH_CRC32_OFS);
455331 pStat->m_comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
455332 pStat->m_uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
455333 pStat->m_internal_attr = MZ_READ_LE16(p + MZ_ZIP_CDH_INTERNAL_ATTR_OFS);
455334 pStat->m_external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS);
455335 pStat->m_local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS);
455336
455337 /* Copy as much of the filename and comment as possible. */
455338 n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
455339 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1);
455340 memcpy(pStat->m_filename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n);
455341 pStat->m_filename[n] = '\0';
455342
455343 n = MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS);
455344 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1);
455345 pStat->m_comment_size = n;
455346 memcpy(pStat->m_comment, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS), n);
455347 pStat->m_comment[n] = '\0';
455348
455349 /* Set some flags for convienance */
455350 pStat->m_is_directory = mz_zip_reader_is_file_a_directory(pZip, file_index);
455351 pStat->m_is_encrypted = mz_zip_reader_is_file_encrypted(pZip, file_index);
455352 pStat->m_is_supported = mz_zip_reader_is_file_supported(pZip, file_index);
455353
455354 /* See if we need to read any zip64 extended information fields. */
455355 /* Confusingly, these zip64 fields can be present even on non-zip64 archives (Debian zip on a huge files from stdin piped to stdout creates them). */
455356 if (MZ_MAX(MZ_MAX(pStat->m_comp_size, pStat->m_uncomp_size), pStat->m_local_header_ofs) == MZ_UINT32_MAX)
455357 {
455358 /* Attempt to find zip64 extended information field in the entry's extra data */
455359 mz_uint32 extra_size_remaining = MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS);
455360
455361 if (extra_size_remaining)
455362 {
455363 const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS);
455364
455365 do
455366 {
455367 mz_uint32 field_id;
455368 mz_uint32 field_data_size;
455369
455370 if (extra_size_remaining < (sizeof(mz_uint16) * 2))
455371 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455372
455373 field_id = MZ_READ_LE16(pExtra_data);
455374 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
455375
455376 if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
455377 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455378
455379 if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
455380 {
455381 const mz_uint8 *pField_data = pExtra_data + sizeof(mz_uint16) * 2;
455382 mz_uint32 field_data_remaining = field_data_size;
455383
455384 if (pFound_zip64_extra_data)
455385 *pFound_zip64_extra_data = MZ_TRUE;
455386
455387 if (pStat->m_uncomp_size == MZ_UINT32_MAX)
455388 {
455389 if (field_data_remaining < sizeof(mz_uint64))
455390 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455391
455392 pStat->m_uncomp_size = MZ_READ_LE64(pField_data);
455393 pField_data += sizeof(mz_uint64);
455394 field_data_remaining -= sizeof(mz_uint64);
455395 }
455396
455397 if (pStat->m_comp_size == MZ_UINT32_MAX)
455398 {
455399 if (field_data_remaining < sizeof(mz_uint64))
455400 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455401
455402 pStat->m_comp_size = MZ_READ_LE64(pField_data);
455403 pField_data += sizeof(mz_uint64);
455404 field_data_remaining -= sizeof(mz_uint64);
455405 }
455406
455407 if (pStat->m_local_header_ofs == MZ_UINT32_MAX)
455408 {
455409 if (field_data_remaining < sizeof(mz_uint64))
455410 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
455411
455412 pStat->m_local_header_ofs = MZ_READ_LE64(pField_data);
455413 pField_data += sizeof(mz_uint64);
455414 field_data_remaining -= sizeof(mz_uint64);
455415 }
455416
455417 break;
455418 }
455419
455420 pExtra_data += sizeof(mz_uint16) * 2 + field_data_size;
455421 extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size;
455422 } while (extra_size_remaining);
455423 }
455424 }
455425
455426 return MZ_TRUE;
455427}

◆ mz_zip_string_equal()

MZ_FORCEINLINE mz_bool duckdb_miniz::mz_zip_string_equal ( const char * pA,
const char * pB,
mz_uint len,
mz_uint flags )
static
455430{
455431 mz_uint i;
455432 if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
455433 return 0 == memcmp(pA, pB, len);
455434 for (i = 0; i < len; ++i)
455435 if (MZ_TOLOWER(pA[i]) != MZ_TOLOWER(pB[i]))
455436 return MZ_FALSE;
455437 return MZ_TRUE;
455438}

◆ mz_zip_filename_compare()

MZ_FORCEINLINE int duckdb_miniz::mz_zip_filename_compare ( const mz_zip_array * pCentral_dir_array,
const mz_zip_array * pCentral_dir_offsets,
mz_uint l_index,
const char * pR,
mz_uint r_len )
static
455441{
455442 const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE;
455443 mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS);
455444 mz_uint8 l = 0, r = 0;
455445 pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE;
455446 pE = pL + MZ_MIN(l_len, r_len);
455447 while (pL < pE)
455448 {
455449 if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR)))
455450 break;
455451 pL++;
455452 pR++;
455453 }
455454 return (pL == pE) ? (int)(l_len - r_len) : (l - r);
455455}

◆ mz_zip_locate_file_binary_search()

mz_bool duckdb_miniz::mz_zip_locate_file_binary_search ( mz_zip_archive * pZip,
const char * pFilename,
mz_uint32 * pIndex )
static
455458{
455459 mz_zip_internal_state *pState = pZip->m_pState;
455460 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
455461 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
455462 mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
455463 const uint32_t size = pZip->m_total_files;
455464 const mz_uint filename_len = (mz_uint)strlen(pFilename);
455465
455466 if (pIndex)
455467 *pIndex = 0;
455468
455469 if (size)
455470 {
455471 /* yes I could use uint32_t's, but then we would have to add some special case checks in the loop, argh, and */
455472 /* honestly the major expense here on 32-bit CPU's will still be the filename compare */
455473 mz_int64 l = 0, h = (mz_int64)size - 1;
455474
455475 while (l <= h)
455476 {
455477 mz_int64 m = l + ((h - l) >> 1);
455478 uint32_t file_index = pIndices[(uint32_t)m];
455479
455480 int comp = mz_zip_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len);
455481 if (!comp)
455482 {
455483 if (pIndex)
455484 *pIndex = file_index;
455485 return MZ_TRUE;
455486 }
455487 else if (comp < 0)
455488 l = m + 1;
455489 else
455490 h = m - 1;
455491 }
455492 }
455493
455494 return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
455495}

◆ mz_zip_compute_crc32_callback()

size_t duckdb_miniz::mz_zip_compute_crc32_callback ( void * pOpaque,
mz_uint64 file_ofs,
const void * pBuf,
size_t n )
static
456366{
456367 mz_uint32 *p = (mz_uint32 *)pOpaque;
456368 (void)file_ofs;
456369 *p = (mz_uint32)mz_crc32(*p, (const mz_uint8 *)pBuf, n);
456370 return n;
456371}

◆ mz_write_le16()

MZ_FORCEINLINE void duckdb_miniz::mz_write_le16 ( mz_uint8 * p,
mz_uint16 v )
static
456721{
456722 p[0] = (mz_uint8)v;
456723 p[1] = (mz_uint8)(v >> 8);
456724}
uint32_t v

◆ mz_write_le32()

MZ_FORCEINLINE void duckdb_miniz::mz_write_le32 ( mz_uint8 * p,
mz_uint32 v )
static
456726{
456727 p[0] = (mz_uint8)v;
456728 p[1] = (mz_uint8)(v >> 8);
456729 p[2] = (mz_uint8)(v >> 16);
456730 p[3] = (mz_uint8)(v >> 24);
456731}

◆ mz_write_le64()

MZ_FORCEINLINE void duckdb_miniz::mz_write_le64 ( mz_uint8 * p,
mz_uint64 v )
static
456733{
456734 mz_write_le32(p, (mz_uint32)v);
456735 mz_write_le32(p + sizeof(mz_uint32), (mz_uint32)(v >> 32));
456736}

◆ mz_zip_heap_write_func()

size_t duckdb_miniz::mz_zip_heap_write_func ( void * pOpaque,
mz_uint64 file_ofs,
const void * pBuf,
size_t n )
static
456743{
456744 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
456745 mz_zip_internal_state *pState = pZip->m_pState;
456746 mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
456747
456748 if (!n)
456749 return 0;
456750
456751 /* An allocation this big is likely to just fail on 32-bit systems, so don't even go there. */
456752 if ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))
456753 {
456754 mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE);
456755 return 0;
456756 }
456757
456758 if (new_size > pState->m_mem_capacity)
456759 {
456760 void *pNew_block;
456761 size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity);
456762
456763 while (new_capacity < new_size)
456764 new_capacity *= 2;
456765
456766 if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity)))
456767 {
456768 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
456769 return 0;
456770 }
456771
456772 pState->m_pMem = pNew_block;
456773 pState->m_mem_capacity = new_capacity;
456774 }
456775 memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n);
456776 pState->m_mem_size = (size_t)new_size;
456777 return n;
456778}

◆ mz_zip_writer_end_internal()

mz_bool duckdb_miniz::mz_zip_writer_end_internal ( mz_zip_archive * pZip,
mz_bool set_last_error )
static
456781{
456782 mz_zip_internal_state *pState;
456783 mz_bool status = MZ_TRUE;
456784
456785 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || ((pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) && (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)))
456786 {
456787 if (set_last_error)
456788 mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
456789 return MZ_FALSE;
456790 }
456791
456792 pState = pZip->m_pState;
456793 pZip->m_pState = NULL;
456794 mz_zip_array_clear(pZip, &pState->m_central_dir);
456795 mz_zip_array_clear(pZip, &pState->m_central_dir_offsets);
456796 mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets);
456797
456798#ifndef MINIZ_NO_STDIO
456799 if (pState->m_pFile)
456800 {
456801 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
456802 {
456803 if (MZ_FCLOSE(pState->m_pFile) == EOF)
456804 {
456805 if (set_last_error)
456806 mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED);
456807 status = MZ_FALSE;
456808 }
456809 }
456810
456811 pState->m_pFile = NULL;
456812 }
456813#endif /* #ifndef MINIZ_NO_STDIO */
456814
456815 if ((pZip->m_pWrite == mz_zip_heap_write_func) && (pState->m_pMem))
456816 {
456817 pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem);
456818 pState->m_pMem = NULL;
456819 }
456820
456821 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
456822 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
456823 return status;
456824}

◆ mz_zip_writer_add_put_buf_callback()

mz_bool duckdb_miniz::mz_zip_writer_add_put_buf_callback ( const void * pBuf,
int len,
void * pUser )
static
457109{
457111 if ((int)pState->m_pZip->m_pWrite(pState->m_pZip->m_pIO_opaque, pState->m_cur_archive_file_ofs, pBuf, len) != len)
457112 return MZ_FALSE;
457113
457114 pState->m_cur_archive_file_ofs += len;
457115 pState->m_comp_size += len;
457116 return MZ_TRUE;
457117}

◆ mz_zip_writer_create_zip64_extra_data()

mz_uint32 duckdb_miniz::mz_zip_writer_create_zip64_extra_data ( mz_uint8 * pBuf,
mz_uint64 * pUncomp_size,
mz_uint64 * pComp_size,
mz_uint64 * pLocal_header_ofs )
static
457122{
457123 mz_uint8 *pDst = pBuf;
457124 mz_uint32 field_size = 0;
457125
457126 MZ_WRITE_LE16(pDst + 0, MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID);
457127 MZ_WRITE_LE16(pDst + 2, 0);
457128 pDst += sizeof(mz_uint16) * 2;
457129
457130 if (pUncomp_size)
457131 {
457132 MZ_WRITE_LE64(pDst, *pUncomp_size);
457133 pDst += sizeof(mz_uint64);
457134 field_size += sizeof(mz_uint64);
457135 }
457136
457137 if (pComp_size)
457138 {
457139 MZ_WRITE_LE64(pDst, *pComp_size);
457140 pDst += sizeof(mz_uint64);
457141 field_size += sizeof(mz_uint64);
457142 }
457143
457144 if (pLocal_header_ofs)
457145 {
457146 MZ_WRITE_LE64(pDst, *pLocal_header_ofs);
457147 pDst += sizeof(mz_uint64);
457148 field_size += sizeof(mz_uint64);
457149 }
457150
457151 MZ_WRITE_LE16(pBuf + 2, field_size);
457152
457153 return (mz_uint32)(pDst - pBuf);
457154}

◆ mz_zip_writer_create_local_dir_header()

mz_bool duckdb_miniz::mz_zip_writer_create_local_dir_header ( mz_zip_archive * pZip,
mz_uint8 * pDst,
mz_uint16 filename_size,
mz_uint16 extra_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date )
static
457157{
457158 (void)pZip;
457159 memset(pDst, 0, MZ_ZIP_LOCAL_DIR_HEADER_SIZE);
457160 MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_SIG_OFS, MZ_ZIP_LOCAL_DIR_HEADER_SIG);
457161 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_VERSION_NEEDED_OFS, method ? 20 : 0);
457162 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_BIT_FLAG_OFS, bit_flags);
457163 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_METHOD_OFS, method);
457164 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_TIME_OFS, dos_time);
457165 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_DATE_OFS, dos_date);
457166 MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_CRC32_OFS, uncomp_crc32);
457167 MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS, MZ_MIN(comp_size, MZ_UINT32_MAX));
457168 MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS, MZ_MIN(uncomp_size, MZ_UINT32_MAX));
457169 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILENAME_LEN_OFS, filename_size);
457170 MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_EXTRA_LEN_OFS, extra_size);
457171 return MZ_TRUE;
457172}

◆ mz_zip_writer_create_central_dir_header()

mz_bool duckdb_miniz::mz_zip_writer_create_central_dir_header ( mz_zip_archive * pZip,
mz_uint8 * pDst,
mz_uint16 filename_size,
mz_uint16 extra_size,
mz_uint16 comment_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date,
mz_uint64 local_header_ofs,
mz_uint32 ext_attributes )
static
457179{
457180 (void)pZip;
457181 memset(pDst, 0, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE);
457182 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_SIG_OFS, MZ_ZIP_CENTRAL_DIR_HEADER_SIG);
457183 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_NEEDED_OFS, method ? 20 : 0);
457184 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_BIT_FLAG_OFS, bit_flags);
457185 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_METHOD_OFS, method);
457186 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_TIME_OFS, dos_time);
457187 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_DATE_OFS, dos_date);
457188 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_CRC32_OFS, uncomp_crc32);
457189 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, MZ_MIN(comp_size, MZ_UINT32_MAX));
457190 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, MZ_MIN(uncomp_size, MZ_UINT32_MAX));
457191 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILENAME_LEN_OFS, filename_size);
457192 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_EXTRA_LEN_OFS, extra_size);
457193 MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_COMMENT_LEN_OFS, comment_size);
457194 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, ext_attributes);
457195 MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_LOCAL_HEADER_OFS, MZ_MIN(local_header_ofs, MZ_UINT32_MAX));
457196 return MZ_TRUE;
457197}

◆ mz_zip_writer_add_to_central_dir()

mz_bool duckdb_miniz::mz_zip_writer_add_to_central_dir ( mz_zip_archive * pZip,
const char * pFilename,
mz_uint16 filename_size,
const void * pExtra,
mz_uint16 extra_size,
const void * pComment,
mz_uint16 comment_size,
mz_uint64 uncomp_size,
mz_uint64 comp_size,
mz_uint32 uncomp_crc32,
mz_uint16 method,
mz_uint16 bit_flags,
mz_uint16 dos_time,
mz_uint16 dos_date,
mz_uint64 local_header_ofs,
mz_uint32 ext_attributes,
const char * user_extra_data,
mz_uint user_extra_data_len )
static
457205{
457206 mz_zip_internal_state *pState = pZip->m_pState;
457207 mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size;
457208 size_t orig_central_dir_size = pState->m_central_dir.m_size;
457209 mz_uint8 central_dir_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE];
457210
457211 if (!pZip->m_pState->m_zip64)
457212 {
457213 if (local_header_ofs > 0xFFFFFFFF)
457214 return mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE);
457215 }
457216
457217 /* miniz doesn't support central dirs >= MZ_UINT32_MAX bytes yet */
457218 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)
457219 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE);
457220
457221 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))
457222 return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
457223
457224 if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) ||
457225 (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pFilename, filename_size)) ||
457226 (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pExtra, extra_size)) ||
457227 (!mz_zip_array_push_back(pZip, &pState->m_central_dir, user_extra_data, user_extra_data_len)) ||
457228 (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pComment, comment_size)) ||
457229 (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &central_dir_ofs, 1)))
457230 {
457231 /* Try to resize the central directory array back into its original state. */
457232 mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE);
457233 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457234 }
457235
457236 return MZ_TRUE;
457237}

◆ mz_zip_writer_validate_archive_name()

mz_bool duckdb_miniz::mz_zip_writer_validate_archive_name ( const char * pArchive_name)
static
457240{
457241 /* Basic ZIP archive filename validity checks: Valid filenames cannot start with a forward slash, cannot contain a drive letter, and cannot use DOS-style backward slashes. */
457242 if (*pArchive_name == '/')
457243 return MZ_FALSE;
457244
457245 while (*pArchive_name)
457246 {
457247 if ((*pArchive_name == '\\') || (*pArchive_name == ':'))
457248 return MZ_FALSE;
457249
457250 pArchive_name++;
457251 }
457252
457253 return MZ_TRUE;
457254}

◆ mz_zip_writer_compute_padding_needed_for_file_alignment()

mz_uint duckdb_miniz::mz_zip_writer_compute_padding_needed_for_file_alignment ( mz_zip_archive * pZip)
static
457257{
457258 mz_uint32 n;
457259 if (!pZip->m_file_offset_alignment)
457260 return 0;
457261 n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1));
457262 return (mz_uint)((pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1));
457263}

◆ mz_zip_writer_write_zeros()

mz_bool duckdb_miniz::mz_zip_writer_write_zeros ( mz_zip_archive * pZip,
mz_uint64 cur_file_ofs,
mz_uint32 n )
static
457266{
457267 char buf[4096];
457268 memset(buf, 0, MZ_MIN(sizeof(buf), n));
457269 while (n)
457270 {
457271 mz_uint32 s = MZ_MIN(sizeof(buf), n);
457272 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs, buf, s) != s)
457273 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED);
457274
457275 cur_file_ofs += s;
457276 n -= s;
457277 }
457278 return MZ_TRUE;
457279}

◆ mz_zip_writer_update_zip64_extension_block()

mz_bool duckdb_miniz::mz_zip_writer_update_zip64_extension_block ( mz_zip_array * pNew_ext,
mz_zip_archive * pZip,
const mz_uint8 * pExt,
uint32_t ext_len,
mz_uint64 * pComp_size,
mz_uint64 * pUncomp_size,
mz_uint64 * pLocal_header_ofs,
mz_uint32 * pDisk_start )
static
457907{
457908 /* + 64 should be enough for any new zip64 data */
457909 if (!mz_zip_array_reserve(pZip, pNew_ext, ext_len + 64, MZ_FALSE))
457910 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457911
457912 mz_zip_array_resize(pZip, pNew_ext, 0, MZ_FALSE);
457913
457914 if ((pUncomp_size) || (pComp_size) || (pLocal_header_ofs) || (pDisk_start))
457915 {
457916 mz_uint8 new_ext_block[64];
457917 mz_uint8 *pDst = new_ext_block;
457918 mz_write_le16(pDst, MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID);
457919 mz_write_le16(pDst + sizeof(mz_uint16), 0);
457920 pDst += sizeof(mz_uint16) * 2;
457921
457922 if (pUncomp_size)
457923 {
457924 mz_write_le64(pDst, *pUncomp_size);
457925 pDst += sizeof(mz_uint64);
457926 }
457927
457928 if (pComp_size)
457929 {
457930 mz_write_le64(pDst, *pComp_size);
457931 pDst += sizeof(mz_uint64);
457932 }
457933
457934 if (pLocal_header_ofs)
457935 {
457936 mz_write_le64(pDst, *pLocal_header_ofs);
457937 pDst += sizeof(mz_uint64);
457938 }
457939
457940 if (pDisk_start)
457941 {
457942 mz_write_le32(pDst, *pDisk_start);
457943 pDst += sizeof(mz_uint32);
457944 }
457945
457946 mz_write_le16(new_ext_block + sizeof(mz_uint16), (mz_uint16)((pDst - new_ext_block) - sizeof(mz_uint16) * 2));
457947
457948 if (!mz_zip_array_push_back(pZip, pNew_ext, new_ext_block, pDst - new_ext_block))
457949 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457950 }
457951
457952 if ((pExt) && (ext_len))
457953 {
457954 mz_uint32 extra_size_remaining = ext_len;
457955 const mz_uint8 *pExtra_data = pExt;
457956
457957 do
457958 {
457959 mz_uint32 field_id, field_data_size, field_total_size;
457960
457961 if (extra_size_remaining < (sizeof(mz_uint16) * 2))
457962 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
457963
457964 field_id = MZ_READ_LE16(pExtra_data);
457965 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
457966 field_total_size = field_data_size + sizeof(mz_uint16) * 2;
457967
457968 if (field_total_size > extra_size_remaining)
457969 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
457970
457971 if (field_id != MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID)
457972 {
457973 if (!mz_zip_array_push_back(pZip, pNew_ext, pExtra_data, field_total_size))
457974 return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
457975 }
457976
457977 pExtra_data += field_total_size;
457978 extra_size_remaining -= field_total_size;
457979 } while (extra_size_remaining);
457980 }
457981
457982 return MZ_TRUE;
457983}

Variable Documentation

◆ s_tdefl_len_sym

const mz_uint16 duckdb_miniz::s_tdefl_len_sym[256]
static
Initial value:
=
{
257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272,
273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276,
277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280,
281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282,
283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285
}

Copyright 2013-2014 RAD Game Tools and Valve Software Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

451920 {
451921 257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272,
451922 273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276,
451923 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
451924 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280,
451925 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
451926 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282,
451927 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
451928 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285
451929 };

◆ s_tdefl_len_extra

const mz_uint8 duckdb_miniz::s_tdefl_len_extra[256]
static
Initial value:
=
{
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
}
451932 {
451933 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
451934 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
451935 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
451936 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
451937 };

◆ s_tdefl_small_dist_sym

const mz_uint8 duckdb_miniz::s_tdefl_small_dist_sym[512]
static
Initial value:
=
{
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
}
451940 {
451941 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
451942 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
451943 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
451944 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
451945 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
451946 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
451947 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
451948 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
451949 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
451950 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
451951 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
451952 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
451953 };

◆ s_tdefl_small_dist_extra

const mz_uint8 duckdb_miniz::s_tdefl_small_dist_extra[512]
static
Initial value:
=
{
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7
}
451956 {
451957 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
451958 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
451959 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
451960 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
451961 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
451962 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
451963 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
451964 7, 7, 7, 7, 7, 7, 7, 7
451965 };

◆ s_tdefl_large_dist_sym

const mz_uint8 duckdb_miniz::s_tdefl_large_dist_sym[128]
static
Initial value:
=
{
0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
}
451968 {
451969 0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
451970 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
451971 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
451972 };

◆ s_tdefl_large_dist_extra

const mz_uint8 duckdb_miniz::s_tdefl_large_dist_extra[128]
static
Initial value:
=
{
0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13
}
451975 {
451976 0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
451977 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
451978 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13
451979 };

◆ s_tdefl_packed_code_size_syms_swizzle

mz_uint8 duckdb_miniz::s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }
static
452221{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };

◆ mz_bitmasks

const mz_uint duckdb_miniz::mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }
static
452332{ 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };

◆ s_tdefl_num_probes

const mz_uint duckdb_miniz::s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }
static
453311{ 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };