| 1 |
diff --git a/thirdparty/minizip/ioapi.c b/thirdparty/minizip/ioapi.c |
| 2 |
index 3dbefe48c2..b072ecdcc2 100644 |
| 3 |
--- a/thirdparty/minizip/ioapi.c |
| 4 |
+++ b/thirdparty/minizip/ioapi.c |
| 5 |
@@ -75,9 +75,12 @@ void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef |
| 6 |
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; |
| 7 |
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; |
| 8 |
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; |
| 9 |
+ p_filefunc64_32->zfile_func64.alloc_mem = p_filefunc32->alloc_mem; |
| 10 |
+ p_filefunc64_32->zfile_func64.free_mem = p_filefunc32->free_mem; |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
+#if 0 |
| 15 |
|
| 16 |
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) { |
| 17 |
FILE* file = NULL; |
| 18 |
@@ -229,3 +232,5 @@ void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) { |
| 19 |
pzlib_filefunc_def->zerror_file = ferror_file_func; |
| 20 |
pzlib_filefunc_def->opaque = NULL; |
| 21 |
} |
| 22 |
+ |
| 23 |
+#endif |
| 24 |
diff --git a/thirdparty/minizip/ioapi.h b/thirdparty/minizip/ioapi.h |
| 25 |
index 6b9968c732..be64d7db45 100644 |
| 26 |
--- a/thirdparty/minizip/ioapi.h |
| 27 |
+++ b/thirdparty/minizip/ioapi.h |
| 28 |
@@ -128,6 +128,8 @@ typedef struct zlib_filefunc_def_s |
| 29 |
close_file_func zclose_file; |
| 30 |
testerror_file_func zerror_file; |
| 31 |
voidpf opaque; |
| 32 |
+ alloc_func alloc_mem; |
| 33 |
+ free_func free_mem; |
| 34 |
} zlib_filefunc_def; |
| 35 |
|
| 36 |
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream); |
| 37 |
@@ -144,6 +146,8 @@ typedef struct zlib_filefunc64_def_s |
| 38 |
close_file_func zclose_file; |
| 39 |
testerror_file_func zerror_file; |
| 40 |
voidpf opaque; |
| 41 |
+ alloc_func alloc_mem; |
| 42 |
+ free_func free_mem; |
| 43 |
} zlib_filefunc64_def; |
| 44 |
|
| 45 |
void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def); |
| 46 |
diff --git a/thirdparty/minizip/unzip.c b/thirdparty/minizip/unzip.c |
| 47 |
index e9088bd542..98a568e098 100644 |
| 48 |
--- a/thirdparty/minizip/unzip.c |
| 49 |
+++ b/thirdparty/minizip/unzip.c |
| 50 |
@@ -148,6 +148,7 @@ typedef struct |
| 51 |
uLong compression_method; /* compression method (0==store) */ |
| 52 |
ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ |
| 53 |
int raw; |
| 54 |
+ int extra_size; |
| 55 |
} file_in_zip64_read_info_s; |
| 56 |
|
| 57 |
|
| 58 |
@@ -509,9 +510,9 @@ local unzFile unzOpenInternal(const void *path, |
| 59 |
us.z_filefunc.zseek32_file = NULL; |
| 60 |
us.z_filefunc.ztell32_file = NULL; |
| 61 |
if (pzlib_filefunc64_32_def==NULL) |
| 62 |
- fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); |
| 63 |
- else |
| 64 |
- us.z_filefunc = *pzlib_filefunc64_32_def; |
| 65 |
+ //fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); |
| 66 |
+ return NULL; // standard i/o not supported |
| 67 |
+ us.z_filefunc = *pzlib_filefunc64_32_def; |
| 68 |
us.is64bitOpenFunction = is64bitOpenFunction; |
| 69 |
|
| 70 |
|
| 71 |
@@ -699,6 +700,15 @@ extern unzFile ZEXPORT unzOpen64(const void *path) { |
| 72 |
return unzOpenInternal(path, NULL, 1); |
| 73 |
} |
| 74 |
|
| 75 |
+extern void* unzGetOpaque(unzFile file) { |
| 76 |
+ unz64_s* s; |
| 77 |
+ if (file==NULL) |
| 78 |
+ return NULL; |
| 79 |
+ s=(unz64_s*)file; |
| 80 |
+ |
| 81 |
+ return s->z_filefunc.zfile_func64.opaque; |
| 82 |
+} |
| 83 |
+ |
| 84 |
/* |
| 85 |
Close a ZipFile opened with unzOpen. |
| 86 |
If there is files inside the .Zip opened with unzOpenCurrentFile (see later), |
| 87 |
@@ -901,10 +911,19 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, |
| 88 |
|
| 89 |
if (lSeek!=0) |
| 90 |
{ |
| 91 |
- if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) |
| 92 |
- lSeek=0; |
| 93 |
- else |
| 94 |
- err=UNZ_ERRNO; |
| 95 |
+ if (lSeek<0) { |
| 96 |
+ // WORKAROUND for backwards seeking |
| 97 |
+ ZPOS64_T pos = ZTELL64(s->z_filefunc, s->filestream); |
| 98 |
+ if (ZSEEK64(s->z_filefunc, s->filestream,pos+(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_SET)==0) |
| 99 |
+ lSeek=0; |
| 100 |
+ else |
| 101 |
+ err=UNZ_ERRNO; |
| 102 |
+ } else { |
| 103 |
+ if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) |
| 104 |
+ lSeek=0; |
| 105 |
+ else |
| 106 |
+ err=UNZ_ERRNO; |
| 107 |
+ } |
| 108 |
} |
| 109 |
|
| 110 |
while(acc < file_info.size_file_extra) |
| 111 |
@@ -1442,8 +1461,8 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, |
| 112 |
} |
| 113 |
else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) |
| 114 |
{ |
| 115 |
- pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; |
| 116 |
- pfile_in_zip_read_info->stream.zfree = (free_func)0; |
| 117 |
+ pfile_in_zip_read_info->stream.zalloc = s->z_filefunc.zfile_func64.alloc_mem; |
| 118 |
+ pfile_in_zip_read_info->stream.zfree = s->z_filefunc.zfile_func64.free_mem; |
| 119 |
pfile_in_zip_read_info->stream.opaque = (voidpf)0; |
| 120 |
pfile_in_zip_read_info->stream.next_in = 0; |
| 121 |
pfile_in_zip_read_info->stream.avail_in = 0; |
| 122 |
@@ -1476,6 +1495,7 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, |
| 123 |
iSizeVar; |
| 124 |
|
| 125 |
pfile_in_zip_read_info->stream.avail_in = (uInt)0; |
| 126 |
+ pfile_in_zip_read_info->extra_size = iSizeVar; |
| 127 |
|
| 128 |
s->pfile_in_zip_read = pfile_in_zip_read_info; |
| 129 |
s->encrypted = 0; |
| 130 |
@@ -1506,6 +1526,84 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, |
| 131 |
return UNZ_OK; |
| 132 |
} |
| 133 |
|
| 134 |
+extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos) { |
| 135 |
+ unz64_s* s; |
| 136 |
+ file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 137 |
+ if (file==NULL) |
| 138 |
+ return UNZ_PARAMERROR; |
| 139 |
+ s=(unz64_s*)file; |
| 140 |
+ pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 141 |
+ |
| 142 |
+ if (pfile_in_zip_read_info==NULL) |
| 143 |
+ return UNZ_PARAMERROR; |
| 144 |
+ |
| 145 |
+ if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) { // don't know how to support bzip |
| 146 |
+ return UNZ_INTERNALERROR; |
| 147 |
+ } |
| 148 |
+ |
| 149 |
+ if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) { |
| 150 |
+ |
| 151 |
+ pfile_in_zip_read_info->rest_read_compressed = |
| 152 |
+ s->cur_file_info.compressed_size - pos; |
| 153 |
+ pfile_in_zip_read_info->rest_read_uncompressed = |
| 154 |
+ s->cur_file_info.uncompressed_size - pos; |
| 155 |
+ |
| 156 |
+ pfile_in_zip_read_info->pos_in_zipfile = |
| 157 |
+ s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + |
| 158 |
+ pfile_in_zip_read_info->extra_size + pos; |
| 159 |
+ |
| 160 |
+ pfile_in_zip_read_info->stream.avail_in = (uInt)0; |
| 161 |
+ pfile_in_zip_read_info->stream.total_out = pos; |
| 162 |
+ pfile_in_zip_read_info->total_out_64 = pos; |
| 163 |
+ |
| 164 |
+ return ZSEEK64(pfile_in_zip_read_info->z_filefunc, |
| 165 |
+ pfile_in_zip_read_info->filestream, |
| 166 |
+ pfile_in_zip_read_info->byte_before_the_zipfile + pfile_in_zip_read_info->pos_in_zipfile, |
| 167 |
+ ZLIB_FILEFUNC_SEEK_SET); |
| 168 |
+ |
| 169 |
+ } else { // gzip |
| 170 |
+ |
| 171 |
+ if (pos < pfile_in_zip_read_info->stream.total_out) { // negative seek, rewind |
| 172 |
+ |
| 173 |
+ pfile_in_zip_read_info->rest_read_compressed = |
| 174 |
+ s->cur_file_info.compressed_size ; |
| 175 |
+ pfile_in_zip_read_info->rest_read_uncompressed = |
| 176 |
+ s->cur_file_info.uncompressed_size ; |
| 177 |
+ |
| 178 |
+ pfile_in_zip_read_info->pos_in_zipfile = |
| 179 |
+ s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + |
| 180 |
+ pfile_in_zip_read_info->extra_size; |
| 181 |
+ |
| 182 |
+ (void)inflateReset(&pfile_in_zip_read_info->stream); |
| 183 |
+ |
| 184 |
+ pfile_in_zip_read_info->stream.avail_in = (uInt)0; |
| 185 |
+ pfile_in_zip_read_info->stream.total_out = 0; |
| 186 |
+ pfile_in_zip_read_info->total_out_64 = 0; |
| 187 |
+ pfile_in_zip_read_info->stream.next_in = 0; |
| 188 |
+ } |
| 189 |
+ |
| 190 |
+ // not sure where to read, so read on the stack |
| 191 |
+ { |
| 192 |
+ char buf[512]; |
| 193 |
+ int to_read = pos - pfile_in_zip_read_info->stream.total_out; |
| 194 |
+ while (to_read) { |
| 195 |
+ |
| 196 |
+ int len = to_read > sizeof(buf)?sizeof(buf):to_read; |
| 197 |
+ int read = unzReadCurrentFile(file, buf, len); |
| 198 |
+ if (read < 0) { |
| 199 |
+ return read; |
| 200 |
+ } |
| 201 |
+ to_read -= read; |
| 202 |
+ if (read == UNZ_EOF) { |
| 203 |
+ return pos; |
| 204 |
+ } |
| 205 |
+ } |
| 206 |
+ } |
| 207 |
+ } |
| 208 |
+ |
| 209 |
+ return pos; |
| 210 |
+} |
| 211 |
+ |
| 212 |
extern int ZEXPORT unzOpenCurrentFile(unzFile file) { |
| 213 |
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); |
| 214 |
} |
| 215 |
diff --git a/thirdparty/minizip/unzip.h b/thirdparty/minizip/unzip.h |
| 216 |
index ceb614e783..d515cdafce 100644 |
| 217 |
--- a/thirdparty/minizip/unzip.h |
| 218 |
+++ b/thirdparty/minizip/unzip.h |
| 219 |
@@ -202,6 +202,8 @@ extern int ZEXPORT unzClose(unzFile file); |
| 220 |
these files MUST be closed with unzCloseCurrentFile before call unzClose. |
| 221 |
return UNZ_OK if there is no problem. */ |
| 222 |
|
| 223 |
+extern void* unzGetOpaque(unzFile file); |
| 224 |
+ |
| 225 |
extern int ZEXPORT unzGetGlobalInfo(unzFile file, |
| 226 |
unz_global_info *pglobal_info); |
| 227 |
|
| 228 |
@@ -394,6 +396,11 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, |
| 229 |
(UNZ_ERRNO for IO error, or zLib error for uncompress error) |
| 230 |
*/ |
| 231 |
|
| 232 |
+extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos); |
| 233 |
+/* |
| 234 |
+ Seek to position in uncompressed data |
| 235 |
+*/ |
| 236 |
+ |
| 237 |
extern z_off_t ZEXPORT unztell(unzFile file); |
| 238 |
|
| 239 |
extern ZPOS64_T ZEXPORT unztell64(unzFile file); |
| 240 |
diff --git a/thirdparty/minizip/zip.c b/thirdparty/minizip/zip.c |
| 241 |
index 103f325d37..4fd193e1f3 100644 |
| 242 |
--- a/thirdparty/minizip/zip.c |
| 243 |
+++ b/thirdparty/minizip/zip.c |
| 244 |
@@ -1061,9 +1061,9 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo |
| 245 |
|
| 246 |
ziinit.z_filefunc.zseek32_file = NULL; |
| 247 |
ziinit.z_filefunc.ztell32_file = NULL; |
| 248 |
- if (pzlib_filefunc64_32_def==NULL) |
| 249 |
- fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); |
| 250 |
- else |
| 251 |
+ if (pzlib_filefunc64_32_def==NULL) { |
| 252 |
+ //fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); |
| 253 |
+ } else |
| 254 |
ziinit.z_filefunc = *pzlib_filefunc64_32_def; |
| 255 |
|
| 256 |
ziinit.filestream = ZOPEN64(ziinit.z_filefunc, |
| 257 |
@@ -1423,8 +1423,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c |
| 258 |
{ |
| 259 |
if(zi->ci.method == Z_DEFLATED) |
| 260 |
{ |
| 261 |
- zi->ci.stream.zalloc = (alloc_func)0; |
| 262 |
- zi->ci.stream.zfree = (free_func)0; |
| 263 |
+ zi->ci.stream.zalloc = zi->z_filefunc.zfile_func64.alloc_mem; |
| 264 |
+ zi->ci.stream.zfree = zi->z_filefunc.zfile_func64.free_mem; |
| 265 |
zi->ci.stream.opaque = (voidpf)0; |
| 266 |
|
| 267 |
if (windowBits>0) |