libzip :
- aggiornamento alla versione 1.10.0.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -41,6 +41,9 @@
|
||||
/* to have *_MAX definitions for all types when compiling with g++ */
|
||||
#define __STDC_LIMIT_MACROS
|
||||
|
||||
/* to have ISO C secure library functions */
|
||||
#define __STDC_WANT_LIB_EXT1__ 1
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef ZIP_EXTERN
|
||||
#ifndef ZIP_STATIC
|
||||
@@ -97,6 +100,9 @@ typedef char bool;
|
||||
#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#if !defined(HAVE__SNWPRINTF_S)
|
||||
#define _snwprintf_s(buf, bufsz, len, fmt, ...) (_snwprintf((buf), (len), (fmt), __VA_ARGS__))
|
||||
#endif
|
||||
#if defined(HAVE__STRDUP)
|
||||
#if !defined(HAVE_STRDUP) || defined(_WIN32)
|
||||
#undef strdup
|
||||
@@ -125,6 +131,33 @@ typedef char bool;
|
||||
#define ftello(s) ((long)ftell((s)))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LOCALTIME_S
|
||||
#ifdef _WIN32
|
||||
/* Windows is incompatible to the C11 standard, hurray! */
|
||||
#define zip_localtime(t, tm) (localtime_s((tm), (t)) == 0 ? tm : NULL)
|
||||
#else
|
||||
#define zip_localtime localtime_s
|
||||
#endif
|
||||
#else
|
||||
#ifdef HAVE_LOCALTIME_R
|
||||
#define zip_localtime localtime_r
|
||||
#else
|
||||
#define zip_localtime(t, tm) (localtime(t))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMCPY_S
|
||||
#define memcpy_s(dest, destsz, src, count) (memcpy((dest), (src), (count)) == NULL)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF_S
|
||||
#ifdef HAVE__SNPRINTF_S
|
||||
#define snprintf_s(buf, bufsz, fmt, ...) (_snprintf_s((buf), (bufsz), (bufsz), (fmt), __VA_ARGS__))
|
||||
#else
|
||||
#define snprintf_s snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRCASECMP)
|
||||
#if defined(HAVE__STRICMP)
|
||||
#define strcasecmp _stricmp
|
||||
@@ -133,6 +166,19 @@ typedef char bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCPY_S
|
||||
#define strncpy_s(dest, destsz, src, count) (strncpy((dest), (src), (count)), 0)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR_S
|
||||
#define strerrorlen_s(errnum) (strlen(strerror(errnum)))
|
||||
#define strerror_s(buf, bufsz, errnum) ((void)strncpy_s((buf), (bufsz), strerror(errnum), (bufsz)), (buf)[(bufsz)-1] = '\0', strerrorlen_s(errnum) >= (bufsz))
|
||||
#else
|
||||
#ifndef HAVE_STRERRORLEN_S
|
||||
#define strerrorlen_s(errnum) 8192
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SIZEOF_OFF_T == 8
|
||||
#define ZIP_OFF_MAX ZIP_INT64_MAX
|
||||
#define ZIP_OFF_MIN ZIP_INT64_MIN
|
||||
|
||||
+13
-4
@@ -4,18 +4,20 @@
|
||||
#include "zipconf.h"
|
||||
#endif
|
||||
/* BEGIN DEFINES */
|
||||
#define ENABLE_FDOPEN
|
||||
/* #undef HAVE___PROGNAME */
|
||||
#define HAVE__CLOSE
|
||||
#define HAVE__DUP
|
||||
#define HAVE__FDOPEN
|
||||
#define HAVE__FILENO
|
||||
#define HAVE__SETMODE
|
||||
/*#define HAVE__SNPRINTF*/
|
||||
#define HAVE__SNPRINTF
|
||||
#define HAVE__SNPRINTF_S
|
||||
#define HAVE__SNWPRINTF_S
|
||||
#define HAVE__STRDUP
|
||||
#define HAVE__STRICMP
|
||||
#define HAVE__STRTOI64
|
||||
#define HAVE__STRTOUI64
|
||||
/* #undef HAVE__UMASK */
|
||||
#define HAVE__UNLINK
|
||||
/* #undef HAVE_ARC4RANDOM */
|
||||
/* #undef HAVE_CLONEFILE */
|
||||
@@ -23,6 +25,7 @@
|
||||
#define HAVE_CRYPTO
|
||||
/* #undef HAVE_FICLONERANGE */
|
||||
#define HAVE_FILENO
|
||||
/* #undef HAVE_FCHMOD */
|
||||
/* #undef HAVE_FSEEKO */
|
||||
/* #undef HAVE_FTELLO */
|
||||
/* #undef HAVE_GETPROGNAME */
|
||||
@@ -31,15 +34,21 @@
|
||||
/* #undef HAVE_LIBLZMA */
|
||||
/* #undef HAVE_LIBZSTD */
|
||||
/* #undef HAVE_LOCALTIME_R */
|
||||
#define HAVE_LOCALTIME_S
|
||||
#define HAVE_MEMCPY_S
|
||||
/* #undef HAVE_MBEDTLS */
|
||||
/* #undef HAVE_MKSTEMP */
|
||||
/* #undef HAVE_NULLABLE */
|
||||
/* #undef HAVE_OPENSSL */
|
||||
#define HAVE_SETMODE
|
||||
/* #define HAVE_SNPRINTF */
|
||||
#define HAVE_SNPRINTF
|
||||
/* #undef HAVE_SNPRINTF_S */
|
||||
/* #undef HAVE_STRCASECMP */
|
||||
#define HAVE_STRDUP
|
||||
#define HAVE_STRERROR_S
|
||||
/* #undef HAVE_STRERRORLEN_S */
|
||||
#define HAVE_STRICMP
|
||||
#define HAVE_STRNCPY_S
|
||||
#define HAVE_STRTOLL
|
||||
#define HAVE_STRTOULL
|
||||
/* #undef HAVE_STRUCT_TM_TM_ZONE */
|
||||
@@ -58,6 +67,6 @@
|
||||
#define HAVE_SHARED
|
||||
/* END DEFINES */
|
||||
#define PACKAGE "libzip"
|
||||
#define VERSION "1.8.0"
|
||||
#define VERSION "1.10.0"
|
||||
|
||||
#endif /* HAD_CONFIG_H */
|
||||
|
||||
+11
-2
@@ -4,6 +4,7 @@
|
||||
#include "zipconf.h"
|
||||
#endif
|
||||
/* BEGIN DEFINES */
|
||||
#define ENABLE_FDOPEN
|
||||
/* #undef HAVE___PROGNAME */
|
||||
#define HAVE__CLOSE
|
||||
#define HAVE__DUP
|
||||
@@ -11,11 +12,12 @@
|
||||
#define HAVE__FILENO
|
||||
#define HAVE__SETMODE
|
||||
#define HAVE__SNPRINTF
|
||||
#define HAVE__SNPRINTF_S
|
||||
#define HAVE__SNWPRINTF_S
|
||||
#define HAVE__STRDUP
|
||||
#define HAVE__STRICMP
|
||||
#define HAVE__STRTOI64
|
||||
#define HAVE__STRTOUI64
|
||||
/* #undef HAVE__UMASK */
|
||||
#define HAVE__UNLINK
|
||||
/* #undef HAVE_ARC4RANDOM */
|
||||
/* #undef HAVE_CLONEFILE */
|
||||
@@ -23,6 +25,7 @@
|
||||
#define HAVE_CRYPTO
|
||||
/* #undef HAVE_FICLONERANGE */
|
||||
#define HAVE_FILENO
|
||||
/* #undef HAVE_FCHMOD */
|
||||
/* #undef HAVE_FSEEKO */
|
||||
/* #undef HAVE_FTELLO */
|
||||
/* #undef HAVE_GETPROGNAME */
|
||||
@@ -31,15 +34,21 @@
|
||||
/* #undef HAVE_LIBLZMA */
|
||||
/* #undef HAVE_LIBZSTD */
|
||||
/* #undef HAVE_LOCALTIME_R */
|
||||
#define HAVE_LOCALTIME_S
|
||||
#define HAVE_MEMCPY_S
|
||||
/* #undef HAVE_MBEDTLS */
|
||||
/* #undef HAVE_MKSTEMP */
|
||||
/* #undef HAVE_NULLABLE */
|
||||
/* #undef HAVE_OPENSSL */
|
||||
#define HAVE_SETMODE
|
||||
#define HAVE_SNPRINTF
|
||||
/* #undef HAVE_SNPRINTF_S */
|
||||
/* #undef HAVE_STRCASECMP */
|
||||
#define HAVE_STRDUP
|
||||
#define HAVE_STRERROR_S
|
||||
/* #undef HAVE_STRERRORLEN_S */
|
||||
#define HAVE_STRICMP
|
||||
#define HAVE_STRNCPY_S
|
||||
#define HAVE_STRTOLL
|
||||
#define HAVE_STRTOULL
|
||||
/* #undef HAVE_STRUCT_TM_TM_ZONE */
|
||||
@@ -58,6 +67,6 @@
|
||||
#define HAVE_SHARED
|
||||
/* END DEFINES */
|
||||
#define PACKAGE "libzip"
|
||||
#define VERSION "1.8.0"
|
||||
#define VERSION "1.10.0"
|
||||
|
||||
#endif /* HAD_CONFIG_H */
|
||||
|
||||
@@ -56,8 +56,8 @@ VS_VERSION_INFO$(NDEB64) VERSIONINFO
|
||||
#else
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
#endif
|
||||
FILEVERSION 1,8,0,0
|
||||
PRODUCTVERSION 1,8,0,0
|
||||
FILEVERSION 1,10,0,0
|
||||
PRODUCTVERSION 1,10,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -73,12 +73,12 @@ BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "Libzip Release Version"
|
||||
VALUE "FileVersion", "1.8.0.0"
|
||||
VALUE "FileVersion", "1.10.0.0"
|
||||
VALUE "InternalName", "zipR64.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2021"
|
||||
VALUE "OriginalFilename", "zipR64.dll"
|
||||
VALUE "ProductName", "libzip"
|
||||
VALUE "ProductVersion", "1.8.0.0"
|
||||
VALUE "ProductVersion", "1.10.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
@@ -94,8 +94,8 @@ VS_VERSION_INFO$(NDEB32) VERSIONINFO
|
||||
#else
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
#endif
|
||||
FILEVERSION 1,8,0,0
|
||||
PRODUCTVERSION 1,8,0,0
|
||||
FILEVERSION 1,10,0,0
|
||||
PRODUCTVERSION 1,10,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -111,11 +111,11 @@ BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "Libzip Release Version"
|
||||
VALUE "FileVersion", "1.8.0.0"
|
||||
VALUE "FileVersion", "1.10.0.0"
|
||||
VALUE "InternalName", "zipR32.dll"
|
||||
VALUE "OriginalFilename", "zipR32.dll"
|
||||
VALUE "ProductName", "libzip"
|
||||
VALUE "ProductVersion", "1.8.0.0"
|
||||
VALUE "ProductVersion", "1.10.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
@@ -131,8 +131,8 @@ VS_VERSION_INFO$(_DEB64) VERSIONINFO
|
||||
#else
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
#endif
|
||||
FILEVERSION 1,8,0,0
|
||||
PRODUCTVERSION 1,8,0,0
|
||||
FILEVERSION 1,10,0,0
|
||||
PRODUCTVERSION 1,10,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -148,11 +148,11 @@ BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "Libzip Debug Version"
|
||||
VALUE "FileVersion", "1.8.0.0"
|
||||
VALUE "FileVersion", "1.10.0.0"
|
||||
VALUE "InternalName", "zipD64.dll"
|
||||
VALUE "OriginalFilename", "zipD64.dll"
|
||||
VALUE "ProductName", "libzip"
|
||||
VALUE "ProductVersion", "1.8.0.0"
|
||||
VALUE "ProductVersion", "1.10.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
@@ -168,8 +168,8 @@ VS_VERSION_INFO$(_DEB32) VERSIONINFO
|
||||
#else
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
#endif
|
||||
FILEVERSION 1,8,0,0
|
||||
PRODUCTVERSION 1,8,0,0
|
||||
FILEVERSION 1,10,0,0
|
||||
PRODUCTVERSION 1,10,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -185,11 +185,11 @@ BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "Libzip Debug Version"
|
||||
VALUE "FileVersion", "1.8.0.0"
|
||||
VALUE "FileVersion", "1.10.0.0"
|
||||
VALUE "InternalName", "zipD32.dll"
|
||||
VALUE "OriginalFilename", "zipD32.dll"
|
||||
VALUE "ProductName", "libzip"
|
||||
VALUE "ProductVersion", "1.8.0.0"
|
||||
VALUE "ProductVersion", "1.10.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+8
-8
@@ -104,13 +104,13 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS ; _CRT_NONSTDC_NO_DEPRECATE ; %(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include; Include_x32</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>/EgtDev/Extern/zlib/Lib</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>C:\EgtDev\Extern\zlib\Lib\zlibD32.lib ; kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>zlibD32.lib ; kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG; _DEB32; _USING_V110_SDK71_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
@@ -129,7 +129,7 @@ copy $(TargetPath) \EgtProg\DllD32</Command>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS; _CRT_NONSTDC_NO_DEPRECATE ; %(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include; Include_x32</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include</AdditionalIncludeDirectories>
|
||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
@@ -141,7 +141,7 @@ copy $(TargetPath) \EgtProg\DllD32</Command>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>/EgtDev/Extern/zlib/Lib</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>zlibR32.lib ; kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>zlibR32.lib; kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG; NDEB32; _USING_V110_SDK71_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
@@ -157,8 +157,7 @@ copy $(TargetPath) \EgtProg\Dll32</Command>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS; _CRT_NONSTDC_NO_DEPRECATE ; %(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>
|
||||
</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -184,8 +183,7 @@ copy $(TargetPath) \EgtProg\DllD64</Command>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS; _CRT_NONSTDC_NO_DEPRECATE ; %(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>
|
||||
</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>/EgtDev/Extern/zlib/Include</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
@@ -214,6 +212,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClInclude Include="config_x32.h" />
|
||||
<ClInclude Include="config_x64.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="zip.h" />
|
||||
<ClInclude Include="zipint.h" />
|
||||
<ClInclude Include="zip_crypto.h" />
|
||||
<ClInclude Include="zip_crypto_commoncrypto.h" />
|
||||
@@ -317,6 +316,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
|
||||
<ClCompile Include="zip_source_is_deleted.c" />
|
||||
<ClCompile Include="zip_source_layered.c" />
|
||||
<ClCompile Include="zip_source_open.c" />
|
||||
<ClCompile Include="zip_source_pass_to_lower_layer.c" />
|
||||
<ClCompile Include="zip_source_pkware_decode.c" />
|
||||
<ClCompile Include="zip_source_pkware_encode.c" />
|
||||
<ClCompile Include="zip_source_read.c" />
|
||||
|
||||
@@ -60,6 +60,9 @@
|
||||
<ClInclude Include="config_x64.h">
|
||||
<Filter>File di intestazione</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="zip.h">
|
||||
<Filter>File di intestazione</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="zip_add.c">
|
||||
@@ -419,6 +422,9 @@
|
||||
<ClCompile Include="zip_err_str.c">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="zip_source_pass_to_lower_layer.c">
|
||||
<Filter>File di origine</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="libzip.rc">
|
||||
|
||||
@@ -0,0 +1,513 @@
|
||||
#ifndef _HAD_ZIP_H
|
||||
#define _HAD_ZIP_H
|
||||
|
||||
/*
|
||||
zip.h -- exported declarations.
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
3. The names of the authors may not be used to endorse or promote
|
||||
products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* fix autoindent */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <zipconf.h>
|
||||
|
||||
#ifndef ZIP_EXTERN
|
||||
#ifndef ZIP_STATIC
|
||||
#ifdef _WIN32
|
||||
#define ZIP_EXTERN __declspec(dllimport)
|
||||
#elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define ZIP_EXTERN __attribute__((visibility("default")))
|
||||
#else
|
||||
#define ZIP_EXTERN
|
||||
#endif
|
||||
#else
|
||||
#define ZIP_EXTERN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ZIP_DEPRECATED
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define ZIP_DEPRECATED(x) __attribute__((deprecated(x)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ZIP_DEPRECATED(x) __declspec(deprecated(x))
|
||||
#else
|
||||
#define ZIP_DEPRECATED(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
/* flags for zip_open */
|
||||
|
||||
#define ZIP_CREATE 1
|
||||
#define ZIP_EXCL 2
|
||||
#define ZIP_CHECKCONS 4
|
||||
#define ZIP_TRUNCATE 8
|
||||
#define ZIP_RDONLY 16
|
||||
|
||||
|
||||
/* flags for zip_name_locate, zip_fopen, zip_stat, ... */
|
||||
|
||||
#define ZIP_FL_NOCASE 1u /* ignore case on name lookup */
|
||||
#define ZIP_FL_NODIR 2u /* ignore directory component */
|
||||
#define ZIP_FL_COMPRESSED 4u /* read compressed data */
|
||||
#define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */
|
||||
/* 16u was ZIP_FL_RECOMPRESS, which is deprecated */
|
||||
#define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */
|
||||
#define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */
|
||||
#define ZIP_FL_ENC_RAW 64u /* get unmodified string */
|
||||
#define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */
|
||||
#define ZIP_FL_LOCAL 256u /* in local header */
|
||||
#define ZIP_FL_CENTRAL 512u /* in central directory */
|
||||
/* 1024u reserved for internal use */
|
||||
#define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */
|
||||
#define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */
|
||||
#define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */
|
||||
|
||||
/* archive global flags flags */
|
||||
|
||||
#define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */
|
||||
#define ZIP_AFL_IS_TORRENTZIP 4u /* current archive is torrentzipped */
|
||||
#define ZIP_AFL_WANT_TORRENTZIP 8u /* write archive in torrentzip format */
|
||||
#define ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE 16u /* don't remove file if archive is empty */
|
||||
|
||||
|
||||
/* create a new extra field */
|
||||
|
||||
#define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX
|
||||
#define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX
|
||||
|
||||
|
||||
/* libzip error codes */
|
||||
|
||||
#define ZIP_ER_OK 0 /* N No error */
|
||||
#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
|
||||
#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
|
||||
#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
|
||||
#define ZIP_ER_SEEK 4 /* S Seek error */
|
||||
#define ZIP_ER_READ 5 /* S Read error */
|
||||
#define ZIP_ER_WRITE 6 /* S Write error */
|
||||
#define ZIP_ER_CRC 7 /* N CRC error */
|
||||
#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
|
||||
#define ZIP_ER_NOENT 9 /* N No such file */
|
||||
#define ZIP_ER_EXISTS 10 /* N File already exists */
|
||||
#define ZIP_ER_OPEN 11 /* S Can't open file */
|
||||
#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
|
||||
#define ZIP_ER_ZLIB 13 /* Z Zlib error */
|
||||
#define ZIP_ER_MEMORY 14 /* N Malloc failure */
|
||||
#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
|
||||
#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
|
||||
#define ZIP_ER_EOF 17 /* N Premature end of file */
|
||||
#define ZIP_ER_INVAL 18 /* N Invalid argument */
|
||||
#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
|
||||
#define ZIP_ER_INTERNAL 20 /* N Internal error */
|
||||
#define ZIP_ER_INCONS 21 /* L Zip archive inconsistent */
|
||||
#define ZIP_ER_REMOVE 22 /* S Can't remove file */
|
||||
#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
|
||||
#define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */
|
||||
#define ZIP_ER_RDONLY 25 /* N Read-only archive */
|
||||
#define ZIP_ER_NOPASSWD 26 /* N No password provided */
|
||||
#define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */
|
||||
#define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */
|
||||
#define ZIP_ER_INUSE 29 /* N Resource still in use */
|
||||
#define ZIP_ER_TELL 30 /* S Tell error */
|
||||
#define ZIP_ER_COMPRESSED_DATA 31 /* N Compressed data invalid */
|
||||
#define ZIP_ER_CANCELLED 32 /* N Operation cancelled */
|
||||
#define ZIP_ER_DATA_LENGTH 33 /* N Unexpected length of data */
|
||||
#define ZIP_ER_NOT_ALLOWED 34 /* N Not allowed in torrentzip */
|
||||
|
||||
/* type of system error value */
|
||||
|
||||
#define ZIP_ET_NONE 0 /* sys_err unused */
|
||||
#define ZIP_ET_SYS 1 /* sys_err is errno */
|
||||
#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
|
||||
#define ZIP_ET_LIBZIP 3 /* sys_err is libzip error code */
|
||||
|
||||
/* compression methods */
|
||||
|
||||
#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
|
||||
#define ZIP_CM_STORE 0 /* stored (uncompressed) */
|
||||
#define ZIP_CM_SHRINK 1 /* shrunk */
|
||||
#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
|
||||
#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
|
||||
#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
|
||||
#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
|
||||
#define ZIP_CM_IMPLODE 6 /* imploded */
|
||||
/* 7 - Reserved for Tokenizing compression algorithm */
|
||||
#define ZIP_CM_DEFLATE 8 /* deflated */
|
||||
#define ZIP_CM_DEFLATE64 9 /* deflate64 */
|
||||
#define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
|
||||
/* 11 - Reserved by PKWARE */
|
||||
#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
|
||||
/* 13 - Reserved by PKWARE */
|
||||
#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
|
||||
/* 15-17 - Reserved by PKWARE */
|
||||
#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
|
||||
#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
|
||||
/* 20 - old value for Zstandard */
|
||||
#define ZIP_CM_LZMA2 33
|
||||
#define ZIP_CM_ZSTD 93 /* Zstandard compressed data */
|
||||
#define ZIP_CM_XZ 95 /* XZ compressed data */
|
||||
#define ZIP_CM_JPEG 96 /* Compressed Jpeg data */
|
||||
#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
|
||||
#define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */
|
||||
|
||||
/* encryption methods */
|
||||
|
||||
#define ZIP_EM_NONE 0 /* not encrypted */
|
||||
#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
|
||||
#if 0 /* Strong Encryption Header not parsed yet */
|
||||
#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
|
||||
#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
|
||||
#define ZIP_EM_3DES_168 0x6603
|
||||
#define ZIP_EM_3DES_112 0x6609
|
||||
#define ZIP_EM_PKZIP_AES_128 0x660e
|
||||
#define ZIP_EM_PKZIP_AES_192 0x660f
|
||||
#define ZIP_EM_PKZIP_AES_256 0x6610
|
||||
#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
|
||||
#define ZIP_EM_RC4 0x6801
|
||||
#endif
|
||||
#define ZIP_EM_AES_128 0x0101 /* Winzip AES encryption */
|
||||
#define ZIP_EM_AES_192 0x0102
|
||||
#define ZIP_EM_AES_256 0x0103
|
||||
#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
|
||||
|
||||
#define ZIP_OPSYS_DOS 0x00u
|
||||
#define ZIP_OPSYS_AMIGA 0x01u
|
||||
#define ZIP_OPSYS_OPENVMS 0x02u
|
||||
#define ZIP_OPSYS_UNIX 0x03u
|
||||
#define ZIP_OPSYS_VM_CMS 0x04u
|
||||
#define ZIP_OPSYS_ATARI_ST 0x05u
|
||||
#define ZIP_OPSYS_OS_2 0x06u
|
||||
#define ZIP_OPSYS_MACINTOSH 0x07u
|
||||
#define ZIP_OPSYS_Z_SYSTEM 0x08u
|
||||
#define ZIP_OPSYS_CPM 0x09u
|
||||
#define ZIP_OPSYS_WINDOWS_NTFS 0x0au
|
||||
#define ZIP_OPSYS_MVS 0x0bu
|
||||
#define ZIP_OPSYS_VSE 0x0cu
|
||||
#define ZIP_OPSYS_ACORN_RISC 0x0du
|
||||
#define ZIP_OPSYS_VFAT 0x0eu
|
||||
#define ZIP_OPSYS_ALTERNATE_MVS 0x0fu
|
||||
#define ZIP_OPSYS_BEOS 0x10u
|
||||
#define ZIP_OPSYS_TANDEM 0x11u
|
||||
#define ZIP_OPSYS_OS_400 0x12u
|
||||
#define ZIP_OPSYS_OS_X 0x13u
|
||||
|
||||
#define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX
|
||||
|
||||
|
||||
enum zip_source_cmd {
|
||||
ZIP_SOURCE_OPEN, /* prepare for reading */
|
||||
ZIP_SOURCE_READ, /* read data */
|
||||
ZIP_SOURCE_CLOSE, /* reading is done */
|
||||
ZIP_SOURCE_STAT, /* get meta information */
|
||||
ZIP_SOURCE_ERROR, /* get error information */
|
||||
ZIP_SOURCE_FREE, /* cleanup and free resources */
|
||||
ZIP_SOURCE_SEEK, /* set position for reading */
|
||||
ZIP_SOURCE_TELL, /* get read position */
|
||||
ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */
|
||||
ZIP_SOURCE_COMMIT_WRITE, /* writing is done */
|
||||
ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */
|
||||
ZIP_SOURCE_WRITE, /* write data */
|
||||
ZIP_SOURCE_SEEK_WRITE, /* set position for writing */
|
||||
ZIP_SOURCE_TELL_WRITE, /* get write position */
|
||||
ZIP_SOURCE_SUPPORTS, /* check whether source supports command */
|
||||
ZIP_SOURCE_REMOVE, /* remove file */
|
||||
ZIP_SOURCE_RESERVED_1, /* previously used internally */
|
||||
ZIP_SOURCE_BEGIN_WRITE_CLONING, /* like ZIP_SOURCE_BEGIN_WRITE, but keep part of original file */
|
||||
ZIP_SOURCE_ACCEPT_EMPTY, /* whether empty files are valid archives */
|
||||
ZIP_SOURCE_GET_FILE_ATTRIBUTES, /* get additional file attributes */
|
||||
ZIP_SOURCE_SUPPORTS_REOPEN /* allow reading from changed entry */
|
||||
};
|
||||
typedef enum zip_source_cmd zip_source_cmd_t;
|
||||
|
||||
#define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (((zip_int64_t)1) << (cmd))
|
||||
|
||||
#define ZIP_SOURCE_CHECK_SUPPORTED(supported, cmd) (((supported) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd)) != 0)
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_READABLE (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE))
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_SEEKABLE (ZIP_SOURCE_SUPPORTS_READABLE \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS))
|
||||
|
||||
#define ZIP_SOURCE_SUPPORTS_WRITABLE (ZIP_SOURCE_SUPPORTS_SEEKABLE \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \
|
||||
| ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE))
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
/* for use by sources */
|
||||
struct zip_source_args_seek {
|
||||
zip_int64_t offset;
|
||||
int whence;
|
||||
};
|
||||
|
||||
typedef struct zip_source_args_seek zip_source_args_seek_t;
|
||||
#define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data))
|
||||
|
||||
|
||||
/* error information */
|
||||
/* use zip_error_*() to access */
|
||||
struct zip_error {
|
||||
int zip_err; /* libzip error code (ZIP_ER_*) */
|
||||
int sys_err; /* copy of errno (E*) or zlib error code */
|
||||
char *_Nullable str; /* string representation or NULL */
|
||||
};
|
||||
|
||||
#define ZIP_STAT_NAME 0x0001u
|
||||
#define ZIP_STAT_INDEX 0x0002u
|
||||
#define ZIP_STAT_SIZE 0x0004u
|
||||
#define ZIP_STAT_COMP_SIZE 0x0008u
|
||||
#define ZIP_STAT_MTIME 0x0010u
|
||||
#define ZIP_STAT_CRC 0x0020u
|
||||
#define ZIP_STAT_COMP_METHOD 0x0040u
|
||||
#define ZIP_STAT_ENCRYPTION_METHOD 0x0080u
|
||||
#define ZIP_STAT_FLAGS 0x0100u
|
||||
|
||||
struct zip_stat {
|
||||
zip_uint64_t valid; /* which fields have valid values */
|
||||
const char *_Nullable name; /* name of the file */
|
||||
zip_uint64_t index; /* index within archive */
|
||||
zip_uint64_t size; /* size of file (uncompressed) */
|
||||
zip_uint64_t comp_size; /* size of file (compressed) */
|
||||
time_t mtime; /* modification time */
|
||||
zip_uint32_t crc; /* crc of file data */
|
||||
zip_uint16_t comp_method; /* compression method used */
|
||||
zip_uint16_t encryption_method; /* encryption method used */
|
||||
zip_uint32_t flags; /* reserved for future use */
|
||||
};
|
||||
|
||||
struct zip_buffer_fragment {
|
||||
zip_uint8_t *_Nonnull data;
|
||||
zip_uint64_t length;
|
||||
};
|
||||
|
||||
struct zip_file_attributes {
|
||||
zip_uint64_t valid; /* which fields have valid values */
|
||||
zip_uint8_t version; /* version of this struct, currently 1 */
|
||||
zip_uint8_t host_system; /* host system on which file was created */
|
||||
zip_uint8_t ascii; /* flag whether file is ASCII text */
|
||||
zip_uint8_t version_needed; /* minimum version needed to extract file */
|
||||
zip_uint32_t external_file_attributes; /* external file attributes (host-system specific) */
|
||||
zip_uint16_t general_purpose_bit_flags; /* general purpose big flags, only some bits are honored */
|
||||
zip_uint16_t general_purpose_bit_mask; /* which bits in general_purpose_bit_flags are valid */
|
||||
};
|
||||
|
||||
#define ZIP_FILE_ATTRIBUTES_HOST_SYSTEM 0x0001u
|
||||
#define ZIP_FILE_ATTRIBUTES_ASCII 0x0002u
|
||||
#define ZIP_FILE_ATTRIBUTES_VERSION_NEEDED 0x0004u
|
||||
#define ZIP_FILE_ATTRIBUTES_EXTERNAL_FILE_ATTRIBUTES 0x0008u
|
||||
#define ZIP_FILE_ATTRIBUTES_GENERAL_PURPOSE_BIT_FLAGS 0x0010u
|
||||
|
||||
struct zip;
|
||||
struct zip_file;
|
||||
struct zip_source;
|
||||
|
||||
typedef struct zip zip_t;
|
||||
typedef struct zip_error zip_error_t;
|
||||
typedef struct zip_file zip_file_t;
|
||||
typedef struct zip_file_attributes zip_file_attributes_t;
|
||||
typedef struct zip_source zip_source_t;
|
||||
typedef struct zip_stat zip_stat_t;
|
||||
typedef struct zip_buffer_fragment zip_buffer_fragment_t;
|
||||
|
||||
typedef zip_uint32_t zip_flags_t;
|
||||
|
||||
typedef zip_int64_t (*zip_source_callback)(void *_Nullable, void *_Nullable, zip_uint64_t, zip_source_cmd_t);
|
||||
typedef zip_int64_t (*zip_source_layered_callback)(zip_source_t *_Nonnull, void *_Nullable, void *_Nullable, zip_uint64_t, enum zip_source_cmd);
|
||||
typedef void (*zip_progress_callback)(zip_t *_Nonnull, double, void *_Nullable);
|
||||
typedef int (*zip_cancel_callback)(zip_t *_Nonnull, void *_Nullable);
|
||||
|
||||
#ifndef ZIP_DISABLE_DEPRECATED
|
||||
#define ZIP_FL_RECOMPRESS 16u /* force recompression of data */
|
||||
|
||||
typedef void (*zip_progress_callback_t)(double);
|
||||
ZIP_DEPRECATED("use 'zip_register_progress_callback_with_state' instead") ZIP_EXTERN void zip_register_progress_callback(zip_t *_Nonnull, zip_progress_callback_t _Nullable);
|
||||
|
||||
ZIP_DEPRECATED("use 'zip_file_add' instead") ZIP_EXTERN zip_int64_t zip_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull);
|
||||
ZIP_DEPRECATED("use 'zip_dir_add' instead") ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *_Nonnull, const char *_Nonnull);
|
||||
ZIP_DEPRECATED("use 'zip_file_get_comment' instead") ZIP_EXTERN const char *_Nullable zip_get_file_comment(zip_t *_Nonnull, zip_uint64_t, int *_Nullable, int);
|
||||
ZIP_DEPRECATED("use 'zip_get_num_entries' instead") ZIP_EXTERN int zip_get_num_files(zip_t *_Nonnull);
|
||||
ZIP_DEPRECATED("use 'zip_file_rename' instead") ZIP_EXTERN int zip_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull);
|
||||
ZIP_DEPRECATED("use 'zip_file_replace' instead") ZIP_EXTERN int zip_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull);
|
||||
ZIP_DEPRECATED("use 'zip_file_set_comment' instead") ZIP_EXTERN int zip_set_file_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, int);
|
||||
ZIP_DEPRECATED("use 'zip_error_init_with_code' and 'zip_error_system_type' instead") ZIP_EXTERN int zip_error_get_sys_type(int);
|
||||
ZIP_DEPRECATED("use 'zip_get_error' instead") ZIP_EXTERN void zip_error_get(zip_t *_Nonnull, int *_Nullable, int *_Nullable);
|
||||
ZIP_DEPRECATED("use 'zip_error_strerror' instead") ZIP_EXTERN int zip_error_to_str(char *_Nonnull, zip_uint64_t, int, int);
|
||||
ZIP_DEPRECATED("use 'zip_file_get_error' instead") ZIP_EXTERN void zip_file_error_get(zip_file_t *_Nonnull, int *_Nullable, int *_Nullable);
|
||||
ZIP_DEPRECATED("use 'zip_source_zip_file' instead") ZIP_EXTERN zip_source_t *_Nullable zip_source_zip(zip_t *_Nonnull, zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t);
|
||||
ZIP_DEPRECATED("use 'zip_source_zip_file_create' instead") ZIP_EXTERN zip_source_t *_Nullable zip_source_zip_create(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
#endif
|
||||
|
||||
ZIP_EXTERN int zip_close(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_delete(zip_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_int64_t zip_dir_add(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN void zip_discard(zip_t *_Nonnull);
|
||||
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_get_error(zip_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_clear(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_code_zip(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_code_system(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_error_init_with_code(zip_error_t *_Nonnull, int);
|
||||
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int);
|
||||
ZIP_EXTERN void zip_error_set_from_source(zip_error_t *_Nonnull, zip_source_t *_Nullable);
|
||||
ZIP_EXTERN const char *_Nonnull zip_error_strerror(zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_error_system_type(const zip_error_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_error_to_data(const zip_error_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
|
||||
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_fdopen(int, int, int *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_file_add(zip_t *_Nonnull, const char *_Nonnull, zip_source_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN void zip_file_attributes_init(zip_file_attributes_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_file_error_clear(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_file_extra_field_delete(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_extra_field_delete_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_extra_field_set(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, const zip_uint8_t *_Nullable, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_uint16_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN const zip_uint8_t *_Nullable zip_file_extra_field_get_by_id(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_uint16_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nullable zip_file_get_comment(zip_t *_Nonnull, zip_uint64_t, zip_uint32_t *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_file_get_error(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_file_get_external_attributes(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint8_t *_Nullable, zip_uint32_t *_Nullable);
|
||||
ZIP_EXTERN int zip_file_is_seekable(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_file_rename(zip_t *_Nonnull, zip_uint64_t, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_replace(zip_t *_Nonnull, zip_uint64_t, zip_source_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_comment(zip_t *_Nonnull, zip_uint64_t, const char *_Nullable, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_dostime(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t);
|
||||
ZIP_EXTERN int zip_file_set_encryption(zip_t *_Nonnull, zip_uint64_t, zip_uint16_t, const char *_Nullable);
|
||||
ZIP_EXTERN int zip_file_set_external_attributes(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint8_t, zip_uint32_t);
|
||||
ZIP_EXTERN int zip_file_set_mtime(zip_t *_Nonnull, zip_uint64_t, time_t, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nonnull zip_file_strerror(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_encrypted(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t, const char *_Nullable);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index_encrypted(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, const char *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_int8_t zip_fseek(zip_file_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN zip_int64_t zip_ftell(zip_file_t *_Nonnull);
|
||||
ZIP_EXTERN const char *_Nullable zip_get_archive_comment(zip_t *_Nonnull, int *_Nullable, zip_flags_t);
|
||||
ZIP_EXTERN int zip_get_archive_flag(zip_t *_Nonnull, zip_flags_t, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nullable zip_get_name(zip_t *_Nonnull, zip_uint64_t, zip_flags_t);
|
||||
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN const char *_Nonnull zip_libzip_version(void);
|
||||
ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable);
|
||||
ZIP_EXTERN zip_t *_Nullable zip_open_from_source(zip_source_t *_Nonnull, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t *_Nonnull, double, zip_progress_callback _Nullable, void (*_Nullable)(void *_Nullable), void *_Nullable);
|
||||
ZIP_EXTERN int zip_register_cancel_callback_with_state(zip_t *_Nonnull, zip_cancel_callback _Nullable, void (*_Nullable)(void *_Nullable), void *_Nullable);
|
||||
ZIP_EXTERN int zip_set_archive_comment(zip_t *_Nonnull, const char *_Nullable, zip_uint16_t);
|
||||
ZIP_EXTERN int zip_set_archive_flag(zip_t *_Nonnull, zip_flags_t, int);
|
||||
ZIP_EXTERN int zip_set_default_password(zip_t *_Nonnull, const char *_Nullable);
|
||||
ZIP_EXTERN int zip_set_file_compression(zip_t *_Nonnull, zip_uint64_t, zip_int32_t, zip_uint32_t);
|
||||
ZIP_EXTERN int zip_source_begin_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_begin_write_cloning(zip_source_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer(zip_t *_Nonnull, const void *_Nullable, zip_uint64_t, int);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_create(const void *_Nullable, zip_uint64_t, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_fragment(zip_t *_Nonnull, const zip_buffer_fragment_t *_Nonnull, zip_uint64_t, int);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_fragment_create(const zip_buffer_fragment_t *_Nullable, zip_uint64_t, int, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_close(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_commit_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_error_t *_Nonnull zip_source_error(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_file(zip_t *_Nonnull, const char *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_file_create(const char *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep(zip_t *_Nonnull, FILE *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_filep_create(FILE *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_function(zip_t *_Nonnull, zip_source_callback _Nonnull, void *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_function_create(zip_source_callback _Nonnull, void *_Nullable, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_get_file_attributes(zip_source_t *_Nonnull, zip_file_attributes_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_is_deleted(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_is_seekable(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_source_keep(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_layered(zip_t *_Nullable, zip_source_t *_Nonnull, zip_source_layered_callback _Nonnull, void *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_layered_create(zip_source_t *_Nonnull, zip_source_layered_callback _Nonnull, void *_Nullable, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t, ...);
|
||||
ZIP_EXTERN int zip_source_open(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_pass_to_lower_layer(zip_source_t *_Nonnull, void *_Nullable, zip_uint64_t, zip_source_cmd_t);
|
||||
ZIP_EXTERN zip_int64_t zip_source_read(zip_source_t *_Nonnull, void *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN void zip_source_rollback_write(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_source_seek(zip_source_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN zip_int64_t zip_source_seek_compute_offset(zip_uint64_t, zip_uint64_t, void *_Nonnull, zip_uint64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_source_seek_write(zip_source_t *_Nonnull, zip_int64_t, int);
|
||||
ZIP_EXTERN int zip_source_stat(zip_source_t *_Nonnull, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *_Nonnull);
|
||||
ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *_Nonnull);
|
||||
#ifdef _WIN32
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32a(zip_t *_Nonnull, const char *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32a_create(const char *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32handle(zip_t *_Nonnull, void *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32handle_create(void *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32w(zip_t *_Nonnull, const wchar_t *_Nonnull, zip_uint64_t, zip_int64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_win32w_create(const wchar_t *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
#endif
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_window_create(zip_source_t *_Nonnull, zip_uint64_t, zip_int64_t, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *_Nonnull, const void *_Nullable, zip_uint64_t);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_zip_file(zip_t *_Nonnull, zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t, const char *_Nullable);
|
||||
ZIP_EXTERN zip_source_t *_Nullable zip_source_zip_file_create(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t, const char *_Nullable, zip_error_t *_Nullable);
|
||||
ZIP_EXTERN int zip_stat(zip_t *_Nonnull, const char *_Nonnull, zip_flags_t, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_stat_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t, zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN void zip_stat_init(zip_stat_t *_Nonnull);
|
||||
ZIP_EXTERN const char *_Nonnull zip_strerror(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_unchange(zip_t *_Nonnull, zip_uint64_t);
|
||||
ZIP_EXTERN int zip_unchange_all(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_unchange_archive(zip_t *_Nonnull);
|
||||
ZIP_EXTERN int zip_compression_method_supported(zip_int32_t method, int compress);
|
||||
ZIP_EXTERN int zip_encryption_method_supported(zip_uint16_t method, int encode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HAD_ZIP_H */
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+24
-13
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -40,7 +40,8 @@
|
||||
struct ctx {
|
||||
zip_error_t *error;
|
||||
bool compress;
|
||||
int compression_flags;
|
||||
int level;
|
||||
int mem_level;
|
||||
bool end_of_input;
|
||||
z_stream zstr;
|
||||
};
|
||||
@@ -60,7 +61,7 @@ maximum_compressed_size(zip_uint64_t uncompressed_size) {
|
||||
|
||||
|
||||
static void *
|
||||
allocate(bool compress, int compression_flags, zip_error_t *error) {
|
||||
allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
struct ctx *ctx;
|
||||
|
||||
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
|
||||
@@ -70,10 +71,13 @@ allocate(bool compress, int compression_flags, zip_error_t *error) {
|
||||
|
||||
ctx->error = error;
|
||||
ctx->compress = compress;
|
||||
ctx->compression_flags = compression_flags;
|
||||
if (ctx->compression_flags < 1 || ctx->compression_flags > 9) {
|
||||
ctx->compression_flags = Z_BEST_COMPRESSION;
|
||||
if (compression_flags >= 1 && compression_flags <= 9) {
|
||||
ctx->level = (int)compression_flags;
|
||||
}
|
||||
else {
|
||||
ctx->level = Z_BEST_COMPRESSION;
|
||||
}
|
||||
ctx->mem_level = compression_flags == TORRENTZIP_COMPRESSION_FLAGS ? TORRENTZIP_MEM_LEVEL : MAX_MEM_LEVEL;
|
||||
ctx->end_of_input = false;
|
||||
|
||||
ctx->zstr.zalloc = Z_NULL;
|
||||
@@ -85,13 +89,15 @@ allocate(bool compress, int compression_flags, zip_error_t *error) {
|
||||
|
||||
|
||||
static void *
|
||||
compress_allocate(zip_uint16_t method, int compression_flags, zip_error_t *error) {
|
||||
compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(true, compression_flags, error);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
decompress_allocate(zip_uint16_t method, int compression_flags, zip_error_t *error) {
|
||||
decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
|
||||
(void)method;
|
||||
return allocate(false, compression_flags, error);
|
||||
}
|
||||
|
||||
@@ -112,10 +118,10 @@ general_purpose_bit_flags(void *ud) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->compression_flags < 3) {
|
||||
if (ctx->level < 3) {
|
||||
return 2 << 1;
|
||||
}
|
||||
else if (ctx->compression_flags > 7) {
|
||||
else if (ctx->level > 7) {
|
||||
return 1 << 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -127,6 +133,9 @@ start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
int ret;
|
||||
|
||||
(void)st;
|
||||
(void)attributes;
|
||||
|
||||
ctx->zstr.avail_in = 0;
|
||||
ctx->zstr.next_in = NULL;
|
||||
ctx->zstr.avail_out = 0;
|
||||
@@ -134,7 +143,7 @@ start(void *ud, zip_stat_t *st, zip_file_attributes_t *attributes) {
|
||||
|
||||
if (ctx->compress) {
|
||||
/* negative value to tell zlib not to write a header */
|
||||
ret = deflateInit2(&ctx->zstr, ctx->compression_flags, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
|
||||
ret = deflateInit2(&ctx->zstr, ctx->level, Z_DEFLATED, -MAX_WBITS, ctx->mem_level, Z_DEFAULT_STRATEGY);
|
||||
}
|
||||
else {
|
||||
ret = inflateInit2(&ctx->zstr, -MAX_WBITS);
|
||||
@@ -198,10 +207,12 @@ end_of_input(void *ud) {
|
||||
static zip_compression_status_t
|
||||
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
struct ctx *ctx = (struct ctx *)ud;
|
||||
uInt avail_out;
|
||||
|
||||
int ret;
|
||||
|
||||
ctx->zstr.avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
|
||||
avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
|
||||
ctx->zstr.avail_out = avail_out;
|
||||
ctx->zstr.next_out = (Bytef *)data;
|
||||
|
||||
if (ctx->compress) {
|
||||
@@ -211,7 +222,7 @@ process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
|
||||
ret = inflate(&ctx->zstr, Z_SYNC_FLUSH);
|
||||
}
|
||||
|
||||
*length = *length - ctx->zstr.avail_out;
|
||||
*length = avail_out - ctx->zstr.avail_out;
|
||||
|
||||
switch (ret) {
|
||||
case Z_OK:
|
||||
|
||||
+18
-5
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2014-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -132,13 +132,20 @@ _zip_buffer_left(zip_buffer_t *buffer) {
|
||||
|
||||
zip_uint64_t
|
||||
_zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
|
||||
zip_uint64_t copied;
|
||||
|
||||
if (_zip_buffer_left(buffer) < length) {
|
||||
length = _zip_buffer_left(buffer);
|
||||
}
|
||||
|
||||
memcpy(data, _zip_buffer_get(buffer, length), length);
|
||||
copied = 0;
|
||||
while (copied < length) {
|
||||
size_t n = ZIP_MIN(length - copied, SIZE_MAX);
|
||||
(void)memcpy_s(data + copied, n, _zip_buffer_get(buffer, n), n);
|
||||
copied += n;
|
||||
}
|
||||
|
||||
return length;
|
||||
return copied;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +154,14 @@ _zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) {
|
||||
bool free_data = (data == NULL);
|
||||
zip_buffer_t *buffer;
|
||||
|
||||
#if ZIP_UINT64_MAX > SIZE_MAX
|
||||
if (size > SIZE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data == NULL) {
|
||||
if ((data = (zip_uint8_t *)malloc(size)) == NULL) {
|
||||
if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -221,7 +234,7 @@ _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(dst, src, length);
|
||||
(void)memcpy_s(dst, length, src, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+77
-35
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_close.c -- close zip archive and update changes
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 1999-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -45,6 +45,7 @@
|
||||
static int add_data(zip_t *, zip_source_t *, zip_dirent_t *, zip_uint32_t);
|
||||
static int copy_data(zip_t *, zip_uint64_t);
|
||||
static int copy_source(zip_t *, zip_source_t *, zip_int64_t);
|
||||
static int torrentzip_compare_names(const void *a, const void *b);
|
||||
static int write_cdir(zip_t *, const zip_filelist_t *, zip_uint64_t);
|
||||
static int write_data_descriptor(zip_t *za, const zip_dirent_t *dirent, int is_zip64);
|
||||
|
||||
@@ -61,12 +62,12 @@ zip_close(zip_t *za) {
|
||||
|
||||
changed = _zip_changed(za, &survivors);
|
||||
|
||||
/* don't create zip files with no entries */
|
||||
if (survivors == 0) {
|
||||
if (survivors == 0 && !(za->ch_flags & ZIP_AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE)) {
|
||||
/* don't create zip files with no entries */
|
||||
if ((za->open_flags & ZIP_TRUNCATE) || changed) {
|
||||
if (zip_source_remove(za->src) < 0) {
|
||||
if (!((zip_error_code_zip(zip_source_error(za->src)) == ZIP_ER_REMOVE) && (zip_error_code_system(zip_source_error(za->src)) == ENOENT))) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -75,7 +76,8 @@ zip_close(zip_t *za) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
/* Always write empty archive if we are told to keep it, otherwise it wouldn't be created if the file doesn't already exist. */
|
||||
if (!changed && survivors > 0) {
|
||||
zip_discard(za);
|
||||
return 0;
|
||||
}
|
||||
@@ -105,6 +107,7 @@ zip_close(zip_t *za) {
|
||||
}
|
||||
|
||||
filelist[j].idx = i;
|
||||
filelist[j].name = zip_get_name(za, i, 0);
|
||||
j++;
|
||||
}
|
||||
if (j < survivors) {
|
||||
@@ -113,7 +116,11 @@ zip_close(zip_t *za) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
qsort(filelist, (size_t)survivors, sizeof(filelist[0]), torrentzip_compare_names);
|
||||
}
|
||||
|
||||
if (ZIP_WANT_TORRENTZIP(za) || (zip_source_supports(za->src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE_CLONING)) == 0) {
|
||||
unchanged_offset = 0;
|
||||
}
|
||||
else {
|
||||
@@ -146,7 +153,7 @@ zip_close(zip_t *za) {
|
||||
}
|
||||
if (unchanged_offset == 0) {
|
||||
if (zip_source_begin_write(za->src) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
free(filelist);
|
||||
return -1;
|
||||
}
|
||||
@@ -178,7 +185,7 @@ zip_close(zip_t *za) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD));
|
||||
new_data = (ZIP_ENTRY_DATA_CHANGED(entry) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_COMP_METHOD) || ZIP_ENTRY_CHANGED(entry, ZIP_DIRENT_ENCRYPTION_METHOD)) || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za));
|
||||
|
||||
/* create new local directory entry */
|
||||
if (entry->changes == NULL) {
|
||||
@@ -195,8 +202,12 @@ zip_close(zip_t *za) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_dirent_torrentzip_normalize(entry->changes);
|
||||
}
|
||||
|
||||
if ((off = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -207,7 +218,7 @@ zip_close(zip_t *za) {
|
||||
|
||||
zs = NULL;
|
||||
if (!ZIP_ENTRY_DATA_CHANGED(entry)) {
|
||||
if ((zs = _zip_source_zip_new(za, i, ZIP_FL_UNCHANGED, 0, 0, NULL, &za->error)) == NULL) {
|
||||
if ((zs = zip_source_zip_file_create(za, i, ZIP_FL_UNCHANGED, 0, -1, NULL, &za->error)) == NULL) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -240,7 +251,7 @@ zip_close(zip_t *za) {
|
||||
break;
|
||||
}
|
||||
if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -267,7 +278,7 @@ zip_close(zip_t *za) {
|
||||
|
||||
if (!error) {
|
||||
if (zip_source_commit_write(za->src) != 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
error = 1;
|
||||
}
|
||||
_zip_progress_end(za->progress);
|
||||
@@ -296,7 +307,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
bool needs_recompress, needs_decompress, needs_crc, needs_compress, needs_reencrypt, needs_decrypt, needs_encrypt;
|
||||
|
||||
if (zip_source_stat(src, &st) < 0) {
|
||||
_zip_error_set_from_source(&za->error, src);
|
||||
zip_error_set_from_source(&za->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -324,6 +335,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
flags = ZIP_EF_LOCAL;
|
||||
|
||||
if ((st.valid & ZIP_STAT_SIZE) == 0) {
|
||||
/* TODO: not valid for torrentzip */
|
||||
flags |= ZIP_FL_FORCE_ZIP64;
|
||||
data_length = -1;
|
||||
}
|
||||
@@ -350,6 +362,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
}
|
||||
|
||||
if (max_compressed_size > 0xffffffffu) {
|
||||
/* TODO: not valid for torrentzip */
|
||||
flags |= ZIP_FL_FORCE_ZIP64;
|
||||
}
|
||||
}
|
||||
@@ -360,7 +373,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
}
|
||||
|
||||
if ((offstart = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -370,7 +383,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
needs_recompress = st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
|
||||
needs_recompress = ZIP_WANT_TORRENTZIP(za) || st.comp_method != ZIP_CM_ACTUAL(de->comp_method);
|
||||
needs_decompress = needs_recompress && (st.comp_method != ZIP_CM_STORE);
|
||||
/* in these cases we can compute the CRC ourselves, so we do */
|
||||
needs_crc = (st.comp_method == ZIP_CM_STORE) || needs_decompress;
|
||||
@@ -397,7 +410,6 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
zip_source_free(src_final);
|
||||
src_final = src_tmp;
|
||||
}
|
||||
|
||||
@@ -407,7 +419,6 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
zip_source_free(src_final);
|
||||
src_final = src_tmp;
|
||||
}
|
||||
|
||||
@@ -417,7 +428,6 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
zip_source_free(src_final);
|
||||
src_final = src_tmp;
|
||||
}
|
||||
|
||||
@@ -427,7 +437,6 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
zip_source_free(src_final);
|
||||
src_final = src_tmp;
|
||||
}
|
||||
|
||||
@@ -448,34 +457,48 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
zip_source_free(src_final);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (de->encryption_method == ZIP_EM_TRAD_PKWARE) {
|
||||
de->bitflags |= ZIP_GPBF_DATA_DESCRIPTOR;
|
||||
|
||||
/* PKWare encryption uses last_mod, make sure it gets the right value. */
|
||||
if (de->changed & ZIP_DIRENT_LAST_MOD) {
|
||||
zip_stat_t st_mtime;
|
||||
zip_stat_init(&st_mtime);
|
||||
st_mtime.valid = ZIP_STAT_MTIME;
|
||||
st_mtime.mtime = de->last_mod;
|
||||
if ((src_tmp = _zip_source_window_new(src_final, 0, -1, &st_mtime, 0, NULL, NULL, 0, true, &za->error)) == NULL) {
|
||||
zip_source_free(src_final);
|
||||
return -1;
|
||||
}
|
||||
src_final = src_tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ((src_tmp = impl(za, src_final, de->encryption_method, ZIP_CODEC_ENCODE, password)) == NULL) {
|
||||
/* error set by impl */
|
||||
zip_source_free(src_final);
|
||||
return -1;
|
||||
}
|
||||
if (de->encryption_method == ZIP_EM_TRAD_PKWARE) {
|
||||
de->bitflags |= ZIP_GPBF_DATA_DESCRIPTOR;
|
||||
}
|
||||
|
||||
zip_source_free(src_final);
|
||||
src_final = src_tmp;
|
||||
}
|
||||
|
||||
|
||||
if ((offdata = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = copy_source(za, src_final, data_length);
|
||||
|
||||
if (zip_source_stat(src_final, &st) < 0) {
|
||||
_zip_error_set_from_source(&za->error, src_final);
|
||||
zip_error_set_from_source(&za->error, src_final);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (zip_source_get_file_attributes(src_final, &attributes) != 0) {
|
||||
_zip_error_set_from_source(&za->error, src_final);
|
||||
zip_error_set_from_source(&za->error, src_final);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@@ -486,12 +509,12 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
}
|
||||
|
||||
if ((offend = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (zip_source_seek_write(za->src, offstart, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -512,6 +535,10 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
de->comp_size = (zip_uint64_t)(offend - offdata);
|
||||
_zip_dirent_apply_attributes(de, &attributes, (flags & ZIP_FL_FORCE_ZIP64) != 0, changed);
|
||||
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_dirent_torrentzip_normalize(de);
|
||||
}
|
||||
|
||||
if ((ret = _zip_dirent_write(za, de, flags)) < 0)
|
||||
return -1;
|
||||
|
||||
@@ -522,7 +549,7 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
}
|
||||
|
||||
if (zip_source_seek_write(za->src, offend, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -539,7 +566,6 @@ add_data(zip_t *za, zip_source_t *src, zip_dirent_t *de, zip_uint32_t changed) {
|
||||
static int
|
||||
copy_data(zip_t *za, zip_uint64_t len) {
|
||||
DEFINE_BYTE_ARRAY(buf, BUFSIZE);
|
||||
size_t n;
|
||||
double total = (double)len;
|
||||
|
||||
if (!byte_array_init(buf, BUFSIZE)) {
|
||||
@@ -548,7 +574,8 @@ copy_data(zip_t *za, zip_uint64_t len) {
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
n = len > BUFSIZE ? BUFSIZE : len;
|
||||
zip_uint64_t n = ZIP_MIN(len, BUFSIZE);
|
||||
|
||||
if (_zip_read(za->src, buf, n, &za->error) < 0) {
|
||||
byte_array_fini(buf);
|
||||
return -1;
|
||||
@@ -579,7 +606,7 @@ copy_source(zip_t *za, zip_source_t *src, zip_int64_t data_length) {
|
||||
int ret;
|
||||
|
||||
if (zip_source_open(src) < 0) {
|
||||
_zip_error_set_from_source(&za->error, src);
|
||||
zip_error_set_from_source(&za->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -606,7 +633,7 @@ copy_source(zip_t *za, zip_source_t *src, zip_int64_t data_length) {
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
_zip_error_set_from_source(&za->error, src);
|
||||
zip_error_set_from_source(&za->error, src);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@@ -643,7 +670,7 @@ _zip_changed(const zip_t *za, zip_uint64_t *survivorsp) {
|
||||
changed = 0;
|
||||
survivors = 0;
|
||||
|
||||
if (za->comment_changed || za->ch_flags != za->flags) {
|
||||
if (za->comment_changed || (ZIP_WANT_TORRENTZIP(za) && !ZIP_IS_TORRENTZIP(za))) {
|
||||
changed = 1;
|
||||
}
|
||||
|
||||
@@ -696,3 +723,18 @@ write_data_descriptor(zip_t *za, const zip_dirent_t *de, int is_zip64) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int torrentzip_compare_names(const void *a, const void *b) {
|
||||
const char *aname = ((const zip_filelist_t *)a)->name;
|
||||
const char *bname = ((const zip_filelist_t *)b)->name;
|
||||
|
||||
if (aname == NULL) {
|
||||
return (bname != NULL) * -1;
|
||||
}
|
||||
else if (bname == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strcasecmp(aname, bname);
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+22
-5
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -36,17 +36,34 @@
|
||||
|
||||
#define HAVE_SECURE_RANDOM
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
#define _zip_crypto_aes_t AES_KEY
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x02070000fL)
|
||||
#define USE_OPENSSL_1_0_API
|
||||
#elif OPENSSL_VERSION_NUMBER < 0x3000000fL
|
||||
#define USE_OPENSSL_1_1_API
|
||||
#else
|
||||
#define USE_OPENSSL_3_API
|
||||
#endif
|
||||
|
||||
#define _zip_crypto_aes_t EVP_CIPHER_CTX
|
||||
#ifdef USE_OPENSSL_3_API
|
||||
struct _zip_crypto_hmac_t {
|
||||
EVP_MAC *mac;
|
||||
EVP_MAC_CTX *ctx;
|
||||
};
|
||||
typedef struct _zip_crypto_hmac_t _zip_crypto_hmac_t;
|
||||
#define _zip_crypto_hmac(hmac, data, length) (EVP_MAC_update((hmac->ctx), (data), (length)) == 1)
|
||||
#else
|
||||
#define _zip_crypto_hmac_t HMAC_CTX
|
||||
#define _zip_crypto_hmac(hmac, data, length) (HMAC_Update((hmac), (data), (length)) == 1)
|
||||
#endif
|
||||
|
||||
void _zip_crypto_aes_free(_zip_crypto_aes_t *aes);
|
||||
#define _zip_crypto_aes_encrypt_block(aes, in, out) (AES_encrypt((in), (out), (aes)), true)
|
||||
bool _zip_crypto_aes_encrypt_block(_zip_crypto_aes_t *aes, const zip_uint8_t *in, zip_uint8_t *out);
|
||||
_zip_crypto_aes_t *_zip_crypto_aes_new(const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error);
|
||||
|
||||
#define _zip_crypto_hmac(hmac, data, length) (HMAC_Update((hmac), (data), (length)) == 1)
|
||||
void _zip_crypto_hmac_free(_zip_crypto_hmac_t *hmac);
|
||||
_zip_crypto_hmac_t *_zip_crypto_hmac_new(const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error);
|
||||
bool _zip_crypto_hmac_output(_zip_crypto_hmac_t *hmac, zip_uint8_t *data);
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -254,7 +254,7 @@ pbkdf2(PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, DWORD c
|
||||
for (j = 0; j < cIterations; j++) {
|
||||
if (j == 0) {
|
||||
/* construct first input for PRF */
|
||||
memcpy(U, pbSalt, cbSalt);
|
||||
(void)memcpy_s(U, cbSalt, pbSalt, cbSalt);
|
||||
U[cbSalt] = (BYTE)((i & 0xFF000000) >> 24);
|
||||
U[cbSalt + 1] = (BYTE)((i & 0x00FF0000) >> 16);
|
||||
U[cbSalt + 2] = (BYTE)((i & 0x0000FF00) >> 8);
|
||||
@@ -262,7 +262,7 @@ pbkdf2(PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, DWORD c
|
||||
dwULen = cbSalt + 4;
|
||||
}
|
||||
else {
|
||||
memcpy(U, V, DIGEST_SIZE);
|
||||
(void)memcpy_s(U, DIGEST_SIZE, V, DIGEST_SIZE);
|
||||
dwULen = DIGEST_SIZE;
|
||||
}
|
||||
|
||||
@@ -274,11 +274,11 @@ pbkdf2(PUCHAR pbPassword, ULONG cbPassword, PUCHAR pbSalt, ULONG cbSalt, DWORD c
|
||||
}
|
||||
|
||||
if (i != l) {
|
||||
memcpy(&pbDerivedKey[(i - 1) * DIGEST_SIZE], Ti, DIGEST_SIZE);
|
||||
(void)memcpy_s(&pbDerivedKey[(i - 1) * DIGEST_SIZE], cbDerivedKey - (i - 1) * DIGEST_SIZE, Ti, DIGEST_SIZE);
|
||||
}
|
||||
else {
|
||||
/* Take only the first r bytes */
|
||||
memcpy(&pbDerivedKey[(i - 1) * DIGEST_SIZE], Ti, r);
|
||||
(void)memcpy_s(&pbDerivedKey[(i - 1) * DIGEST_SIZE], cbDerivedKey - (i - 1) * DIGEST_SIZE, Ti, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -61,11 +61,11 @@ zip_dir_add(zip_t *za, const char *name, zip_flags_t flags) {
|
||||
len = strlen(name);
|
||||
|
||||
if (name[len - 1] != '/') {
|
||||
if ((s = (char *)malloc(len + 2)) == NULL) {
|
||||
if (len > SIZE_MAX - 2 || (s = (char *)malloc(len + 2)) == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
||||
return -1;
|
||||
}
|
||||
strcpy(s, name);
|
||||
(void)strncpy_s(s, len + 2, name, len);
|
||||
s[len] = '/';
|
||||
s[len + 1] = '\0';
|
||||
}
|
||||
|
||||
+140
-96
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
@@ -127,15 +128,21 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor
|
||||
zip_uint64_t i;
|
||||
bool is_zip64;
|
||||
int ret;
|
||||
zip_uint32_t cdir_crc;
|
||||
|
||||
if ((off = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
offset = (zip_uint64_t)off;
|
||||
|
||||
is_zip64 = false;
|
||||
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
cdir_crc = (zip_uint32_t)crc32(0, NULL, 0);
|
||||
za->write_crc = &cdir_crc;
|
||||
}
|
||||
|
||||
for (i = 0; i < survivors; i++) {
|
||||
zip_entry_t *entry = za->entry + filelist[i].idx;
|
||||
|
||||
@@ -145,15 +152,17 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor
|
||||
is_zip64 = true;
|
||||
}
|
||||
|
||||
za->write_crc = NULL;
|
||||
|
||||
if ((off = zip_source_tell_write(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
size = (zip_uint64_t)off - offset;
|
||||
|
||||
if (offset > ZIP_UINT32_MAX || survivors > ZIP_UINT16_MAX)
|
||||
if (offset > ZIP_UINT32_MAX || survivors > ZIP_UINT16_MAX) {
|
||||
is_zip64 = true;
|
||||
|
||||
}
|
||||
|
||||
if ((buffer = _zip_buffer_new(buf, sizeof(buf))) == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
||||
@@ -186,7 +195,13 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor
|
||||
|
||||
comment = za->comment_changed ? za->comment_changes : za->comment_orig;
|
||||
|
||||
_zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
_zip_buffer_put_16(buffer, TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH);
|
||||
}
|
||||
else {
|
||||
_zip_buffer_put_16(buffer, (zip_uint16_t)(comment ? comment->length : 0));
|
||||
}
|
||||
|
||||
|
||||
if (!_zip_buffer_ok(buffer)) {
|
||||
zip_error_set(&za->error, ZIP_ER_INTERNAL, 0);
|
||||
@@ -201,7 +216,15 @@ _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivor
|
||||
|
||||
_zip_buffer_free(buffer);
|
||||
|
||||
if (comment) {
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
char torrentzip_comment[TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH + 1];
|
||||
snprintf(torrentzip_comment, sizeof(torrentzip_comment), TORRENTZIP_SIGNATURE "%08X", cdir_crc);
|
||||
|
||||
if (_zip_write(za, torrentzip_comment, strlen(torrentzip_comment)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (comment != NULL) {
|
||||
if (_zip_write(za, comment->raw, comment->length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -219,7 +242,7 @@ _zip_dirent_clone(const zip_dirent_t *sde) {
|
||||
return NULL;
|
||||
|
||||
if (sde)
|
||||
memcpy(tde, sde, sizeof(*sde));
|
||||
(void)memcpy_s(tde, sizeof(*tde), sde, sizeof(*sde));
|
||||
else
|
||||
_zip_dirent_init(tde);
|
||||
|
||||
@@ -503,76 +526,18 @@ _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, boo
|
||||
|
||||
if (zde->uncomp_size == ZIP_UINT32_MAX || zde->comp_size == ZIP_UINT32_MAX || zde->offset == ZIP_UINT32_MAX) {
|
||||
zip_uint16_t got_len;
|
||||
zip_buffer_t *ef_buffer;
|
||||
const zip_uint8_t *ef = _zip_ef_get_by_id(zde->extra_fields, &got_len, ZIP_EF_ZIP64, 0, local ? ZIP_EF_LOCAL : ZIP_EF_CENTRAL, error);
|
||||
/* TODO: if got_len == 0 && !ZIP64_EOCD: no error, 0xffffffff is valid value */
|
||||
if (ef == NULL) {
|
||||
if (!from_buffer) {
|
||||
_zip_buffer_free(buffer);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
if (!from_buffer) {
|
||||
_zip_buffer_free(buffer);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (zde->uncomp_size == ZIP_UINT32_MAX) {
|
||||
zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
else if (local) {
|
||||
/* From appnote.txt: This entry in the Local header MUST
|
||||
include BOTH original and compressed file size fields. */
|
||||
(void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
|
||||
}
|
||||
if (zde->comp_size == ZIP_UINT32_MAX) {
|
||||
zde->comp_size = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
if (!local) {
|
||||
if (zde->offset == ZIP_UINT32_MAX) {
|
||||
zde->offset = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
if (zde->disk_number == ZIP_UINT16_MAX) {
|
||||
zde->disk_number = _zip_buffer_get_32(ef_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_zip_buffer_eof(ef_buffer)) {
|
||||
/* accept additional fields if values match */
|
||||
bool ok = true;
|
||||
switch (got_len) {
|
||||
case 28:
|
||||
_zip_buffer_set_offset(ef_buffer, 24);
|
||||
if (zde->disk_number != _zip_buffer_get_32(ef_buffer)) {
|
||||
ok = false;
|
||||
}
|
||||
/* fallthrough */
|
||||
case 24:
|
||||
_zip_buffer_set_offset(ef_buffer, 0);
|
||||
if ((zde->uncomp_size != _zip_buffer_get_64(ef_buffer)) || (zde->comp_size != _zip_buffer_get_64(ef_buffer)) || (zde->offset != _zip_buffer_get_64(ef_buffer))) {
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) {
|
||||
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
|
||||
_zip_buffer_free(ef_buffer);
|
||||
if (ef != NULL) {
|
||||
if (!zip_dirent_process_ef_zip64(zde, ef, got_len, local, error)) {
|
||||
if (!from_buffer) {
|
||||
_zip_buffer_free(buffer);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
_zip_buffer_free(ef_buffer);
|
||||
}
|
||||
|
||||
|
||||
if (!_zip_buffer_ok(buffer)) {
|
||||
zip_error_set(error, ZIP_ER_INTERNAL, 0);
|
||||
if (!from_buffer) {
|
||||
@@ -599,6 +564,65 @@ _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, boo
|
||||
return (zip_int64_t)size + (zip_int64_t)variable_size;
|
||||
}
|
||||
|
||||
bool zip_dirent_process_ef_zip64(zip_dirent_t* zde, const zip_uint8_t* ef, zip_uint64_t got_len, bool local, zip_error_t* error) {
|
||||
zip_buffer_t *ef_buffer;
|
||||
|
||||
if ((ef_buffer = _zip_buffer_new((zip_uint8_t *)ef, got_len)) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zde->uncomp_size == ZIP_UINT32_MAX) {
|
||||
zde->uncomp_size = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
else if (local) {
|
||||
/* From appnote.txt: This entry in the Local header MUST
|
||||
include BOTH original and compressed file size fields. */
|
||||
(void)_zip_buffer_skip(ef_buffer, 8); /* error is caught by _zip_buffer_eof() call */
|
||||
}
|
||||
if (zde->comp_size == ZIP_UINT32_MAX) {
|
||||
zde->comp_size = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
if (!local) {
|
||||
if (zde->offset == ZIP_UINT32_MAX) {
|
||||
zde->offset = _zip_buffer_get_64(ef_buffer);
|
||||
}
|
||||
if (zde->disk_number == ZIP_UINT16_MAX) {
|
||||
zde->disk_number = _zip_buffer_get_32(ef_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_zip_buffer_eof(ef_buffer)) {
|
||||
/* accept additional fields if values match */
|
||||
bool ok = true;
|
||||
switch (got_len) {
|
||||
case 28:
|
||||
_zip_buffer_set_offset(ef_buffer, 24);
|
||||
if (zde->disk_number != _zip_buffer_get_32(ef_buffer)) {
|
||||
ok = false;
|
||||
}
|
||||
/* fallthrough */
|
||||
case 24:
|
||||
_zip_buffer_set_offset(ef_buffer, 0);
|
||||
if ((zde->uncomp_size != _zip_buffer_get_64(ef_buffer)) || (zde->comp_size != _zip_buffer_get_64(ef_buffer)) || (zde->offset != _zip_buffer_get_64(ef_buffer))) {
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ok = false;
|
||||
}
|
||||
if (!ok) {
|
||||
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_INVALID_ZIP64_EF);
|
||||
_zip_buffer_free(ef_buffer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_zip_buffer_free(ef_buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static zip_string_t *
|
||||
_zip_dirent_process_ef_utf_8(const zip_dirent_t *de, zip_uint16_t id, zip_string_t *str) {
|
||||
@@ -664,19 +688,18 @@ _zip_dirent_process_winzip_aes(zip_dirent_t *de, zip_error_t *error) {
|
||||
|
||||
crc_valid = true;
|
||||
switch (_zip_buffer_get_16(buffer)) {
|
||||
case 1:
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (de->uncomp_size < 20 /* TODO: constant */) {
|
||||
case 2:
|
||||
crc_valid = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
|
||||
_zip_buffer_free(buffer);
|
||||
return false;
|
||||
/* TODO: When checking consistency, check that crc is 0. */
|
||||
break;
|
||||
|
||||
default:
|
||||
zip_error_set(error, ZIP_ER_ENCRNOTSUPP, 0);
|
||||
_zip_buffer_free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* vendor */
|
||||
@@ -729,7 +752,7 @@ _zip_dirent_size(zip_source_t *src, zip_uint16_t flags, zip_error_t *error) {
|
||||
size = local ? LENTRYSIZE : CDENTRYSIZE;
|
||||
|
||||
if (zip_source_seek(src, local ? 26 : 28, SEEK_CUR) < 0) {
|
||||
_zip_error_set_from_source(error, src);
|
||||
zip_error_set_from_source(error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -902,7 +925,13 @@ _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
|
||||
_zip_buffer_put_16(buffer, (zip_uint16_t)de->comp_method);
|
||||
}
|
||||
|
||||
_zip_u2d_time(de->last_mod, &dostime, &dosdate);
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
dostime = 0xbc00;
|
||||
dosdate = 0x2198;
|
||||
}
|
||||
else {
|
||||
_zip_u2d_time(de->last_mod, &dostime, &dosdate);
|
||||
}
|
||||
_zip_buffer_put_16(buffer, dostime);
|
||||
_zip_buffer_put_16(buffer, dosdate);
|
||||
|
||||
@@ -938,12 +967,15 @@ _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
|
||||
}
|
||||
|
||||
_zip_buffer_put_16(buffer, _zip_string_length(de->filename));
|
||||
/* TODO: check for overflow */
|
||||
ef_total_size = (zip_uint32_t)_zip_ef_size(de->extra_fields, flags) + (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH);
|
||||
ef_total_size = (zip_uint32_t)_zip_ef_size(ef, ZIP_EF_BOTH);
|
||||
if (!ZIP_WANT_TORRENTZIP(za)) {
|
||||
/* TODO: check for overflow */
|
||||
ef_total_size += (zip_uint32_t)_zip_ef_size(de->extra_fields, flags);
|
||||
}
|
||||
_zip_buffer_put_16(buffer, (zip_uint16_t)ef_total_size);
|
||||
|
||||
if ((flags & ZIP_FL_LOCAL) == 0) {
|
||||
_zip_buffer_put_16(buffer, _zip_string_length(de->comment));
|
||||
_zip_buffer_put_16(buffer, ZIP_WANT_TORRENTZIP(za) ? 0 : _zip_string_length(de->comment));
|
||||
_zip_buffer_put_16(buffer, (zip_uint16_t)de->disk_number);
|
||||
_zip_buffer_put_16(buffer, de->int_attrib);
|
||||
_zip_buffer_put_32(buffer, de->ext_attrib);
|
||||
@@ -982,13 +1014,13 @@ _zip_dirent_write(zip_t *za, zip_dirent_t *de, zip_flags_t flags) {
|
||||
}
|
||||
}
|
||||
_zip_ef_free(ef);
|
||||
if (de->extra_fields) {
|
||||
if (de->extra_fields && !ZIP_WANT_TORRENTZIP(za)) {
|
||||
if (_zip_ef_write(za, de->extra_fields, flags) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & ZIP_FL_LOCAL) == 0) {
|
||||
if ((flags & ZIP_FL_LOCAL) == 0 && !ZIP_WANT_TORRENTZIP(za)) {
|
||||
if (de->comment) {
|
||||
if (_zip_string_write(za, de->comment) < 0) {
|
||||
return -1;
|
||||
@@ -1090,15 +1122,10 @@ _zip_get_dirent(zip_t *za, zip_uint64_t idx, zip_flags_t flags, zip_error_t *err
|
||||
void
|
||||
_zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate) {
|
||||
struct tm *tpm;
|
||||
|
||||
#ifdef HAVE_LOCALTIME_R
|
||||
struct tm tm;
|
||||
tpm = localtime_r(&intime, &tm);
|
||||
#else
|
||||
tpm = localtime(&intime);
|
||||
#endif
|
||||
tpm = zip_localtime(&intime, &tm);
|
||||
if (tpm == NULL) {
|
||||
/* if localtime() fails, return an arbitrary date (1980-01-01 00:00:00) */
|
||||
/* if localtime fails, return an arbitrary date (1980-01-01 00:00:00) */
|
||||
*ddate = (1 << 5) + 1;
|
||||
*dtime = 0;
|
||||
return;
|
||||
@@ -1109,8 +1136,6 @@ _zip_u2d_time(time_t intime, zip_uint16_t *dtime, zip_uint16_t *ddate) {
|
||||
|
||||
*ddate = (zip_uint16_t)(((tpm->tm_year + 1900 - 1980) << 9) + ((tpm->tm_mon + 1) << 5) + tpm->tm_mday);
|
||||
*dtime = (zip_uint16_t)(((tpm->tm_hour) << 11) + ((tpm->tm_min) << 5) + ((tpm->tm_sec) >> 1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1161,3 +1186,22 @@ _zip_dirent_apply_attributes(zip_dirent_t *de, zip_file_attributes_t *attributes
|
||||
de->version_madeby = (de->version_madeby & 0xff) | (zip_uint16_t)(attributes->host_system << 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* _zip_dirent_torrent_normalize(de);
|
||||
Set values suitable for torrentzip.
|
||||
*/
|
||||
|
||||
void zip_dirent_torrentzip_normalize(zip_dirent_t *de) {
|
||||
de->version_madeby = 0;
|
||||
de->version_needed = 20; /* 2.0 */
|
||||
de->bitflags = 2; /* maximum compression */
|
||||
de->comp_method = ZIP_CM_DEFLATE;
|
||||
de->compression_level = TORRENTZIP_COMPRESSION_FLAGS;
|
||||
de->disk_number = 0;
|
||||
de->int_attrib = 0;
|
||||
de->ext_attrib = 0;
|
||||
|
||||
/* last_mod, extra_fields, and comment are normalized in zip_dirent_write() directly */
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+7
-2
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -132,7 +132,12 @@ zip_error_set(zip_error_t *err, int ze, int se) {
|
||||
|
||||
|
||||
void
|
||||
_zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
|
||||
zip_error_set_from_source(zip_error_t *err, zip_source_t *src) {
|
||||
if (src == NULL) {
|
||||
zip_error_set(err, ZIP_ER_INVAL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
_zip_error_copy(err, zip_source_error(src));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+35
-15
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -42,23 +42,29 @@
|
||||
ZIP_EXTERN const char *
|
||||
zip_error_strerror(zip_error_t *err) {
|
||||
const char *zip_error_string, *system_error_string;
|
||||
char buf[128], *s;
|
||||
char *s;
|
||||
char *system_error_buffer = NULL;
|
||||
|
||||
zip_error_fini(err);
|
||||
|
||||
if (err->zip_err < 0 || err->zip_err >= _zip_err_str_count) {
|
||||
snprintf(buf, sizeof(buf), "Unknown error %d", err->zip_err);
|
||||
buf[sizeof(buf) - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
system_error_buffer = (char *)malloc(128);
|
||||
snprintf_s(system_error_buffer, 128, "Unknown error %d", err->zip_err);
|
||||
system_error_buffer[128 - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
zip_error_string = NULL;
|
||||
system_error_string = buf;
|
||||
system_error_string = system_error_buffer;
|
||||
}
|
||||
else {
|
||||
zip_error_string = _zip_err_str[err->zip_err].description;
|
||||
|
||||
switch (_zip_err_str[err->zip_err].type) {
|
||||
case ZIP_ET_SYS:
|
||||
system_error_string = strerror(err->sys_err);
|
||||
case ZIP_ET_SYS: {
|
||||
size_t len = strerrorlen_s(err->sys_err) + 1;
|
||||
system_error_buffer = malloc(len);
|
||||
strerror_s(system_error_buffer, len, err->sys_err);
|
||||
system_error_string = system_error_buffer;
|
||||
break;
|
||||
}
|
||||
|
||||
case ZIP_ET_ZLIB:
|
||||
system_error_string = zError(err->sys_err);
|
||||
@@ -72,14 +78,16 @@ zip_error_strerror(zip_error_t *err) {
|
||||
system_error_string = NULL;
|
||||
}
|
||||
else if (error >= _zip_err_details_count) {
|
||||
snprintf(buf, sizeof(buf), "invalid detail error %u", error);
|
||||
buf[sizeof(buf) - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
system_error_string = buf;
|
||||
system_error_buffer = (char *)malloc(128);
|
||||
snprintf_s(system_error_buffer, 128, "invalid detail error %u", error);
|
||||
system_error_buffer[128 - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
system_error_string = system_error_buffer;
|
||||
}
|
||||
else if (_zip_err_details[error].type == ZIP_DETAIL_ET_ENTRY && index < MAX_DETAIL_INDEX) {
|
||||
snprintf(buf, sizeof(buf), "entry %d: %s", index, _zip_err_details[error].description);
|
||||
buf[sizeof(buf) - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
system_error_string = buf;
|
||||
system_error_buffer = (char *)malloc(128);
|
||||
snprintf_s(system_error_buffer, 128, "entry %d: %s", index, _zip_err_details[error].description);
|
||||
system_error_buffer[128 - 1] = '\0'; /* make sure string is NUL-terminated */
|
||||
system_error_string = system_error_buffer;
|
||||
}
|
||||
else {
|
||||
system_error_string = _zip_err_details[error].description;
|
||||
@@ -93,16 +101,28 @@ zip_error_strerror(zip_error_t *err) {
|
||||
}
|
||||
|
||||
if (system_error_string == NULL) {
|
||||
free(system_error_buffer);
|
||||
return zip_error_string;
|
||||
}
|
||||
else {
|
||||
if ((s = (char *)malloc(strlen(system_error_string) + (zip_error_string ? strlen(zip_error_string) + 2 : 0) + 1)) == NULL) {
|
||||
size_t length = strlen(system_error_string);
|
||||
if (zip_error_string) {
|
||||
size_t length_error = strlen(zip_error_string);
|
||||
if (length + length_error + 2 < length) {
|
||||
free(system_error_buffer);
|
||||
return _zip_err_str[ZIP_ER_MEMORY].description;
|
||||
}
|
||||
length += length_error + 2;
|
||||
}
|
||||
if (length == SIZE_MAX || (s = (char *)malloc(length + 1)) == NULL) {
|
||||
free(system_error_buffer);
|
||||
return _zip_err_str[ZIP_ER_MEMORY].description;
|
||||
}
|
||||
|
||||
sprintf(s, "%s%s%s", (zip_error_string ? zip_error_string : ""), (zip_error_string ? ": " : ""), system_error_string);
|
||||
snprintf_s(s, length + 1, "%s%s%s", (zip_error_string ? zip_error_string : ""), (zip_error_string ? ": " : ""), system_error_string);
|
||||
err->str = s;
|
||||
|
||||
free(system_error_buffer);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-20
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define _ZIP_COMPILING_DEPRECATED
|
||||
#include "zipint.h"
|
||||
@@ -42,26 +41,18 @@
|
||||
|
||||
ZIP_EXTERN int
|
||||
zip_error_to_str(char *buf, zip_uint64_t len, int ze, int se) {
|
||||
const char *zs, *ss;
|
||||
zip_error_t error;
|
||||
const char *error_string;
|
||||
int ret;
|
||||
|
||||
if (ze < 0 || ze >= _zip_err_str_count) {
|
||||
return snprintf(buf, len, "Unknown error %d", ze);
|
||||
}
|
||||
zip_error_init(&error);
|
||||
zip_error_set(&error, ze, se);
|
||||
|
||||
zs = _zip_err_str[ze].description;
|
||||
error_string = zip_error_strerror(&error);
|
||||
|
||||
switch (_zip_err_str[ze].type) {
|
||||
case ZIP_ET_SYS:
|
||||
ss = strerror(se);
|
||||
break;
|
||||
|
||||
case ZIP_ET_ZLIB:
|
||||
ss = zError(se);
|
||||
break;
|
||||
|
||||
default:
|
||||
ss = NULL;
|
||||
}
|
||||
ret = snprintf_s(buf, ZIP_MIN(len, SIZE_MAX), error_string, strlen(error_string));
|
||||
|
||||
return snprintf(buf, len, "%s%s%s", zs, (ss ? ": " : ""), (ss ? ss : ""));
|
||||
zip_error_fini(&error);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
+4
-3
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2012-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -243,10 +243,11 @@ _zip_ef_parse(const zip_uint8_t *data, zip_uint16_t len, zip_flags_t flags, zip_
|
||||
if (!_zip_buffer_eof(buffer)) {
|
||||
/* Android APK files align stored file data with padding in extra fields; ignore. */
|
||||
/* see https://android.googlesource.com/platform/build/+/master/tools/zipalign/ZipAlign.cpp */
|
||||
/* buffer is at most 64k long, so this can't overflow. */
|
||||
size_t glen = _zip_buffer_left(buffer);
|
||||
zip_uint8_t *garbage;
|
||||
garbage = _zip_buffer_get(buffer, glen);
|
||||
if (glen >= 4 || garbage == NULL || memcmp(garbage, "\0\0\0", glen) != 0) {
|
||||
if (glen >= 4 || garbage == NULL || memcmp(garbage, "\0\0\0", (size_t)glen) != 0) {
|
||||
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_EF_TRAILING_GARBAGE);
|
||||
_zip_buffer_free(buffer);
|
||||
_zip_ef_free(ef_head);
|
||||
@@ -370,7 +371,7 @@ _zip_read_local_ef(zip_t *za, zip_uint64_t idx) {
|
||||
}
|
||||
|
||||
if (zip_source_seek(za->src, (zip_int64_t)(e->orig->offset + 26), SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2012-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -56,6 +56,10 @@ zip_file_extra_field_delete(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_idx, zi
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
|
||||
return -1;
|
||||
@@ -88,6 +92,10 @@ zip_file_extra_field_delete_by_id(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_i
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_zip_file_extra_field_prepare_for_change(za, idx) < 0)
|
||||
return -1;
|
||||
@@ -236,6 +244,10 @@ zip_file_extra_field_set(zip_t *za, zip_uint64_t idx, zip_uint16_t ef_id, zip_ui
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ZIP_EF_IS_INTERNAL(ef_id)) {
|
||||
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+6
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -51,6 +51,10 @@ zip_fdopen(int fd_orig, int _flags, int *zep) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_FDOPEN
|
||||
_zip_set_open_error(zep, NULL, ZIP_ER_OPNOTSUPP);
|
||||
return NULL;
|
||||
#else
|
||||
/* We dup() here to avoid messing with the passed in fd.
|
||||
We could not restore it to the original state in case of error. */
|
||||
|
||||
@@ -83,4 +87,5 @@ zip_fdopen(int fd_orig, int _flags, int *zep) {
|
||||
zip_error_fini(&error);
|
||||
close(fd_orig);
|
||||
return za;
|
||||
#endif
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2013-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -57,7 +57,7 @@ _zip_file_get_offset(const zip_t *za, zip_uint64_t idx, zip_error_t *error) {
|
||||
offset = za->entry[idx].orig->offset;
|
||||
|
||||
if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -93,11 +93,11 @@ _zip_file_get_end(const zip_t *za, zip_uint64_t index, zip_error_t *error) {
|
||||
if (entry->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
|
||||
zip_uint8_t buf[4];
|
||||
if (zip_source_seek(za->src, (zip_int64_t)offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
return 0;
|
||||
}
|
||||
if (zip_source_read(za->src, buf, 4) != 4) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(buf, DATADES_MAGIC, 4) == 0) {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -50,6 +50,10 @@ zip_file_set_comment(zip_t *za, zip_uint64_t idx, const char *comment, zip_uint1
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len > 0 && comment == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2016-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -51,6 +51,10 @@ zip_file_set_encryption(zip_t *za, zip_uint64_t idx, zip_uint16_t method, const
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (method != ZIP_EM_NONE && _zip_get_encryption_implementation(method, ZIP_CODEC_ENCODE) == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_ENCRNOTSUPP, 0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2013-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -47,6 +47,10 @@ zip_file_set_external_attributes(zip_t *za, zip_uint64_t idx, zip_flags_t flags,
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
e = za->entry + idx;
|
||||
|
||||
|
||||
+11
-2
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_file_set_mtime.c -- set modification time of entry.
|
||||
Copyright (C) 2014-2020 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 2014-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -51,9 +51,18 @@ zip_file_set_mtime(zip_t *za, zip_uint64_t idx, time_t mtime, zip_flags_t flags)
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
e = za->entry + idx;
|
||||
|
||||
if (e->orig != NULL && e->orig->encryption_method == ZIP_EM_TRAD_PKWARE && !ZIP_ENTRY_CHANGED(e, ZIP_DIRENT_ENCRYPTION_METHOD) && !ZIP_ENTRY_DATA_CHANGED(e)) {
|
||||
zip_error_set(&za->error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (e->changes == NULL) {
|
||||
if ((e->changes = _zip_dirent_clone(e->orig)) == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -49,11 +49,11 @@ zip_fopen_index_encrypted(zip_t *za, zip_uint64_t index, zip_flags_t flags, cons
|
||||
password = NULL;
|
||||
}
|
||||
|
||||
if ((src = _zip_source_zip_new(za, index, flags, 0, 0, password, &za->error)) == NULL)
|
||||
if ((src = zip_source_zip_file_create(za, index, flags, 0, -1, password, &za->error)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (zip_source_open(src) < 0) {
|
||||
_zip_error_set_from_source(&za->error, src);
|
||||
zip_error_set_from_source(&za->error, src);
|
||||
zip_source_free(src);
|
||||
return NULL;
|
||||
}
|
||||
@@ -78,9 +78,7 @@ _zip_file_new(zip_t *za) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zf->za = za;
|
||||
zip_error_init(&zf->error);
|
||||
zf->eof = 0;
|
||||
zf->src = NULL;
|
||||
|
||||
return zf;
|
||||
|
||||
+4
-3
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -50,11 +50,12 @@ zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((zf->eof) || (toread == 0))
|
||||
if (toread == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((n = zip_source_read(zf->src, outbuf, toread)) < 0) {
|
||||
_zip_error_set_from_source(&zf->error, zf->src);
|
||||
zip_error_set_from_source(&zf->error, zf->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2016-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -43,9 +43,19 @@ zip_fseek(zip_file_t *zf, zip_int64_t offset, int whence) {
|
||||
return -1;
|
||||
|
||||
if (zip_source_seek(zf->src, offset, whence) < 0) {
|
||||
_zip_error_set_from_source(&zf->error, zf->src);
|
||||
zip_error_set_from_source(&zf->error, zf->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ZIP_EXTERN int
|
||||
zip_file_is_seekable(zip_file_t *zfile) {
|
||||
if (!zfile) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return zip_source_is_seekable(zfile->src);
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2016-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -46,7 +46,7 @@ zip_ftell(zip_file_t *zf) {
|
||||
|
||||
res = zip_source_tell(zf->src);
|
||||
if (res < 0) {
|
||||
_zip_error_set_from_source(&zf->error, zf->src);
|
||||
zip_error_set_from_source(&zf->error, zf->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2008-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2015-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+16
-4
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -31,8 +31,10 @@
|
||||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "zipint.h"
|
||||
|
||||
@@ -46,7 +48,7 @@ _zip_read(zip_source_t *src, zip_uint8_t *b, zip_uint64_t length, zip_error_t *e
|
||||
}
|
||||
|
||||
if ((n = zip_source_read(src, b, length)) < 0) {
|
||||
_zip_error_set_from_source(error, src);
|
||||
zip_error_set_from_source(error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ _zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp
|
||||
free(r);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(r, data, length);
|
||||
(void)memcpy_s(r, length, data, length);
|
||||
}
|
||||
else {
|
||||
if (_zip_read(src, r, length, error) < 0) {
|
||||
@@ -122,7 +124,7 @@ _zip_write(zip_t *za, const void *data, zip_uint64_t length) {
|
||||
zip_int64_t n;
|
||||
|
||||
if ((n = zip_source_write(za->src, data, length)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return -1;
|
||||
}
|
||||
if ((zip_uint64_t)n != length) {
|
||||
@@ -130,5 +132,15 @@ _zip_write(zip_t *za, const void *data, zip_uint64_t length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (za->write_crc != NULL) {
|
||||
zip_uint64_t position = 0;
|
||||
while (position < length) {
|
||||
zip_uint64_t nn = ZIP_MIN(UINT_MAX, length - position);
|
||||
|
||||
*za->write_crc = (zip_uint32_t)crc32(*za->write_crc, (const Bytef *)data + position, (uInt)nn);
|
||||
position += nn;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -50,7 +50,7 @@ _zip_memdup(const void *mem, size_t len, zip_error_t *error) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(ret, mem, len);
|
||||
(void)memcpy_s(ret, len, mem, len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
+29
-5
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_name_locate.c -- get index by name
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 1999-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -49,18 +49,38 @@ zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags) {
|
||||
zip_int64_t
|
||||
_zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *error) {
|
||||
int (*cmp)(const char *, const char *);
|
||||
size_t fname_length;
|
||||
zip_string_t *str = NULL;
|
||||
const char *fn, *p;
|
||||
zip_uint64_t i;
|
||||
|
||||
if (za == NULL)
|
||||
if (za == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fname == NULL) {
|
||||
zip_error_set(error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_CP437)) {
|
||||
fname_length = strlen(fname);
|
||||
|
||||
if (fname_length > ZIP_UINT16_MAX) {
|
||||
zip_error_set(error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flags & (ZIP_FL_ENC_UTF_8 | ZIP_FL_ENC_RAW)) == 0 && fname[0] != '\0') {
|
||||
if ((str = _zip_string_new((const zip_uint8_t *)fname, (zip_uint16_t)strlen(fname), flags, error)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if ((fname = (const char *)_zip_string_get(str, NULL, 0, error)) == NULL) {
|
||||
_zip_string_free(str);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & (ZIP_FL_NOCASE | ZIP_FL_NODIR | ZIP_FL_ENC_RAW | ZIP_FL_ENC_STRICT)) {
|
||||
/* can't use hash table */
|
||||
cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
|
||||
|
||||
@@ -79,14 +99,18 @@ _zip_name_locate(zip_t *za, const char *fname, zip_flags_t flags, zip_error_t *e
|
||||
|
||||
if (cmp(fname, fn) == 0) {
|
||||
_zip_error_clear(error);
|
||||
_zip_string_free(str);
|
||||
return (zip_int64_t)i;
|
||||
}
|
||||
}
|
||||
|
||||
zip_error_set(error, ZIP_ER_NOENT, 0);
|
||||
_zip_string_free(str);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return _zip_hash_lookup(za->names, (const zip_uint8_t *)fname, flags, error);
|
||||
zip_int64_t ret = _zip_hash_lookup(za->names, (const zip_uint8_t *)fname, flags, error);
|
||||
_zip_string_free(str);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+139
-33
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_open.c -- open zip archive by name
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 1999-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -41,10 +42,11 @@
|
||||
typedef enum { EXISTS_ERROR = -1, EXISTS_NOT = 0, EXISTS_OK } exists_t;
|
||||
static zip_t *_zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error);
|
||||
static zip_int64_t _zip_checkcons(zip_t *za, zip_cdir_t *cdir, zip_error_t *error);
|
||||
static void zip_check_torrentzip(zip_t *za, const zip_cdir_t *cdir);
|
||||
static zip_cdir_t *_zip_find_central_dir(zip_t *za, zip_uint64_t len);
|
||||
static exists_t _zip_file_exists(zip_source_t *src, zip_error_t *error);
|
||||
static int _zip_headercomp(const zip_dirent_t *, const zip_dirent_t *);
|
||||
static unsigned char *_zip_memmem(const unsigned char *, size_t, const unsigned char *, size_t);
|
||||
static const unsigned char *_zip_memmem(const unsigned char *, size_t, const unsigned char *, size_t);
|
||||
static zip_cdir_t *_zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_error_t *error);
|
||||
static zip_cdir_t *_zip_read_eocd(zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error);
|
||||
static zip_cdir_t *_zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offset, unsigned int flags, zip_error_t *error);
|
||||
@@ -77,9 +79,6 @@ zip_open(const char *fn, int _flags, int *zep) {
|
||||
|
||||
ZIP_EXTERN zip_t *
|
||||
zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
|
||||
static zip_int64_t needed_support_read = -1;
|
||||
static zip_int64_t needed_support_write = -1;
|
||||
|
||||
unsigned int flags;
|
||||
zip_int64_t supported;
|
||||
exists_t exists;
|
||||
@@ -91,15 +90,11 @@ zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
|
||||
flags = (unsigned int)_flags;
|
||||
|
||||
supported = zip_source_supports(src);
|
||||
if (needed_support_read == -1) {
|
||||
needed_support_read = zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_STAT, -1);
|
||||
needed_support_write = zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, -1);
|
||||
}
|
||||
if ((supported & needed_support_read) != needed_support_read) {
|
||||
if ((supported & ZIP_SOURCE_SUPPORTS_SEEKABLE) != ZIP_SOURCE_SUPPORTS_SEEKABLE) {
|
||||
zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return NULL;
|
||||
}
|
||||
if ((supported & needed_support_write) != needed_support_write) {
|
||||
if ((supported & ZIP_SOURCE_SUPPORTS_WRITABLE) != ZIP_SOURCE_SUPPORTS_WRITABLE) {
|
||||
flags |= ZIP_RDONLY;
|
||||
}
|
||||
|
||||
@@ -127,7 +122,7 @@ zip_open_from_source(zip_source_t *src, int _flags, zip_error_t *error) {
|
||||
return NULL;
|
||||
}
|
||||
if (zip_source_open(src) < 0) {
|
||||
_zip_error_set_from_source(error, src);
|
||||
zip_error_set_from_source(error, src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -158,7 +153,7 @@ _zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) {
|
||||
|
||||
zip_stat_init(&st);
|
||||
if (zip_source_stat(src, &st) < 0) {
|
||||
_zip_error_set_from_source(error, src);
|
||||
zip_error_set_from_source(error, src);
|
||||
return NULL;
|
||||
}
|
||||
if ((st.valid & ZIP_STAT_SIZE) == 0) {
|
||||
@@ -188,7 +183,16 @@ _zip_open(zip_source_t *src, unsigned int flags, zip_error_t *error) {
|
||||
za->entry = cdir->entry;
|
||||
za->nentry = cdir->nentry;
|
||||
za->nentry_alloc = cdir->nentry_alloc;
|
||||
za->comment_orig = cdir->comment;
|
||||
|
||||
zip_check_torrentzip(za, cdir);
|
||||
|
||||
if (ZIP_IS_TORRENTZIP(za)) {
|
||||
/* Torrentzip uses the archive comment to detect changes by tools that are not torrentzip aware. */
|
||||
_zip_string_free(cdir->comment);
|
||||
}
|
||||
else {
|
||||
za->comment_orig = cdir->comment;
|
||||
}
|
||||
|
||||
free(cdir);
|
||||
|
||||
@@ -328,7 +332,7 @@ _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_err
|
||||
cd_buffer = NULL;
|
||||
|
||||
if (zip_source_seek(za->src, (zip_int64_t)cd->offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
_zip_cdir_free(cd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -395,7 +399,7 @@ _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_offset, zip_err
|
||||
zip_int64_t offset = zip_source_tell(za->src);
|
||||
|
||||
if (offset < 0) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
_zip_cdir_free(cd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -452,7 +456,7 @@ _zip_checkcons(zip_t *za, zip_cdir_t *cd, zip_error_t *error) {
|
||||
}
|
||||
|
||||
if (zip_source_seek(za->src, (zip_int64_t)cd->entry[i].orig->offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(error, za->src);
|
||||
zip_error_set_from_source(error, za->src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -498,9 +502,20 @@ _zip_headercomp(const zip_dirent_t *central, const zip_dirent_t *local) {
|
||||
|
||||
if ((central->crc != local->crc) || (central->comp_size != local->comp_size) || (central->uncomp_size != local->uncomp_size)) {
|
||||
/* InfoZip stores valid values in local header even when data descriptor is used.
|
||||
This is in violation of the appnote. */
|
||||
if (((local->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local->crc != 0 || local->comp_size != 0 || local->uncomp_size != 0))
|
||||
This is in violation of the appnote.
|
||||
macOS Archive sets the compressed size even when data descriptor is used ( but not the others),
|
||||
also in violation of the appnote.
|
||||
*/
|
||||
/* if data descriptor is not used, the values must match */
|
||||
if ((local->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0) {
|
||||
return -1;
|
||||
}
|
||||
/* when using a data descriptor, the local header value must be zero or match */
|
||||
if ((local->crc != 0 && central->crc != local->crc) ||
|
||||
(local->comp_size != 0 && central->comp_size != local->comp_size) ||
|
||||
(local->uncomp_size != 0 && central->uncomp_size != local->uncomp_size)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -517,10 +532,15 @@ _zip_allocate_new(zip_source_t *src, unsigned int flags, zip_error_t *error) {
|
||||
|
||||
za->src = src;
|
||||
za->open_flags = flags;
|
||||
za->flags = 0;
|
||||
za->ch_flags = 0;
|
||||
za->write_crc = NULL;
|
||||
|
||||
if (flags & ZIP_RDONLY) {
|
||||
za->flags |= ZIP_AFL_RDONLY;
|
||||
za->ch_flags |= ZIP_AFL_RDONLY;
|
||||
}
|
||||
|
||||
return za;
|
||||
}
|
||||
|
||||
@@ -549,7 +569,7 @@ _zip_file_exists(zip_source_t *src, zip_error_t *error) {
|
||||
static zip_cdir_t *
|
||||
_zip_find_central_dir(zip_t *za, zip_uint64_t len) {
|
||||
zip_cdir_t *cdir, *cdirnew;
|
||||
zip_uint8_t *match;
|
||||
const zip_uint8_t *match;
|
||||
zip_int64_t buf_offset;
|
||||
zip_uint64_t buflen;
|
||||
zip_int64_t a;
|
||||
@@ -572,7 +592,7 @@ _zip_find_central_dir(zip_t *za, zip_uint64_t len) {
|
||||
}
|
||||
}
|
||||
if ((buf_offset = zip_source_tell(za->src)) < 0) {
|
||||
_zip_error_set_from_source(&za->error, za->src);
|
||||
zip_error_set_from_source(&za->error, za->src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -589,7 +609,8 @@ _zip_find_central_dir(zip_t *za, zip_uint64_t len) {
|
||||
zip_error_set(&error, ZIP_ER_NOZIP, 0);
|
||||
|
||||
match = _zip_buffer_get(buffer, 0);
|
||||
while ((match = _zip_memmem(match, _zip_buffer_left(buffer) - (EOCDLEN - 4), (const unsigned char *)EOCD_MAGIC, 4)) != NULL) {
|
||||
/* The size of buffer never greater than CDBUFSIZE. */
|
||||
while (_zip_buffer_left(buffer) >= EOCDLEN && (match = _zip_memmem(match, (size_t)_zip_buffer_left(buffer) - (EOCDLEN - 4), (const unsigned char *)EOCD_MAGIC, 4)) != NULL) {
|
||||
_zip_buffer_set_offset(buffer, (zip_uint64_t)(match - _zip_buffer_data(buffer)));
|
||||
if ((cdirnew = _zip_read_cdir(za, buffer, (zip_uint64_t)buf_offset, &error)) != NULL) {
|
||||
if (cdir) {
|
||||
@@ -634,19 +655,28 @@ _zip_find_central_dir(zip_t *za, zip_uint64_t len) {
|
||||
}
|
||||
|
||||
|
||||
static unsigned char *
|
||||
_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen) {
|
||||
static const unsigned char *_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen) {
|
||||
const unsigned char *p;
|
||||
|
||||
if ((biglen < littlelen) || (littlelen == 0))
|
||||
return NULL;
|
||||
p = big - 1;
|
||||
while ((p = (const unsigned char *)memchr(p + 1, little[0], (size_t)(big - (p + 1)) + (size_t)(biglen - littlelen) + 1)) != NULL) {
|
||||
if (memcmp(p + 1, little + 1, littlelen - 1) == 0)
|
||||
return (unsigned char *)p;
|
||||
if (littlelen == 0) {
|
||||
return big;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (biglen < littlelen) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = big;
|
||||
while (true) {
|
||||
p = (const unsigned char *)memchr(p, little[0], biglen - (littlelen - 1) - (size_t)(p - big));
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (memcmp(p + 1, little + 1, littlelen - 1) == 0) {
|
||||
return p;
|
||||
}
|
||||
p += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -746,7 +776,7 @@ _zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offse
|
||||
}
|
||||
else {
|
||||
if (zip_source_seek(src, (zip_int64_t)eocd_offset, SEEK_SET) < 0) {
|
||||
_zip_error_set_from_source(error, src);
|
||||
zip_error_set_from_source(error, src);
|
||||
return NULL;
|
||||
}
|
||||
if ((buffer = _zip_buffer_new_from_source(src, EOCD64LEN, eocd, error)) == NULL) {
|
||||
@@ -859,3 +889,79 @@ _zip_read_eocd64(zip_source_t *src, zip_buffer_t *buffer, zip_uint64_t buf_offse
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
|
||||
static int decode_hex(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
else if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* _zip_check_torrentzip:
|
||||
check whether ZA has a valid TORRENTZIP comment, i.e. is torrentzipped */
|
||||
|
||||
static void zip_check_torrentzip(zip_t *za, const zip_cdir_t *cdir) {
|
||||
zip_uint32_t crc_should;
|
||||
char buf[8+1];
|
||||
size_t i;
|
||||
|
||||
if (cdir == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_zip_string_length(cdir->comment) != TORRENTZIP_SIGNATURE_LENGTH + TORRENTZIP_CRC_LENGTH
|
||||
|| strncmp((const char *)cdir->comment->raw, TORRENTZIP_SIGNATURE, TORRENTZIP_SIGNATURE_LENGTH) != 0)
|
||||
return;
|
||||
|
||||
memcpy(buf, cdir->comment->raw + TORRENTZIP_SIGNATURE_LENGTH, TORRENTZIP_CRC_LENGTH);
|
||||
buf[TORRENTZIP_CRC_LENGTH] = '\0';
|
||||
crc_should = 0;
|
||||
for (i = 0; i < TORRENTZIP_CRC_LENGTH; i += 2) {
|
||||
int low, high;
|
||||
high = decode_hex((buf[i]));
|
||||
low = decode_hex(buf[i + 1]);
|
||||
if (high < 0 || low < 0) {
|
||||
return;
|
||||
}
|
||||
crc_should = (crc_should << 8) + (high << 4) + low;
|
||||
}
|
||||
|
||||
{
|
||||
zip_stat_t st;
|
||||
zip_source_t* src_window;
|
||||
zip_source_t* src_crc;
|
||||
zip_uint8_t buffer[512];
|
||||
zip_int64_t ret;
|
||||
|
||||
zip_stat_init(&st);
|
||||
st.valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC;
|
||||
st.size = cdir->size;
|
||||
st.crc = crc_should;
|
||||
if ((src_window = _zip_source_window_new(za->src, cdir->offset, cdir->size, &st, 0, NULL, NULL, 0, false, NULL)) == NULL) {
|
||||
return;
|
||||
}
|
||||
if ((src_crc = zip_source_crc_create(src_window, 1, NULL)) == NULL) {
|
||||
zip_source_free(src_window);
|
||||
return;
|
||||
}
|
||||
if (zip_source_open(src_crc) != 0) {
|
||||
zip_source_free(src_crc);
|
||||
return;
|
||||
}
|
||||
while ((ret = zip_source_read(src_crc, buffer, sizeof(buffer))) > 0) {
|
||||
}
|
||||
zip_source_free(src_crc);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: if check consistency, check cdir entries for valid values */
|
||||
za->flags |= ZIP_AFL_IS_TORRENTZIP;
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2016-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -45,6 +45,10 @@ zip_set_archive_comment(zip_t *za, const char *comment, zip_uint16_t len) {
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (len > 0 && comment == NULL) {
|
||||
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
||||
|
||||
+16
-6
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2008-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -39,13 +39,23 @@ ZIP_EXTERN int
|
||||
zip_set_archive_flag(zip_t *za, zip_flags_t flag, int value) {
|
||||
unsigned int new_flags;
|
||||
|
||||
if (value)
|
||||
new_flags = za->ch_flags | flag;
|
||||
else
|
||||
new_flags = za->ch_flags & ~flag;
|
||||
if (flag == ZIP_AFL_IS_TORRENTZIP) {
|
||||
zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (new_flags == za->ch_flags)
|
||||
/* TODO: when setting ZIP_AFL_WANT_TORRENTZIP, we should error out if any changes have been made that are not allowed for torrentzip. */
|
||||
|
||||
if (value) {
|
||||
new_flags = za->ch_flags | flag;
|
||||
}
|
||||
else {
|
||||
new_flags = za->ch_flags & ~flag;
|
||||
}
|
||||
|
||||
if (new_flags == za->ch_flags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ZIP_IS_RDONLY(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2006-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2012-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -49,6 +49,10 @@ zip_set_file_compression(zip_t *za, zip_uint64_t idx, zip_int32_t method, zip_ui
|
||||
zip_error_set(&za->error, ZIP_ER_RDONLY, 0);
|
||||
return -1;
|
||||
}
|
||||
if (ZIP_WANT_TORRENTZIP(za)) {
|
||||
zip_error_set(&za->error, ZIP_ER_NOT_ALLOWED, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!zip_compression_method_supported(method, true)) {
|
||||
zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2019-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
bool
|
||||
zip_source_accept_empty(zip_source_t *src) {
|
||||
int ret;
|
||||
zip_int64_t ret;
|
||||
|
||||
if ((zip_source_supports(src) & ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ACCEPT_EMPTY)) == 0) {
|
||||
if (ZIP_SOURCE_IS_LAYERED(src)) {
|
||||
@@ -46,7 +46,7 @@ zip_source_accept_empty(zip_source_t *src) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ret = (int)_zip_source_call(src, NULL, 0, ZIP_SOURCE_ACCEPT_EMPTY);
|
||||
ret = _zip_source_call(src, NULL, 0, ZIP_SOURCE_ACCEPT_EMPTY);
|
||||
|
||||
return ret != 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2014-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,11 @@
|
||||
|
||||
ZIP_EXTERN int
|
||||
zip_source_begin_write(zip_source_t *src) {
|
||||
if (ZIP_SOURCE_IS_LAYERED(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,11 @@
|
||||
|
||||
ZIP_EXTERN int
|
||||
zip_source_begin_write_cloning(zip_source_t *src, zip_uint64_t offset) {
|
||||
if (ZIP_SOURCE_IS_LAYERED(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ZIP_SOURCE_IS_OPEN_WRITING(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
|
||||
+46
-23
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_source_buffer.c -- create zip data source from buffer
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 1999-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -50,8 +50,8 @@ struct buffer {
|
||||
|
||||
zip_uint64_t shared_fragments; /* number of shared fragments */
|
||||
struct buffer *shared_buffer; /* buffer fragments are shared with */
|
||||
zip_uint64_t size; /* size of buffer */
|
||||
|
||||
zip_uint64_t size; /* size of buffer */
|
||||
zip_uint64_t offset; /* current offset in buffer */
|
||||
zip_uint64_t current_fragment; /* fragment current offset is in */
|
||||
};
|
||||
@@ -159,7 +159,7 @@ zip_source_buffer_fragment_with_attributes_create(const zip_buffer_fragment_t *f
|
||||
ctx->out = NULL;
|
||||
ctx->mtime = time(NULL);
|
||||
if (attributes) {
|
||||
memcpy(&ctx->attributes, attributes, sizeof(ctx->attributes));
|
||||
(void)memcpy_s(&ctx->attributes, sizeof(ctx->attributes), attributes, sizeof(ctx->attributes));
|
||||
}
|
||||
else {
|
||||
zip_file_attributes_init(&ctx->attributes);
|
||||
@@ -226,7 +226,7 @@ read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, &ctx->attributes, sizeof(ctx->attributes));
|
||||
(void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
|
||||
|
||||
return sizeof(ctx->attributes);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ read_data(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
|
||||
}
|
||||
|
||||
case ZIP_SOURCE_SUPPORTS:
|
||||
return zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, -1);
|
||||
return zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_SEEK, ZIP_SOURCE_TELL, ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_BEGIN_WRITE_CLONING, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_WRITE, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
|
||||
|
||||
case ZIP_SOURCE_TELL:
|
||||
if (ctx->in->offset > ZIP_INT64_MAX) {
|
||||
@@ -344,6 +344,7 @@ buffer_clone(buffer_t *buffer, zip_uint64_t offset, zip_error_t *error) {
|
||||
fragment_offset = buffer->fragments[fragment].length;
|
||||
}
|
||||
|
||||
/* TODO: This should also consider the length of the fully shared fragments */
|
||||
waste = buffer->fragments[fragment].length - fragment_offset;
|
||||
if (waste > offset) {
|
||||
zip_error_set(error, ZIP_ER_OPNOTSUPP, 0);
|
||||
@@ -356,18 +357,18 @@ buffer_clone(buffer_t *buffer, zip_uint64_t offset, zip_error_t *error) {
|
||||
|
||||
#ifndef __clang_analyzer__
|
||||
/* clone->fragments can't be null, since it was created with at least one fragment */
|
||||
clone->fragments[clone->nfragments - 1].length = fragment_offset;
|
||||
clone->fragments[fragment].length = fragment_offset;
|
||||
#endif
|
||||
clone->fragment_offsets[clone->nfragments] = offset;
|
||||
clone->size = offset;
|
||||
|
||||
clone->first_owned_fragment = ZIP_MIN(buffer->first_owned_fragment, clone->nfragments - 1);
|
||||
clone->first_owned_fragment = ZIP_MIN(buffer->first_owned_fragment, clone->nfragments);
|
||||
|
||||
buffer->shared_buffer = clone;
|
||||
clone->shared_buffer = buffer;
|
||||
buffer->shared_fragments = clone->nfragments;
|
||||
buffer->shared_fragments = fragment + 1;
|
||||
clone->shared_fragments = fragment + 1;
|
||||
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -376,6 +377,10 @@ static zip_uint64_t
|
||||
buffer_find_fragment(const buffer_t *buffer, zip_uint64_t offset) {
|
||||
zip_uint64_t low, high, mid;
|
||||
|
||||
if (buffer->nfragments == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
high = buffer->nfragments - 1;
|
||||
|
||||
@@ -429,12 +434,20 @@ buffer_grow_fragments(buffer_t *buffer, zip_uint64_t capacity, zip_error_t *erro
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((fragments = realloc(buffer->fragments, sizeof(buffer->fragments[0]) * capacity)) == NULL) {
|
||||
zip_uint64_t fragments_size = sizeof(buffer->fragments[0]) * capacity;
|
||||
zip_uint64_t offsets_size = sizeof(buffer->fragment_offsets[0]) * (capacity + 1);
|
||||
|
||||
if (capacity == ZIP_UINT64_MAX || fragments_size < capacity || fragments_size > SIZE_MAX|| offsets_size < capacity || offsets_size > SIZE_MAX) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((fragments = realloc(buffer->fragments, (size_t)fragments_size)) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
buffer->fragments = fragments;
|
||||
if ((offsets = realloc(buffer->fragment_offsets, sizeof(buffer->fragment_offsets[0]) * (capacity + 1))) == NULL) {
|
||||
if ((offsets = realloc(buffer->fragment_offsets, (size_t)offsets_size)) == NULL) {
|
||||
zip_error_set(error, ZIP_ER_MEMORY, 0);
|
||||
return false;
|
||||
}
|
||||
@@ -493,6 +506,7 @@ buffer_new(const zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int
|
||||
buffer->fragments[j].data = fragments[i].data;
|
||||
buffer->fragments[j].length = fragments[i].length;
|
||||
buffer->fragment_offsets[i] = offset;
|
||||
/* TODO: overflow */
|
||||
offset += fragments[i].length;
|
||||
j++;
|
||||
}
|
||||
@@ -523,8 +537,11 @@ buffer_read(buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) {
|
||||
n = 0;
|
||||
while (n < length) {
|
||||
zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
|
||||
#if ZIP_UINT64_MAX > SIZE_MAX
|
||||
left = ZIP_MIN(left, SIZE_MAX);
|
||||
#endif
|
||||
|
||||
memcpy(data + n, buffer->fragments[i].data + fragment_offset, left);
|
||||
(void)memcpy_s(data + n, (size_t)left, buffer->fragments[i].data + fragment_offset, (size_t)left);
|
||||
|
||||
if (left == buffer->fragments[i].length - fragment_offset) {
|
||||
i++;
|
||||
@@ -555,7 +572,7 @@ buffer_seek(buffer_t *buffer, void *data, zip_uint64_t len, zip_error_t *error)
|
||||
|
||||
static zip_int64_t
|
||||
buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip_error_t *error) {
|
||||
zip_uint64_t n, i, fragment_offset, capacity;
|
||||
zip_uint64_t copied, i, fragment_offset, capacity;
|
||||
|
||||
if (buffer->offset + length + WRITE_FRAGMENT_SIZE - 1 < length) {
|
||||
zip_error_set(error, ZIP_ER_INVAL, 0);
|
||||
@@ -597,24 +614,30 @@ buffer_write(buffer_t *buffer, const zip_uint8_t *data, zip_uint64_t length, zip
|
||||
|
||||
i = buffer->current_fragment;
|
||||
fragment_offset = buffer->offset - buffer->fragment_offsets[i];
|
||||
n = 0;
|
||||
while (n < length) {
|
||||
zip_uint64_t left = ZIP_MIN(length - n, buffer->fragments[i].length - fragment_offset);
|
||||
copied = 0;
|
||||
while (copied < length) {
|
||||
zip_uint64_t n = ZIP_MIN(ZIP_MIN(length - copied, buffer->fragments[i].length - fragment_offset), SIZE_MAX);
|
||||
#if ZIP_UINT64_MAX > SIZE_MAX
|
||||
n = ZIP_MIN(n, SIZE_MAX);
|
||||
#endif
|
||||
|
||||
memcpy(buffer->fragments[i].data + fragment_offset, data + n, left);
|
||||
(void)memcpy_s(buffer->fragments[i].data + fragment_offset, (size_t)n, data + copied, (size_t)n);
|
||||
|
||||
if (left == buffer->fragments[i].length - fragment_offset) {
|
||||
if (n == buffer->fragments[i].length - fragment_offset) {
|
||||
i++;
|
||||
fragment_offset = 0;
|
||||
}
|
||||
n += left;
|
||||
fragment_offset = 0;
|
||||
else {
|
||||
fragment_offset += n;
|
||||
}
|
||||
copied += n;
|
||||
}
|
||||
|
||||
buffer->offset += n;
|
||||
buffer->offset += copied;
|
||||
buffer->current_fragment = i;
|
||||
if (buffer->offset > buffer->size) {
|
||||
buffer->size = buffer->offset;
|
||||
}
|
||||
|
||||
return (zip_int64_t)n;
|
||||
return (zip_int64_t)copied;
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2014-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,11 @@
|
||||
|
||||
ZIP_EXTERN int
|
||||
zip_source_commit_write(zip_source_t *src) {
|
||||
if (ZIP_SOURCE_IS_LAYERED(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ZIP_SOURCE_IS_OPEN_WRITING(src)) {
|
||||
zip_error_set(&src->error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
|
||||
+12
-12
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2017-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -83,10 +83,10 @@ static struct implementation implementations[] = {
|
||||
|
||||
static size_t implementations_size = sizeof(implementations) / sizeof(implementations[0]);
|
||||
|
||||
static zip_source_t *compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, int compression_flags);
|
||||
static zip_source_t *compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, zip_uint32_t compression_flags);
|
||||
static zip_int64_t compress_callback(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t);
|
||||
static void context_free(struct context *ctx);
|
||||
static struct context *context_new(zip_int32_t method, bool compress, int compression_flags, zip_compression_algorithm_t *algorithm);
|
||||
static struct context *context_new(zip_int32_t method, bool compress, zip_uint32_t compression_flags, zip_compression_algorithm_t *algorithm);
|
||||
static zip_int64_t compress_read(zip_source_t *, struct context *, void *, zip_uint64_t);
|
||||
|
||||
zip_compression_algorithm_t *
|
||||
@@ -117,7 +117,7 @@ zip_compression_method_supported(zip_int32_t method, int compress) {
|
||||
}
|
||||
|
||||
zip_source_t *
|
||||
zip_source_compress(zip_t *za, zip_source_t *src, zip_int32_t method, int compression_flags) {
|
||||
zip_source_compress(zip_t *za, zip_source_t *src, zip_int32_t method, zip_uint32_t compression_flags) {
|
||||
return compression_source_new(za, src, method, true, compression_flags);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ zip_source_decompress(zip_t *za, zip_source_t *src, zip_int32_t method) {
|
||||
|
||||
|
||||
static zip_source_t *
|
||||
compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, int compression_flags) {
|
||||
compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool compress, zip_uint32_t compression_flags) {
|
||||
struct context *ctx;
|
||||
zip_source_t *s2;
|
||||
zip_compression_algorithm_t *algorithm = NULL;
|
||||
@@ -158,7 +158,7 @@ compression_source_new(zip_t *za, zip_source_t *src, zip_int32_t method, bool co
|
||||
|
||||
|
||||
static struct context *
|
||||
context_new(zip_int32_t method, bool compress, int compression_flags, zip_compression_algorithm_t *algorithm) {
|
||||
context_new(zip_int32_t method, bool compress, zip_uint32_t compression_flags, zip_compression_algorithm_t *algorithm) {
|
||||
struct context *ctx;
|
||||
|
||||
if ((ctx = (struct context *)malloc(sizeof(*ctx))) == NULL) {
|
||||
@@ -240,7 +240,7 @@ compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t l
|
||||
if (ctx->can_store && (zip_uint64_t)ctx->first_read <= out_offset) {
|
||||
ctx->is_stored = true;
|
||||
ctx->size = (zip_uint64_t)ctx->first_read;
|
||||
memcpy(data, ctx->buffer, ctx->size);
|
||||
(void)memcpy_s(data, ctx->size, ctx->buffer, ctx->size);
|
||||
return (zip_int64_t)ctx->size;
|
||||
}
|
||||
end = true;
|
||||
@@ -257,7 +257,7 @@ compress_read(zip_source_t *src, struct context *ctx, void *data, zip_uint64_t l
|
||||
}
|
||||
|
||||
if ((n = zip_source_read(src, ctx->buffer, sizeof(ctx->buffer))) < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip
|
||||
ctx->first_read = -1;
|
||||
|
||||
if (zip_source_stat(src, &st) < 0 || zip_source_get_file_attributes(src, &attributes) < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -357,6 +357,7 @@ compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip
|
||||
else {
|
||||
st->comp_method = ZIP_CM_STORE;
|
||||
st->valid |= ZIP_STAT_COMP_METHOD;
|
||||
st->valid &= ~ZIP_STAT_COMP_SIZE;
|
||||
if (ctx->end_of_stream) {
|
||||
st->size = ctx->size;
|
||||
st->valid |= ZIP_STAT_SIZE;
|
||||
@@ -389,10 +390,9 @@ compress_callback(zip_source_t *src, void *ud, void *data, zip_uint64_t len, zip
|
||||
}
|
||||
|
||||
case ZIP_SOURCE_SUPPORTS:
|
||||
return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
|
||||
return ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
|
||||
|
||||
default:
|
||||
zip_error_set(&ctx->error, ZIP_ER_INTERNAL, 0);
|
||||
return -1;
|
||||
return zip_source_pass_to_lower_layer(src, data, len, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-8
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -90,7 +90,7 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
|
||||
case ZIP_SOURCE_READ:
|
||||
if ((n = zip_source_read(src, data, len)) < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
struct zip_stat st;
|
||||
|
||||
if (zip_source_stat(src, &st) < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -141,6 +141,10 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
st = (zip_stat_t *)data;
|
||||
|
||||
if (ctx->crc_complete) {
|
||||
if ((st->valid & ZIP_STAT_SIZE) && st->size != ctx->size) {
|
||||
zip_error_set(&ctx->error, ZIP_ER_DATA_LENGTH, 0);
|
||||
return -1;
|
||||
}
|
||||
/* TODO: Set comp_size, comp_method, encryption_method?
|
||||
After all, this only works for uncompressed data. */
|
||||
st->size = ctx->size;
|
||||
@@ -164,11 +168,13 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
zip_int64_t mask = zip_source_supports(src);
|
||||
|
||||
if (mask < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mask & ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
|
||||
mask &= ~zip_source_make_command_bitmap(ZIP_SOURCE_BEGIN_WRITE, ZIP_SOURCE_COMMIT_WRITE, ZIP_SOURCE_ROLLBACK_WRITE, ZIP_SOURCE_SEEK_WRITE, ZIP_SOURCE_TELL_WRITE, ZIP_SOURCE_REMOVE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
|
||||
mask |= zip_source_make_command_bitmap(ZIP_SOURCE_FREE, -1);
|
||||
return mask;
|
||||
}
|
||||
|
||||
case ZIP_SOURCE_SEEK: {
|
||||
@@ -179,7 +185,7 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
return -1;
|
||||
}
|
||||
if (zip_source_seek(src, args->offset, args->whence) < 0 || (new_position = zip_source_tell(src)) < 0) {
|
||||
_zip_error_set_from_source(&ctx->error, src);
|
||||
zip_error_set_from_source(&ctx->error, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -192,7 +198,6 @@ crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint64_t len, zip_source
|
||||
return (zip_int64_t)ctx->position;
|
||||
|
||||
default:
|
||||
zip_error_set(&ctx->error, ZIP_ER_OPNOTSUPP, 0);
|
||||
return -1;
|
||||
return zip_source_pass_to_lower_layer(src, data, len, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2009-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_source_file.h -- header for common file operations
|
||||
Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 2020-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -34,7 +34,7 @@
|
||||
struct zip_source_file_stat {
|
||||
zip_uint64_t size; /* must be valid for regular files */
|
||||
time_t mtime; /* must always be valid, is initialized to current time */
|
||||
bool exists; /* must always be vaild */
|
||||
bool exists; /* must always be valid */
|
||||
bool regular_file; /* must always be valid */
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2021 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -109,7 +109,7 @@ zip_source_file_common_new(const char *fname, void *file, zip_uint64_t start, zi
|
||||
ctx->start = start;
|
||||
ctx->len = (zip_uint64_t)len;
|
||||
if (st) {
|
||||
memcpy(&ctx->st, st, sizeof(ctx->st));
|
||||
(void)memcpy_s(&ctx->st, sizeof(ctx->st), st, sizeof(*st));
|
||||
ctx->st.name = NULL;
|
||||
ctx->st.valid &= ~ZIP_STAT_NAME;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ zip_source_file_common_new(const char *fname, void *file, zip_uint64_t start, zi
|
||||
zip_error_init(&ctx->error);
|
||||
zip_file_attributes_init(&ctx->attributes);
|
||||
|
||||
ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, -1);
|
||||
ctx->supports = ZIP_SOURCE_SUPPORTS_READABLE | zip_source_make_command_bitmap(ZIP_SOURCE_SUPPORTS, ZIP_SOURCE_TELL, ZIP_SOURCE_SUPPORTS_REOPEN, -1);
|
||||
|
||||
zip_source_file_stat_init(&sb);
|
||||
if (!ops->stat(ctx, &sb)) {
|
||||
@@ -262,7 +262,7 @@ read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
|
||||
zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, &ctx->attributes, sizeof(ctx->attributes));
|
||||
(void)memcpy_s(data, sizeof(ctx->attributes), &ctx->attributes, sizeof(ctx->attributes));
|
||||
return sizeof(ctx->attributes);
|
||||
|
||||
case ZIP_SOURCE_OPEN:
|
||||
@@ -272,7 +272,7 @@ read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->start > 0) { // TODO: rewind on re-open
|
||||
if (ctx->start > 0) { /* TODO: rewind on re-open */
|
||||
if (ctx->ops->seek(ctx, ctx->f, (zip_int64_t)ctx->start, SEEK_SET) == false) {
|
||||
/* TODO: skip by reading */
|
||||
return -1;
|
||||
@@ -355,7 +355,7 @@ read_file(void *state, void *data, zip_uint64_t len, zip_source_cmd_t cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, &ctx->st, sizeof(ctx->st));
|
||||
(void)memcpy_s(data, sizeof(ctx->st), &ctx->st, sizeof(ctx->st));
|
||||
return sizeof(ctx->st);
|
||||
}
|
||||
|
||||
|
||||
+1
-31
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -176,33 +176,3 @@ _zip_stdio_op_tell(zip_source_file_context_t *ctx, void *f) {
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fopen replacement that sets the close-on-exec flag
|
||||
* some implementations support an fopen 'e' flag for that,
|
||||
* but e.g. macOS doesn't.
|
||||
*/
|
||||
FILE *
|
||||
_zip_fopen_close_on_exec(const char *name, bool writeable) {
|
||||
int fd;
|
||||
int flags;
|
||||
FILE *fp;
|
||||
|
||||
flags = O_CLOEXEC;
|
||||
if (writeable) {
|
||||
flags |= O_RDWR;
|
||||
}
|
||||
else {
|
||||
flags |= O_RDONLY;
|
||||
}
|
||||
|
||||
/* mode argument needed on Windows */
|
||||
if ((fd = open(name, flags, 0666)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if ((fp = fdopen(fd, writeable ? "r+b" : "rb")) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -42,6 +42,4 @@ bool _zip_stdio_op_seek(zip_source_file_context_t *ctx, void *f, zip_int64_t off
|
||||
bool _zip_stdio_op_stat(zip_source_file_context_t *ctx, zip_source_file_stat_t *st);
|
||||
zip_int64_t _zip_stdio_op_tell(zip_source_file_context_t *ctx, void *f);
|
||||
|
||||
FILE *_zip_fopen_close_on_exec(const char *name, bool writeable);
|
||||
|
||||
#endif /* _HAD_ZIP_SOURCE_FILE_STDIO_H */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
zip_source_file_win32.c -- read-only Windows file source implementation
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
Copyright (C) 1999-2022 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -115,7 +115,7 @@ _zip_win32_op_seek(zip_source_file_context_t *ctx, void *f, zip_int64_t offset,
|
||||
break;
|
||||
default:
|
||||
zip_error_set(&ctx->error, ZIP_ER_SEEK, EINVAL);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
li.QuadPart = (LONGLONG)offset;
|
||||
@@ -184,7 +184,7 @@ _zip_stat_win32(zip_source_file_context_t *ctx, zip_source_file_stat_t *st, HAND
|
||||
zip_error_set(&ctx->error, ZIP_ER_READ, _zip_win32_error_to_errno(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
if (_zip_filetime_to_time_t(mtimeft, &mtime) < 0) {
|
||||
if (!_zip_filetime_to_time_t(mtimeft, &mtime)) {
|
||||
zip_error_set(&ctx->error, ZIP_ER_READ, ERANGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -73,4 +73,12 @@ zip_int64_t _zip_win32_op_tell(zip_source_file_context_t *ctx, void *f);
|
||||
bool _zip_filetime_to_time_t(FILETIME ft, time_t *t);
|
||||
int _zip_win32_error_to_errno(DWORD win32err);
|
||||
|
||||
#ifdef __clang__
|
||||
#define DONT_WARN_INCOMPATIBLE_FN_PTR_BEGIN _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wincompatible-function-pointer-types\"")
|
||||
#define DONT_WARN_INCOMPATIBLE_FN_PTR_END _Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
#define DONT_WARN_INCOMPATIBLE_FN_PTR_BEGIN
|
||||
#define DONT_WARN_INCOMPATIBLE_FN_PTR_END
|
||||
#endif
|
||||
|
||||
#endif /* _HAD_ZIP_SOURCE_FILE_WIN32_H */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,7 @@ static char *ansi_allocate_tempname(const char *name, size_t extra_chars, size_t
|
||||
static void ansi_make_tempname(char *buf, size_t len, const char *name, zip_uint32_t i);
|
||||
|
||||
/* clang-format off */
|
||||
DONT_WARN_INCOMPATIBLE_FN_PTR_BEGIN
|
||||
|
||||
zip_win32_file_operations_t ops_ansi = {
|
||||
ansi_allocate_tempname,
|
||||
@@ -50,6 +51,7 @@ zip_win32_file_operations_t ops_ansi = {
|
||||
strdup
|
||||
};
|
||||
|
||||
DONT_WARN_INCOMPATIBLE_FN_PTR_END
|
||||
/* clang-format on */
|
||||
|
||||
ZIP_EXTERN zip_source_t *
|
||||
@@ -81,5 +83,5 @@ ansi_allocate_tempname(const char *name, size_t extra_chars, size_t *lengthp) {
|
||||
|
||||
static void
|
||||
ansi_make_tempname(char *buf, size_t len, const char *name, zip_uint32_t i) {
|
||||
snprintf(buf, len, "%s.%08x", name, i);
|
||||
snprintf_s(buf, len, "%s.%08x", name, i);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -99,7 +99,6 @@ _zip_win32_named_op_create_temp_output(zip_source_file_context_t *ctx) {
|
||||
|
||||
zip_uint32_t value, i;
|
||||
HANDLE th = INVALID_HANDLE_VALUE;
|
||||
void *temp = NULL;
|
||||
PSECURITY_DESCRIPTOR psd = NULL;
|
||||
PSECURITY_ATTRIBUTES psa = NULL;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -39,6 +39,7 @@ static void utf16_make_tempname(char *buf, size_t len, const char *name, zip_uin
|
||||
static char *utf16_strdup(const char *string);
|
||||
|
||||
/* clang-format off */
|
||||
DONT_WARN_INCOMPATIBLE_FN_PTR_BEGIN
|
||||
|
||||
zip_win32_file_operations_t ops_utf16 = {
|
||||
utf16_allocate_tempname,
|
||||
@@ -52,6 +53,7 @@ zip_win32_file_operations_t ops_utf16 = {
|
||||
utf16_strdup
|
||||
};
|
||||
|
||||
DONT_WARN_INCOMPATIBLE_FN_PTR_END
|
||||
/* clang-format on */
|
||||
|
||||
ZIP_EXTERN zip_source_t *
|
||||
@@ -101,7 +103,7 @@ static HANDLE __stdcall utf16_create_file(const char *name, DWORD access, DWORD
|
||||
|
||||
static void
|
||||
utf16_make_tempname(char *buf, size_t len, const char *name, zip_uint32_t i) {
|
||||
_snwprintf((wchar_t *)buf, len, L"%s.%08x", (const wchar_t *)name, i);
|
||||
_snwprintf_s((wchar_t *)buf, len, len, L"%s.%08x", (const wchar_t *)name, i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 1999-2020 Dieter Baron and Thomas Klausner
|
||||
|
||||
This file is part of libzip, a library to manipulate ZIP archives.
|
||||
The authors can be contacted at <libzip@nih.at>
|
||||
The authors can be contacted at <info@libzip.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user