Compare commits

...
30 Commits
Author SHA1 Message Date
Nathan Moinvaziri f873eccdd2 Version 2.3.7. 2018-07-13 08:31:40 -07:00
Nathan Moinvaziri 9593ca4fc5 Fixed casting warning. 2018-07-12 15:06:19 -07:00
Nathan Moinvaziri 2e4a85e36f Added function to set memory buffer limit if relying on mem stream for its own buffer. 2018-07-12 12:39:02 -07:00
Nathan Moinvaziri ee614ff3ce Fixed loading of zips that have incorrect offsets for central directory - in instances where zips have just been appended on to an existing file.
Fixed reading of raw decrypted data, if you want completely raw then don't pass in a password. #252
2018-07-12 12:36:33 -07:00
Nathan Moinvaziri 6b12c36538 Clean up includes and fixed formatting. 2018-07-12 09:05:25 -07:00
Nathan Moinvaziri a4a5cf66aa Remove calling test script in ci. 2018-07-11 17:17:59 -07:00
Nathan Moinvaziri cfcbccf67e Merge branch 'dev' of https://github.com/nmoinvaz/minizip into dev 2018-07-11 16:45:16 -07:00
Nathan Moinvaziri eb80cd9fa4 Fixed bug extracting 0-byte file when stored. 2018-07-11 16:45:09 -07:00
Nathan Moinvaziri 9e2b2456dc Update README.md 2018-07-11 16:35:32 -07:00
Nathan Moinvaziri ffa830f684 Version 2.3.6. 2018-07-11 16:34:01 -07:00
Nathan Moinvaziri f65b9fecae Fixed bug verifying password header using pkcrypt. 2018-07-11 16:28:56 -07:00
Nathan Moinvaziri f76c04be40 Fixed code accidentally removed. 2018-07-11 15:51:49 -07:00
Nathan Moinvaziri ebb01ce07e Remove unused include. 2018-07-11 15:43:29 -07:00
Nathan Moinvaziri b0a005644d Cleanup, fixed formatting. 2018-07-11 15:34:45 -07:00
Nathan Moinvaziri d7814e9b8d Finialize compression stream even if nothing written due to compatibility with other zip apps. #277
Changed pkcrypt to use crc32 update function instead of doing calculation from crc32 table.
Modified mz_zip_entry_read to not return when uncompressed_size is 0 due to the fact that it is possible for 0-byte files to have packed bytes if using deflate method.
2018-07-11 14:54:14 -07:00
Nathan Moinvaziri 50f3252d2c Fixed missing crc32 stream include. 2018-07-11 09:56:23 -07:00
Nathan Moinvaziri adbbc68fa4 Fixed missing include for crc32 stream. 2018-07-11 09:48:27 -07:00
Nathan Moinvaziri 34e2ab5065 Added crc32 stream. 2018-07-11 09:46:38 -07:00
Nathan Moinvaziri b47b41b8df Move crc32 stream into its own source file and header. 2018-07-11 09:44:29 -07:00
Nathan Moinvaziri 155f8b52b2 Version 2.3.5. 2018-07-09 08:13:28 -07:00
Nathan Moinvaziri 5d3b5c593d Fixed copyright statements on interface headers due to rewrite. 2018-07-09 08:11:16 -07:00
Nathan Moinvaziri e3958d9b46 Rename file. 2018-07-09 07:54:26 -07:00
Nathan Moinvaziri 957e5f92e4 Added 0 byte file for testing. 2018-07-09 07:53:54 -07:00
Nathan Moinvaziri 184f4cbde1 Added comment if entire entry is not read. 2018-07-09 07:53:17 -07:00
Nathan Moinvaziri 8871f6c0f1 Expose more prop values from streams.
Simplify some logic.
2018-07-08 19:23:56 -07:00
Nathan Moinvaziri fa8105b657 Use crypt header size in calculation. 2018-07-08 19:05:00 -07:00
Nathan Moinvaziri 2cf91c09ce Don't finalize compression stream if nothing written. #277 2018-07-08 18:53:52 -07:00
Nathan Moinvaziri 9eecff3140 Simplify command line parsing. 2018-07-08 18:52:41 -07:00
Nathan Moinvaziri 77dcb77506 Fixed lzma not flushing all remaining codes. #275 2018-07-07 12:21:25 -07:00
Nathan Moinvaziri ef776a31e1 Updated to liblzma 5.2.4. 2018-07-07 11:10:11 -07:00
49 changed files with 601 additions and 486 deletions
-7
View File
@@ -7,13 +7,8 @@ compiler:
- clang
- gcc
python:
- "2.7"
before_install:
- sudo apt-get install libbsd-dev
- sudo pip install --upgrade pip
- sudo pip install numpy
before_script:
- mkdir build
@@ -22,5 +17,3 @@ before_script:
script:
- make
- cd ../test
- travis_wait 30 python test.py --exe_dir=../build
+3 -1
View File
@@ -32,7 +32,7 @@ set(INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Installation directory f
set(INSTALL_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/minizip CACHE PATH "Installation directory for cmake files.")
set(VERSION "2.3.4")
set(VERSION "2.3.7")
# Set cmake debug postfix to d
set(CMAKE_DEBUG_POSTFIX "d")
@@ -57,6 +57,7 @@ set(MINIZIP_SRC
mz_compat.c
mz_strm.c
mz_strm_buf.c
mz_strm_crc32.c
mz_strm_mem.c
mz_strm_posix.c
mz_strm_split.c
@@ -68,6 +69,7 @@ set(MINIZIP_PUBLIC_HEADERS
mz_compat.h
mz_strm.h
mz_strm_buf.h
mz_strm_crc32.h
mz_strm_mem.h
mz_strm_posix.h
mz_strm_split.h
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Minizip'
s.version = '2.3.4'
s.version = '2.3.7'
s.license = 'zlib'
s.summary = 'Minizip contrib in zlib with the latest bug fixes and advanced features'
s.description = <<-DESC
+2 -1
View File
@@ -1,4 +1,4 @@
# Minizip 2.3.4
# Minizip 2.3.7
This library is a refactoring of the minizip contribution found in the zlib distribution and is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
@@ -67,6 +67,7 @@ cmake . -DZLIB_LIBRARY=lib\zlib\release\zlibstatic.lib -DZLIB_INCLUDE_DIR=lib\zl
| mz_strm_aes.\* | WinZIP AES stream | No |
| mz_strm_buf.\* | Buffered stream | No |
| mz_strm_bzip.\* | BZIP2 stream using libbzip2 | No |
| mz_strm_crc32.\* | CRC32 stream | Yes |
| mz_strm_lzma.\* | LZMA stream using liblzma | zlib or liblzma |
| mz_strm_mem.\* | Memory stream | Yes |
| mz_strm_split.\* | Disk splitting stream | No |
+5 -1
View File
@@ -219,7 +219,11 @@
*/
#ifndef lzma_nothrow
# if defined(__cplusplus)
# define lzma_nothrow throw()
# if __cplusplus >= 201103L
# define lzma_nothrow noexcept
# else
# define lzma_nothrow throw()
# endif
# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
# define lzma_nothrow __attribute__((__nothrow__))
# else
+6 -1
View File
@@ -644,11 +644,16 @@ extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
* This function is supported only when *strm has been initialized with
* a function that takes a memlimit argument.
*
* liblzma 5.2.3 and earlier has a bug where memlimit value of 0 causes
* this function to do nothing (leaving the limit unchanged) and still
* return LZMA_OK. Later versions treat 0 as if 1 had been specified (so
* lzma_memlimit_get() will return 1 even if you specify 0 here).
*
* \return - LZMA_OK: New memory usage limit successfully set.
* - LZMA_MEMLIMIT_ERROR: The new limit is too small.
* The limit was not changed.
* - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
* support memory usage limit or memlimit was zero.
* support memory usage limit.
*/
extern LZMA_API(lzma_ret) lzma_memlimit_set(
lzma_stream *strm, uint64_t memlimit) lzma_nothrow;
+17 -4
View File
@@ -520,7 +520,10 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter.
* to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return
* LZMA_PROG_ERROR; later versions treat 0 as if 1
* had been specified.
* \param flags Bitwise-or of zero or more of the decoder flags:
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
* LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED
@@ -544,7 +547,10 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder(
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter.
* to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return
* LZMA_PROG_ERROR; later versions treat 0 as if 1
* had been specified.
* \param flags Bitwise-or of flags, or zero for no flags.
*
* \return - LZMA_OK: Initialization was successful.
@@ -560,9 +566,16 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder(
/**
* \brief Initialize .lzma decoder (legacy file format)
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return
* LZMA_PROG_ERROR; later versions treat 0 as if 1
* had been specified.
*
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
* There is no need to use LZMA_FINISH, but allowing it may simplify
* certain types of applications.
* There is no need to use LZMA_FINISH, but it's allowed because it may
* simplify certain types of applications.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
+1 -1
View File
@@ -22,7 +22,7 @@
*/
#define LZMA_VERSION_MAJOR 5
#define LZMA_VERSION_MINOR 2
#define LZMA_VERSION_PATCH 3
#define LZMA_VERSION_PATCH 4
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
#ifndef LZMA_VERSION_COMMIT
+3 -3
View File
@@ -109,9 +109,9 @@ extern const uint64_t lzma_crc64_table[4][256];
/// \brief Initialize *check depending on type
///
/// \param check LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type
/// is not supported by the current version or build of
/// liblzma. LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
/// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
/// supported by the current version or build of liblzma.
/// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
extern void lzma_check_init(lzma_check_state *check, lzma_check type);
/// Update the check state
+1 -4
View File
@@ -184,9 +184,6 @@ lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
{
lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
if (memlimit == 0)
return LZMA_PROG_ERROR;
lzma_alone_coder *coder = next->coder;
if (coder == NULL) {
@@ -208,7 +205,7 @@ lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
coder->options.preset_dict = NULL;
coder->options.preset_dict_size = 0;
coder->uncompressed_size = 0;
coder->memlimit = memlimit;
coder->memlimit = my_max(1, memlimit);
coder->memusage = LZMA_MEMUSAGE_BASE;
return LZMA_OK;
+4 -2
View File
@@ -435,8 +435,10 @@ lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
|| strm->internal->next.memconfig == NULL)
return LZMA_PROG_ERROR;
if (new_memlimit != 0 && new_memlimit < LZMA_MEMUSAGE_BASE)
return LZMA_MEMLIMIT_ERROR;
// Zero is a special value that cannot be used as an actual limit.
// If 0 was specified, use 1 instead.
if (new_memlimit == 0)
new_memlimit = 1;
return strm->internal->next.memconfig(strm->internal->next.coder,
&memusage, &old_memlimit, new_memlimit);
+6
View File
@@ -16,6 +16,12 @@
#include "lzma_decoder.h"
#include "range_decoder.h"
// The macros unroll loops with switch statements.
// Silence warnings about missing fall-through comments.
#if TUKLIB_GNUC_REQ(7, 0)
# pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
#ifdef HAVE_SMALL
+54 -61
View File
@@ -1,5 +1,5 @@
/* minizip.c
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -101,7 +101,6 @@ int32_t minizip_add_path(void *handle, const char *path, const char *filenameinz
filenameinzip += 1;
// Get information about the file on disk so we can store it in zip
printf("Adding: %s\n", filenameinzip);
file_info.version_madeby = MZ_VERSION_MADEBY;
file_info.compression_method = options->compress_method;
@@ -117,6 +116,8 @@ int32_t minizip_add_path(void *handle, const char *path, const char *filenameinz
&file_info.creation_date);
mz_os_get_file_attribs(path, &file_info.external_fa);
printf("Adding: %s\n", file_info.filename);
// Add to zip
err = mz_zip_entry_write_open(handle, &file_info, options->compress_level, password);
if (err != MZ_OK)
@@ -427,8 +428,8 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
if (err == MZ_OK)
{
// Some zips don't contain directory alone before file
if ((mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE) != MZ_OK) &&
(filename != file_info->filename))
err = mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
if ((err != MZ_OK) && (filename != file_info->filename))
{
// Create the directory of the output path
strncpy(directory, out_path, sizeof(directory));
@@ -436,12 +437,12 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
mz_path_remove_filename(directory);
mz_make_dir(directory);
mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
err = mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
}
}
// Read from the zip, unzip to buffer, and write to disk
if (mz_stream_os_is_open(stream) == MZ_OK)
if (err == MZ_OK)
{
printf(" Extracting: %s\n", out_path);
while (1)
@@ -473,7 +474,7 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
}
else
{
printf("Error opening %s\n", out_path);
printf("Error %d opening %s\n", err, out_path);
}
mz_stream_os_delete(&stream);
@@ -570,65 +571,57 @@ int main(int argc, char *argv[])
// Parse command line options
for (i = 1; i < argc; i += 1)
{
if ((*argv[i]) == '-')
if (argv[i][0] == '-')
{
const char *p = argv[i] + 1;
while ((*p) != '\0')
char c = argv[i][1];
if ((c == 'l') || (c == 'L'))
do_list = 1;
if ((c == 'x') || (c == 'X'))
do_extract = 1;
if ((c == 'a') || (c == 'A'))
append = 1;
if ((c == 'u') || (c == 'U'))
buffered = 1;
if ((c == 'o') || (c == 'O'))
options.overwrite = 1;
if ((c == 'i') || (c == 'I'))
options.include_path = 1;
if ((c >= '0') && (c <= '9'))
{
char c = *(p++);
if ((c == 'l') || (c == 'L'))
do_list = 1;
if ((c == 'x') || (c == 'X'))
do_extract = 1;
if ((c == 'a') || (c == 'A'))
append = 1;
if ((c == 'u') || (c == 'U'))
buffered = 1;
if ((c == 'o') || (c == 'O'))
options.overwrite = 1;
if ((c == 'i') || (c == 'I'))
options.include_path = 1;
if ((c >= '0') && (c <= '9'))
{
options.compress_level = (c - '0');
if (options.compress_level == 0)
options.compress_method = MZ_COMPRESS_METHOD_RAW;
}
#ifdef HAVE_BZIP2
if ((c == 'b') || (c == 'B'))
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
#endif
#ifdef HAVE_LZMA
if ((c == 'm') || (c == 'M'))
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
#endif
#ifdef HAVE_AES
if ((c == 's') || (c == 'S'))
options.aes = 1;
#endif
if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
{
disk_size = atoi(argv[i + 1]) * 1024;
i += 1;
}
if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
{
destination = argv[i + 1];
i += 1;
}
if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
{
password = argv[i + 1];
i += 1;
}
options.compress_level = (c - '0');
if (options.compress_level == 0)
options.compress_method = MZ_COMPRESS_METHOD_RAW;
}
continue;
#ifdef HAVE_BZIP2
if ((c == 'b') || (c == 'B'))
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
#endif
#ifdef HAVE_LZMA
if ((c == 'm') || (c == 'M'))
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
#endif
#ifdef HAVE_AES
if ((c == 's') || (c == 'S'))
options.aes = 1;
#endif
if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
{
disk_size = atoi(argv[i + 1]) * 1024;
i += 1;
}
if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
{
destination = argv[i + 1];
i += 1;
}
if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
{
password = argv[i + 1];
i += 1;
}
}
if (path_arg == 0)
else if (path_arg == 0)
path_arg = i;
}
+2 -2
View File
@@ -1,5 +1,5 @@
/* mz.h -- Errors codes, zip flags and magic
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -19,7 +19,7 @@ extern "C" {
/***************************************************************************/
// MZ_VERSION
#define MZ_VERSION ("2.3.4")
#define MZ_VERSION ("2.3.7")
// MZ_ERROR
#define MZ_OK (0)
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_compat.c -- Backwards compatible interface for older versions
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_compat.h -- Backwards compatible interface for older versions
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+2 -17
View File
@@ -1,5 +1,5 @@
/* mz_os.c -- System functions
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -18,12 +18,7 @@
#include "mz.h"
#include "mz_os.h"
#include "mz_strm.h"
#ifdef HAVE_LZMA
# include "mz_strm_lzma.h"
#endif
#ifdef HAVE_ZLIB
# include "mz_strm_zlib.h"
#endif
#include "mz_strm_crc32.h"
/***************************************************************************/
@@ -253,16 +248,6 @@ int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
mz_stream_crc32_create(&crc32_stream);
#ifdef HAVE_ZLIB
mz_stream_crc32_set_update_func(crc32_stream,
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update());
#elif defined(HAVE_LZMA)
mz_stream_crc32_set_update_func(crc32_stream,
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update());
#else
#error ZLIB or LZMA required for CRC32
#endif
mz_stream_crc32_open(crc32_stream, NULL, MZ_OPEN_MODE_READ);
mz_stream_set_base(crc32_stream, stream);
+1 -3
View File
@@ -1,11 +1,9 @@
/* mz_os.h -- System functions
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_os_posix.c -- System functions for posix
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_os_posix.h -- System functions for posix
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -2
View File
@@ -1,5 +1,5 @@
/* mz_os_win32.c -- System functions for Windows
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -14,7 +14,6 @@
#include <string.h>
#include <time.h>
#include <direct.h>
#include <errno.h>
#include <windows.h>
#include <wincrypt.h>
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_os_win32.h -- System functions for Windows
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -161
View File
@@ -1,5 +1,5 @@
/* mz_strm.c -- Stream interface
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -13,8 +13,6 @@
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "mz.h"
#include "mz_strm.h"
@@ -270,164 +268,6 @@ void mz_stream_delete(void **stream)
/***************************************************************************/
static mz_stream_vtbl mz_stream_crc32_vtbl = {
mz_stream_crc32_open,
mz_stream_crc32_is_open,
mz_stream_crc32_read,
mz_stream_crc32_write,
mz_stream_crc32_tell,
mz_stream_crc32_seek,
mz_stream_crc32_close,
mz_stream_crc32_error,
mz_stream_crc32_create,
mz_stream_crc32_delete,
mz_stream_crc32_get_prop_int64,
NULL
};
/***************************************************************************/
typedef struct mz_stream_crc32_s {
mz_stream stream;
int8_t initialized;
int64_t value;
int64_t total_in;
int64_t total_out;
mz_stream_crc32_update update;
} mz_stream_crc32;
/***************************************************************************/
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
MZ_UNUSED(path);
MZ_UNUSED(mode);
crc32->initialized = 1;
crc32->value = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_is_open(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
if (crc32->initialized != 1)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t read = 0;
read = mz_stream_read(crc32x->stream.base, buf, size);
if (read > 0)
crc32x->value = crc32x->update(crc32x->value, buf, read);
crc32x->total_in += read;
return read;
}
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t written = 0;
crc32x->value = crc32x->update(crc32x->value, buf, size);
written = mz_stream_write(crc32x->stream.base, buf, size);
crc32x->total_out += written;
return written;
}
int64_t mz_stream_crc32_tell(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_tell(crc32->stream.base);
}
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->value = 0;
return mz_stream_seek(crc32->stream.base, offset, origin);
}
int32_t mz_stream_crc32_close(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_error(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_error(crc32->stream.base);
}
int32_t mz_stream_crc32_get_value(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return (int32_t)crc32->value;
}
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = crc32->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = crc32->total_out;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->update = update;
return MZ_OK;
}
void *mz_stream_crc32_create(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
crc32 = (mz_stream_crc32 *)MZ_ALLOC(sizeof(mz_stream_crc32));
if (crc32 != NULL)
{
memset(crc32, 0, sizeof(mz_stream_crc32));
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
}
if (stream != NULL)
*stream = crc32;
return crc32;
}
void mz_stream_crc32_delete(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
if (stream == NULL)
return;
crc32 = (mz_stream_crc32 *)*stream;
if (crc32 != NULL)
MZ_FREE(crc32);
*stream = NULL;
}
void *mz_stream_crc32_get_interface(void)
{
return (void *)&mz_stream_crc32_vtbl;
}
/***************************************************************************/
typedef struct mz_stream_raw_s {
mz_stream stream;
int64_t total_in;
+1 -24
View File
@@ -1,5 +1,5 @@
/* mz_strm.h -- Stream interface
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -99,29 +99,6 @@ void mz_stream_delete(void **stream);
/***************************************************************************/
typedef int64_t (*mz_stream_crc32_update)(int64_t value, const void *buf, int32_t size);
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crc32_is_open(void *stream);
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crc32_tell(void *stream);
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_crc32_close(void *stream);
int32_t mz_stream_crc32_error(void *stream);
int32_t mz_stream_crc32_get_value(void *stream);
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update);
void* mz_stream_crc32_create(void **stream);
void mz_stream_crc32_delete(void **stream);
void* mz_stream_crc32_get_interface(void);
/***************************************************************************/
int32_t mz_stream_raw_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_raw_is_open(void *stream);
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size);
+28 -7
View File
@@ -1,5 +1,5 @@
/* mz_strm_aes.c -- Stream for WinZip AES encryption
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -50,7 +50,7 @@ static mz_stream_vtbl mz_stream_aes_vtbl = {
mz_stream_aes_create,
mz_stream_aes_delete,
mz_stream_aes_get_prop_int64,
NULL
mz_stream_aes_set_prop_int64
};
/***************************************************************************/
@@ -62,6 +62,7 @@ typedef struct mz_stream_aes_s {
int16_t initialized;
uint8_t buffer[INT16_MAX];
int64_t total_in;
int64_t max_total_in;
int64_t total_out;
int16_t encryption_mode;
const char *password;
@@ -269,6 +270,7 @@ int32_t mz_stream_aes_close(void *stream)
aes->total_in += MZ_AES_AUTHCODE_SIZE;
// If entire entry was not read this will fail
if (memcmp(authcode, verify_authcode, MZ_AES_AUTHCODE_SIZE) != 0)
return MZ_CRC_ERROR;
}
@@ -302,18 +304,37 @@ int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = aes->total_in;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = aes->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
*value = aes->max_total_in;
break;
case MZ_STREAM_PROP_HEADER_SIZE:
*value = MZ_AES_SALT_LENGTH(aes->encryption_mode) + MZ_AES_PW_VERIFY_SIZE;
return MZ_OK;
break;
case MZ_STREAM_PROP_FOOTER_SIZE:
*value = MZ_AES_AUTHCODE_SIZE;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_stream_aes_set_prop_int64(void *stream, int32_t prop, int64_t value)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN_MAX:
aes->max_total_in = value;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_OK;
}
void *mz_stream_aes_create(void **stream)
+2 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -33,6 +33,7 @@ void mz_stream_aes_set_password(void *stream, const char *password);
void mz_stream_aes_set_encryption_mode(void *stream, int16_t encryption_mode);
int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value);
int32_t mz_stream_aes_set_prop_int64(void *stream, int32_t prop, int64_t value);
void* mz_stream_aes_create(void **stream);
void mz_stream_aes_delete(void **stream);
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_buf.c -- Stream for buffering reads/writes
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
This version of ioapi is designed to buffer IO.
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_buf.h -- Stream for buffering reads/writes
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
This version of ioapi is designed to buffer IO.
+10 -5
View File
@@ -1,5 +1,5 @@
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -340,15 +340,20 @@ int32_t mz_stream_bzip_get_prop_int64(void *stream, int32_t prop, int64_t *value
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = bzip->total_in;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
*value = bzip->max_total_in;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = bzip->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_HEADER_SIZE:
*value = 0;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_stream_bzip_set_prop_int64(void *stream, int32_t prop, int64_t value)
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+206
View File
@@ -0,0 +1,206 @@
/* mz_strm_crc32.c -- Stream for CRC32 hashing
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "mz.h"
#include "mz_strm.h"
#include "mz_strm_crc32.h"
#ifdef HAVE_LZMA
#include "mz_strm_lzma.h"
#endif
#ifdef HAVE_ZLIB
#include "mz_strm_zlib.h"
#endif
/***************************************************************************/
static mz_stream_vtbl mz_stream_crc32_vtbl = {
mz_stream_crc32_open,
mz_stream_crc32_is_open,
mz_stream_crc32_read,
mz_stream_crc32_write,
mz_stream_crc32_tell,
mz_stream_crc32_seek,
mz_stream_crc32_close,
mz_stream_crc32_error,
mz_stream_crc32_create,
mz_stream_crc32_delete,
mz_stream_crc32_get_prop_int64,
NULL
};
/***************************************************************************/
typedef struct mz_stream_crc32_s {
mz_stream stream;
int8_t initialized;
int64_t value;
int64_t total_in;
int64_t total_out;
mz_stream_crc32_update
update;
} mz_stream_crc32;
/***************************************************************************/
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
MZ_UNUSED(path);
MZ_UNUSED(mode);
crc32->initialized = 1;
crc32->value = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_is_open(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
if (crc32->initialized != 1)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t read = 0;
read = mz_stream_read(crc32x->stream.base, buf, size);
if (read > 0)
{
crc32x->value = crc32x->update(crc32x->value, buf, read);
crc32x->total_in += read;
}
return read;
}
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t written = 0;
crc32x->value = crc32x->update(crc32x->value, buf, size);
written = mz_stream_write(crc32x->stream.base, buf, size);
crc32x->total_out += written;
return written;
}
int64_t mz_stream_crc32_tell(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_tell(crc32->stream.base);
}
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->value = 0;
return mz_stream_seek(crc32->stream.base, offset, origin);
}
int32_t mz_stream_crc32_close(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_error(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_error(crc32->stream.base);
}
int32_t mz_stream_crc32_get_value(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return (int32_t)crc32->value;
}
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = crc32->total_in;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = crc32->total_out;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_OK;
}
void *mz_stream_crc32_create(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
crc32 = (mz_stream_crc32 *)MZ_ALLOC(sizeof(mz_stream_crc32));
if (crc32 != NULL)
{
memset(crc32, 0, sizeof(mz_stream_crc32));
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
}
#ifdef HAVE_ZLIB
crc32->update =
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update();
#elif defined(HAVE_LZMA)
crc32->update =
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update();
#else
#error ZLIB or LZMA required for CRC32
#endif
if (stream != NULL)
*stream = crc32;
return crc32;
}
void mz_stream_crc32_delete(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
if (stream == NULL)
return;
crc32 = (mz_stream_crc32 *)*stream;
if (crc32 != NULL)
MZ_FREE(crc32);
*stream = NULL;
}
void *mz_stream_crc32_get_interface(void)
{
return (void *)&mz_stream_crc32_vtbl;
}
int32_t mz_stream_crc32_get_update_func(mz_stream_crc32_update *update)
{
if (update == NULL)
return MZ_PARAM_ERROR;
#ifdef HAVE_ZLIB
*update =
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update();
#elif defined(HAVE_LZMA)
*update =
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update();
#else
#error ZLIB or LZMA required for CRC32
#endif
return MZ_OK;
}
+50
View File
@@ -0,0 +1,50 @@
/* mz_strm_crc32.h -- Stream for CRC32 hashing
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef MZ_STREAM_CRC32_H
#define MZ_STREAM_CRC32_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
typedef int64_t (*mz_stream_crc32_update)(int64_t value, const void *buf, int32_t size);
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crc32_is_open(void *stream);
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crc32_tell(void *stream);
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_crc32_close(void *stream);
int32_t mz_stream_crc32_error(void *stream);
int32_t mz_stream_crc32_get_value(void *stream);
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
void* mz_stream_crc32_create(void **stream);
void mz_stream_crc32_delete(void **stream);
void* mz_stream_crc32_get_interface(void);
int32_t mz_stream_crc32_get_update_func(mz_stream_crc32_update *update);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+20 -16
View File
@@ -1,5 +1,5 @@
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -275,7 +275,7 @@ static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
lzma->buffer_len += out_bytes;
lzma->total_out += out_bytes;
}
while (lzma->lstream.avail_in > 0);
while ((lzma->lstream.avail_in > 0) || (flush == LZMA_FINISH && err == LZMA_OK));
return MZ_OK;
}
@@ -359,15 +359,23 @@ int32_t mz_stream_lzma_get_prop_int64(void *stream, int32_t prop, int64_t *value
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = lzma->total_in;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
*value = lzma->max_total_in;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = lzma->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_OUT_MAX:
*value = lzma->max_total_out;
break;
case MZ_STREAM_PROP_HEADER_SIZE:
*value = MZ_LZMA_HEADER_SIZE;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_stream_lzma_set_prop_int64(void *stream, int32_t prop, int64_t value)
@@ -380,17 +388,19 @@ int32_t mz_stream_lzma_set_prop_int64(void *stream, int32_t prop, int64_t value)
lzma->preset = LZMA_PRESET_EXTREME;
else
lzma->preset = LZMA_PRESET_DEFAULT;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
lzma->max_total_in = value;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_OUT_MAX:
if (value < -1)
return MZ_PARAM_ERROR;
lzma->max_total_out = value;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
void *mz_stream_lzma_create(void **stream)
@@ -432,12 +442,6 @@ static int64_t mz_stream_lzma_crc32(int64_t value, const void *buf, int32_t size
return (int32_t)lzma_crc32(buf, size, (int32_t)value);
}
void *mz_stream_lzma_get_crc32_table(void)
{
extern const uint32_t lzma_crc32_table;
return (void *)lzma_crc32_table;
}
void *mz_stream_lzma_get_crc32_update(void)
{
return (void *)mz_stream_lzma_crc32;
+1 -2
View File
@@ -1,5 +1,5 @@
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -36,7 +36,6 @@ void* mz_stream_lzma_create(void **stream);
void mz_stream_lzma_delete(void **stream);
void* mz_stream_lzma_get_interface(void);
void* mz_stream_lzma_get_crc32_table(void);
void* mz_stream_lzma_get_crc32_update(void);
/***************************************************************************/
+7 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_mem.c -- Stream for memory access
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
This interface is designed to access memory rather than files.
@@ -234,6 +234,12 @@ void mz_stream_mem_get_buffer_length(void *stream, int32_t *length)
*length = mem->limit;
}
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
mem->limit = limit;
}
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
+2 -3
View File
@@ -1,11 +1,9 @@
/* mz_strm_mem.h -- Stream for memory access
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
@@ -35,6 +33,7 @@ void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size);
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf);
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf);
void mz_stream_mem_get_buffer_length(void *stream, int32_t *length);
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit);
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
void* mz_stream_mem_create(void **stream);
+64 -73
View File
@@ -1,12 +1,12 @@
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
@@ -27,24 +27,15 @@
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_ZLIB
#include "zlib.h"
#endif
#include "mz.h"
#include "mz_os.h"
#include "mz_strm.h"
#ifdef HAVE_LZMA
#include "mz_strm_lzma.h"
#endif
#include "mz_strm_crc32.h"
#include "mz_strm_pkcrypt.h"
#ifdef HAVE_ZLIB
#include "mz_strm_zlib.h"
#endif
/***************************************************************************/
#define RAND_HEAD_LEN 12
#define RAND_HEAD_LEN (12)
/***************************************************************************/
@@ -65,17 +56,6 @@ static mz_stream_vtbl mz_stream_pkcrypt_vtbl = {
/***************************************************************************/
// Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng
#if (ZLIB_VERNUM < 0x1270) || defined(ZLIBNG_VERNUM) || !defined(HAVE_ZLIB)
#ifdef HAVE_ZLIB
typedef unsigned long z_crc_t;
#else
typedef uint32_t z_crc_t;
#endif
#endif
/***************************************************************************/
typedef struct mz_stream_pkcrypt_s {
mz_stream stream;
int32_t error;
@@ -84,55 +64,65 @@ typedef struct mz_stream_pkcrypt_s {
int64_t total_in;
int64_t total_out;
uint32_t keys[3]; // keys defining the pseudo-random sequence
const z_crc_t *crc_32_tab;
uint8_t verify1;
uint8_t verify2;
const char *password;
mz_stream_crc32_update
crc32_update;
} mz_stream_pkcrypt;
/***************************************************************************/
#define zdecode(keys,crc_32_tab,c) \
(mz_stream_pkcrypt_update_keys(keys,crc_32_tab, c ^= mz_stream_pkcrypt_decrypt_byte(keys)))
#define mz_stream_pkcrypt_decode(strm, c) \
(mz_stream_pkcrypt_update_keys(strm, \
c ^= mz_stream_pkcrypt_decrypt_byte(strm)))
#define zencode(keys,crc_32_tab,c,t) \
(t = mz_stream_pkcrypt_decrypt_byte(keys), mz_stream_pkcrypt_update_keys(keys,crc_32_tab,c), t^(c))
#define mz_stream_pkcrypt_encode(strm, c, t) \
(t = mz_stream_pkcrypt_decrypt_byte(strm), \
mz_stream_pkcrypt_update_keys(strm, c), t^(c))
/***************************************************************************/
static uint8_t mz_stream_pkcrypt_decrypt_byte(uint32_t *keys)
static uint8_t mz_stream_pkcrypt_decrypt_byte(void *stream)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
temp = ((uint32_t)(*(keys+2)) & 0xffff) | 2;
unsigned temp; // POTENTIAL BUG: temp*(temp^1) may overflow in an
// unpredictable manner on 16-bit systems; not a problem
// with any known compiler so far, though.
temp = pkcrypt->keys[2] | 2;
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
static uint8_t mz_stream_pkcrypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
static uint8_t mz_stream_pkcrypt_update_keys(void *stream, uint8_t c)
{
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
uint8_t buf = c;
pkcrypt->keys[0] = (uint32_t)~pkcrypt->crc32_update(~pkcrypt->keys[0], &buf, 1);
pkcrypt->keys[1] += pkcrypt->keys[0] & 0xff;
pkcrypt->keys[1] *= 134775813L;
pkcrypt->keys[1] += 1;
buf = (uint8_t)(pkcrypt->keys[1] >> 24);
pkcrypt->keys[2] = (uint32_t)~pkcrypt->crc32_update(~pkcrypt->keys[2], &buf, 1);
(*(keys+0)) = (uint32_t)CRC32((*(keys+0)), c);
(*(keys+1)) += (*(keys+0)) & 0xff;
(*(keys+1)) = (*(keys+1)) * 134775813L + 1;
{
register int32_t keyshift = (int32_t)((*(keys + 1)) >> 24);
(*(keys+2)) = (uint32_t)CRC32((*(keys+2)), keyshift);
}
return (uint8_t)c;
}
static void mz_stream_pkcrypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
static void mz_stream_pkcrypt_init_keys(void *stream, const char *password)
{
*(keys+0) = 305419896L;
*(keys+1) = 591751049L;
*(keys+2) = 878082192L;
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
pkcrypt->keys[0] = 305419896L;
pkcrypt->keys[1] = 591751049L;
pkcrypt->keys[2] = 878082192L;
while (*password != 0)
{
mz_stream_pkcrypt_update_keys(keys, crc_32_tab, *password);
mz_stream_pkcrypt_update_keys(stream, *password);
password += 1;
}
}
@@ -144,7 +134,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
uint16_t t = 0;
int16_t i = 0;
//uint8_t verify1 = 0;
uint8_t verify1 = 0;
uint8_t verify2 = 0;
uint8_t header[RAND_HEAD_LEN];
const char *password = path;
@@ -161,18 +151,10 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
if (password == NULL)
return MZ_STREAM_ERROR;
#ifdef HAVE_ZLIB
pkcrypt->crc_32_tab = (z_crc_t *)mz_stream_zlib_get_crc32_table();
#elif defined(HAVE_LZMA)
pkcrypt->crc_32_tab = (z_crc_t *)mz_stream_lzma_get_crc32_table();
#else
#error ZLIB or LZMA required for CRC32
#endif
if (pkcrypt->crc_32_tab == NULL)
return MZ_STREAM_ERROR;
if (mz_stream_crc32_get_update_func(&pkcrypt->crc32_update) != MZ_OK)
return MZ_PARAM_ERROR;
mz_stream_pkcrypt_init_keys(password, pkcrypt->keys, pkcrypt->crc_32_tab);
mz_stream_pkcrypt_init_keys(stream, password);
if (mode & MZ_OPEN_MODE_WRITE)
{
@@ -181,10 +163,10 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
// Encrypt random header (last two bytes is high word of crc)
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i], t);
header[i] = mz_stream_pkcrypt_encode(stream, header[i], t);
header[i++] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, pkcrypt->verify1, t);
header[i++] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, pkcrypt->verify2, t);
header[i++] = mz_stream_pkcrypt_encode(stream, pkcrypt->verify1, t);
header[i++] = mz_stream_pkcrypt_encode(stream, pkcrypt->verify2, t);
if (mz_stream_write(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
@@ -197,12 +179,13 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
return MZ_STREAM_ERROR;
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i]);
header[i] = mz_stream_pkcrypt_decode(stream, header[i]);
//verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
verify2 = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i++]);
verify1 = mz_stream_pkcrypt_decode(stream, header[i++]);
verify2 = mz_stream_pkcrypt_decode(stream, header[i++]);
// Older versions used 2 byte check, newer versions use 1 byte check.
MZ_UNUSED(verify1);
if ((verify2 != 0) && (verify2 != pkcrypt->verify2))
return MZ_PASSWORD_ERROR;
@@ -231,7 +214,7 @@ int32_t mz_stream_pkcrypt_read(void *stream, void *buf, int32_t size)
read = mz_stream_read(pkcrypt->stream.base, buf, size);
for (i = 0; i < read; i++)
buf_ptr[i] = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, buf_ptr[i]);
buf_ptr[i] = mz_stream_pkcrypt_decode(stream, buf_ptr[i]);
pkcrypt->total_in += read;
return read;
@@ -249,7 +232,7 @@ int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size)
return MZ_STREAM_ERROR;
for (i = 0; i < size; i++)
pkcrypt->buffer[i] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, buf_ptr[i], t);
pkcrypt->buffer[i] = mz_stream_pkcrypt_encode(stream, buf_ptr[i], t);
written = mz_stream_write(pkcrypt->stream.base, pkcrypt->buffer, size);
@@ -311,12 +294,20 @@ int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *va
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = pkcrypt->total_in;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = pkcrypt->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_HEADER_SIZE:
*value = RAND_HEAD_LEN;
break;
case MZ_STREAM_PROP_FOOTER_SIZE:
*value = 0;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
void *mz_stream_pkcrypt_create(void **stream)
+1 -9
View File
@@ -1,17 +1,9 @@
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -6
View File
@@ -1,14 +1,9 @@
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
+12 -8
View File
@@ -1,5 +1,5 @@
/* mz_strm_split.c -- Stream for split files
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -338,15 +338,17 @@ int32_t mz_stream_split_get_prop_int64(void *stream, int32_t prop, int64_t *valu
{
case MZ_STREAM_PROP_TOTAL_OUT:
*value = split->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_DISK_NUMBER:
*value = split->number_disk;
return MZ_OK;
break;
case MZ_STREAM_PROP_DISK_SIZE:
*value = split->disk_size;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_stream_split_set_prop_int64(void *stream, int32_t prop, int64_t value)
@@ -356,12 +358,14 @@ int32_t mz_stream_split_set_prop_int64(void *stream, int32_t prop, int64_t value
{
case MZ_STREAM_PROP_DISK_NUMBER:
split->number_disk = (int32_t)value;
return MZ_OK;
break;
case MZ_STREAM_PROP_DISK_SIZE:
split->disk_size = value;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
void *mz_stream_split_create(void **stream)
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_split.h -- Stream for split files
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_strm_win32.c -- Stream for filesystem access for windows
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
+1 -6
View File
@@ -1,14 +1,9 @@
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
+24 -13
View File
@@ -1,5 +1,5 @@
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -23,6 +23,15 @@
/***************************************************************************/
// Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng
#if defined(ZLIBNG_VERNUM)
typedef uint32_t z_crc_t;
#elif (ZLIB_VERNUM < 0x1270)
typedef unsigned long z_crc_t;
#endif
/***************************************************************************/
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
@@ -343,15 +352,20 @@ int32_t mz_stream_zlib_get_prop_int64(void *stream, int32_t prop, int64_t *value
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = zlib->total_in;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
*value = zlib->max_total_in;
break;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = zlib->total_out;
return MZ_OK;
break;
case MZ_STREAM_PROP_HEADER_SIZE:
*value = 0;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value)
@@ -361,12 +375,14 @@ int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value)
{
case MZ_STREAM_PROP_COMPRESS_LEVEL:
zlib->level = (int16_t)value;
return MZ_OK;
break;
case MZ_STREAM_PROP_TOTAL_IN_MAX:
zlib->max_total_in = value;
return MZ_OK;
break;
default:
return MZ_EXIST_ERROR;
}
return MZ_EXIST_ERROR;
return MZ_OK;
}
void *mz_stream_zlib_create(void **stream)
@@ -407,11 +423,6 @@ static int64_t mz_stream_zlib_crc32(int64_t value, const void *buf, int32_t size
return crc32((z_crc_t)value, buf, size);
}
void *mz_stream_zlib_get_crc32_table(void)
{
return (void *)get_crc_table();
}
void *mz_stream_zlib_get_crc32_update(void)
{
return (void *)mz_stream_zlib_crc32;
+1 -2
View File
@@ -1,5 +1,5 @@
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -36,7 +36,6 @@ void* mz_stream_zlib_create(void **stream);
void mz_stream_zlib_delete(void **stream);
void* mz_stream_zlib_get_interface(void);
void* mz_stream_zlib_get_crc32_table(void);
void* mz_stream_zlib_get_crc32_update(void);
/***************************************************************************/
+48 -26
View File
@@ -1,5 +1,5 @@
/* zip.c -- Zip manipulation
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -30,16 +30,17 @@
#ifdef HAVE_BZIP2
# include "mz_strm_bzip.h"
#endif
#include "mz_strm_crc32.h"
#ifdef HAVE_LZMA
# include "mz_strm_lzma.h"
#endif
#include "mz_strm_mem.h"
#ifdef HAVE_PKCRYPT
# include "mz_strm_pkcrypt.h"
#endif
#ifdef HAVE_ZLIB
# include "mz_strm_zlib.h"
#endif
#include "mz_strm_mem.h"
#include "mz_zip.h"
@@ -78,6 +79,7 @@ typedef struct mz_zip_s
int32_t open_mode;
uint32_t disk_number_with_cd; // number of the disk with the central dir
uint64_t disk_offset_shift; // correction for zips that have wrong offset start of cd
uint64_t cd_start_pos; // pos of the first file in the central dir stream
uint64_t cd_current_pos; // pos of the current file in the central dir
@@ -86,7 +88,6 @@ typedef struct mz_zip_s
uint16_t entry_scanned;
uint16_t entry_opened; // 1 if a file in the zip is currently writ.
uint64_t entry_read;
int64_t number_entry;
@@ -249,7 +250,8 @@ static int32_t mz_zip_read_cd(void *handle)
// Offset of start of central directory with respect to the starting disk number
if (err == MZ_OK)
err = mz_stream_read_uint32(zip->stream, &value32);
zip->cd_offset = value32;
if (err == MZ_OK)
zip->cd_offset = value32;
// Zip file global comment length
if (err == MZ_OK)
err = mz_stream_read_uint16(zip->stream, &comment_size);
@@ -309,6 +311,28 @@ static int32_t mz_zip_read_cd(void *handle)
err = MZ_FORMAT_ERROR;
}
if (err == MZ_OK)
{
// Verify central directory signature exists at offset
err = mz_stream_seek(zip->stream, zip->cd_offset, MZ_SEEK_SET);
if (err == MZ_OK)
err = mz_stream_read_uint32(zip->stream, &value32);
if (value32 != MZ_ZIP_MAGIC_CENTRALHEADER)
{
// If not found attempt to seek backward to find it
err = mz_stream_seek(zip->stream, eocd_pos - zip->cd_size, MZ_SEEK_SET);
if (err == MZ_OK)
err = mz_stream_read_uint32(zip->stream, &value32);
if (value32 == MZ_ZIP_MAGIC_CENTRALHEADER)
{
// If found compensate for incorrect locations
value64 = zip->cd_offset;
zip->cd_offset = eocd_pos - zip->cd_size;
zip->disk_offset_shift = zip->cd_offset - value64;
}
}
}
if ((err == MZ_OK) && (comment_size > 0))
{
zip->comment = (char *)MZ_ALLOC(comment_size + 1);
@@ -1075,7 +1099,7 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
{
mz_zip *zip = (mz_zip *)handle;
int64_t max_total_in = 0;
int64_t total_in = 0;
int64_t header_size = 0;
int64_t footer_size = 0;
int32_t err = MZ_OK;
@@ -1100,10 +1124,8 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
return MZ_PARAM_ERROR;
}
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
return MZ_PARAM_ERROR;
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) &&
(zip->compression_method != MZ_COMPRESS_METHOD_RAW || password != NULL))
{
#ifdef HAVE_AES
if (zip->file_info.aes_version)
@@ -1185,10 +1207,13 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
if (zip->compression_method == MZ_COMPRESS_METHOD_RAW || zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED)
{
max_total_in = zip->file_info.compressed_size;
mz_stream_set_prop_int64(zip->crypt_stream, MZ_STREAM_PROP_TOTAL_IN_MAX, max_total_in);
if (mz_stream_get_prop_int64(zip->crypt_stream, MZ_STREAM_PROP_HEADER_SIZE, &header_size) == MZ_OK)
max_total_in -= header_size;
if (mz_stream_get_prop_int64(zip->crypt_stream, MZ_STREAM_PROP_FOOTER_SIZE, &footer_size) == MZ_OK)
max_total_in -= footer_size;
if (mz_stream_get_prop_int64(zip->crypt_stream, MZ_STREAM_PROP_TOTAL_IN, &total_in) == MZ_OK)
max_total_in -= total_in;
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_TOTAL_IN_MAX, max_total_in);
}
if (zip->compression_method == MZ_COMPRESS_METHOD_LZMA && (zip->file_info.flag & MZ_ZIP_FLAG_LZMA_EOS_MARKER) == 0)
@@ -1205,16 +1230,6 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
if (err == MZ_OK)
{
mz_stream_crc32_create(&zip->crc32_stream);
#ifdef HAVE_ZLIB
mz_stream_crc32_set_update_func(zip->crc32_stream,
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update());
#elif defined(HAVE_LZMA)
mz_stream_crc32_set_update_func(zip->crc32_stream,
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update());
#else
#error ZLIB or LZMA required for CRC32
#endif
mz_stream_set_base(zip->crc32_stream, zip->compress_stream);
err = mz_stream_open(zip->crc32_stream, NULL, zip->open_mode);
@@ -1252,7 +1267,7 @@ extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *pas
else
mz_stream_set_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, zip->file_info.disk_number);
err = mz_stream_seek(zip->stream, zip->file_info.disk_offset, MZ_SEEK_SET);
err = mz_stream_seek(zip->stream, zip->file_info.disk_offset + zip->disk_offset_shift, MZ_SEEK_SET);
if (err == MZ_OK)
err = mz_zip_entry_read_header(zip->stream, 1, &zip->local_file_info, zip->local_file_info_stream);
@@ -1353,11 +1368,15 @@ extern int32_t mz_zip_entry_read(void *handle, void *buf, uint32_t len)
return MZ_PARAM_ERROR;
if (UINT_MAX == UINT16_MAX && len > UINT16_MAX) // Zlib limitation
return MZ_PARAM_ERROR;
if (len == 0 || zip->file_info.uncompressed_size == 0)
if (len == 0)
return MZ_PARAM_ERROR;
if (zip->file_info.compressed_size == 0)
return 0;
// Read entire entry even if uncompressed_size = 0, otherwise
// aes encryption validation will fail if compressed_size > 0
read = mz_stream_read(zip->crc32_stream, buf, len);
if (read > 0)
zip->entry_read += read;
return read;
}
@@ -1394,6 +1413,7 @@ extern int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size,
{
mz_zip *zip = (mz_zip *)handle;
uint64_t compressed_size = 0;
int64_t total_in = 0;
int32_t err = MZ_OK;
if (zip == NULL || zip->entry_opened == 0)
@@ -1410,7 +1430,9 @@ extern int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size,
if (zip->file_info.aes_version <= 0x0001)
#endif
{
if ((zip->entry_read > 0) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
mz_stream_crc32_get_prop_int64(zip->crc32_stream, MZ_STREAM_PROP_TOTAL_IN, &total_in);
// If entire entry was not read this will fail
if ((total_in > 0) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
{
if (crc32 != zip->file_info.crc)
err = MZ_CRC_ERROR;
+1 -1
View File
@@ -1,5 +1,5 @@
/* mz_zip.h -- Zip manipulation
Version 2.3.4, June 19, 2018
Version 2.3.7, July 13, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
View File