godot-zlib-1.2.4-minizip-seek.patch 10 KB

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