empty-zip-fix.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. diff --git a/thirdparty/minizip/unzip.c b/thirdparty/minizip/unzip.c
  2. index e83aff2773..af73f06137 100644
  3. --- a/thirdparty/minizip/unzip.c
  4. +++ b/thirdparty/minizip/unzip.c
  5. @@ -408,6 +408,12 @@ extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
  6. #define BUFREADCOMMENT (0x400)
  7. #endif
  8. +/* GODOT start */
  9. +#ifndef CENTRALDIRINVALID
  10. +#define CENTRALDIRINVALID (0xffffffffffffffff)
  11. +#endif
  12. +/* GODOT end */
  13. +
  14. /*
  15. Locate the Central directory of a zipfile (at the end, just before
  16. the global comment)
  17. @@ -419,10 +425,14 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
  18. ZPOS64_T uSizeFile;
  19. ZPOS64_T uBackRead;
  20. ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  21. - ZPOS64_T uPosFound=0;
  22. + /* GODOT start */
  23. + ZPOS64_T uPosFound=CENTRALDIRINVALID;
  24. + /* GODOT end */
  25. if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  26. - return 0;
  27. + /* GODOT start */
  28. + return CENTRALDIRINVALID;
  29. + /* GODOT end */
  30. uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  31. @@ -432,7 +442,9 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
  32. buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  33. if (buf==NULL)
  34. - return 0;
  35. + /* GODOT start */
  36. + return CENTRALDIRINVALID;
  37. + /* GODOT end */
  38. uBackRead = 4;
  39. while (uBackRead<uMaxBack)
  40. @@ -462,7 +474,9 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
  41. break;
  42. }
  43. - if (uPosFound!=0)
  44. + /* GODOT start */
  45. + if (uPosFound!=CENTRALDIRINVALID)
  46. + /* GODOT end */
  47. break;
  48. }
  49. TRYFREE(buf);
  50. @@ -485,12 +499,16 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
  51. ZPOS64_T uSizeFile;
  52. ZPOS64_T uBackRead;
  53. ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  54. - ZPOS64_T uPosFound=0;
  55. + /* GODOT start */
  56. + ZPOS64_T uPosFound=CENTRALDIRINVALID;
  57. + /* GODOT end */
  58. uLong uL;
  59. ZPOS64_T relativeOffset;
  60. if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  61. - return 0;
  62. + /* GODOT start */
  63. + return CENTRALDIRINVALID;
  64. + /* GODOT end */
  65. uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  66. @@ -500,7 +518,9 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
  67. buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  68. if (buf==NULL)
  69. - return 0;
  70. + /* GODOT start */
  71. + return CENTRALDIRINVALID;
  72. + /* GODOT end */
  73. uBackRead = 4;
  74. while (uBackRead<uMaxBack)
  75. @@ -530,47 +550,71 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
  76. break;
  77. }
  78. - if (uPosFound!=0)
  79. + /* GODOT start */
  80. + if (uPosFound!=CENTRALDIRINVALID)
  81. + /* GODOT end */
  82. break;
  83. }
  84. TRYFREE(buf);
  85. - if (uPosFound == 0)
  86. - return 0;
  87. + /* GODOT start */
  88. + if (uPosFound == CENTRALDIRINVALID)
  89. + return CENTRALDIRINVALID;
  90. + /* GODOT end */
  91. /* Zip64 end of central directory locator */
  92. if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
  93. - return 0;
  94. + /* GODOT start */
  95. + return CENTRALDIRINVALID;
  96. + /* GODOT end */
  97. /* the signature, already checked */
  98. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  99. - return 0;
  100. + /* GODOT start */
  101. + return CENTRALDIRINVALID;
  102. + /* GODOT end */
  103. /* number of the disk with the start of the zip64 end of central directory */
  104. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  105. - return 0;
  106. + /* GODOT start */
  107. + return CENTRALDIRINVALID;
  108. + /* GODOT end */
  109. if (uL != 0)
  110. - return 0;
  111. + /* GODOT start */
  112. + return CENTRALDIRINVALID;
  113. + /* GODOT end */
  114. /* relative offset of the zip64 end of central directory record */
  115. if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
  116. - return 0;
  117. + /* GODOT start */
  118. + return CENTRALDIRINVALID;
  119. + /* GODOT end */
  120. /* total number of disks */
  121. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  122. - return 0;
  123. + /* GODOT start */
  124. + return CENTRALDIRINVALID;
  125. + /* GODOT end */
  126. if (uL != 1)
  127. - return 0;
  128. + /* GODOT start */
  129. + return CENTRALDIRINVALID;
  130. + /* GODOT end */
  131. /* Goto end of central directory record */
  132. if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
  133. - return 0;
  134. + /* GODOT start */
  135. + return CENTRALDIRINVALID;
  136. + /* GODOT end */
  137. /* the signature */
  138. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  139. - return 0;
  140. + /* GODOT start */
  141. + return CENTRALDIRINVALID;
  142. + /* GODOT end */
  143. if (uL != 0x06064b50)
  144. - return 0;
  145. + /* GODOT start */
  146. + return CENTRALDIRINVALID;
  147. + /* GODOT end */
  148. return relativeOffset;
  149. }
  150. @@ -625,7 +669,9 @@ local unzFile unzOpenInternal (const void *path,
  151. return NULL;
  152. central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
  153. - if (central_pos)
  154. + /* GODOT start */
  155. + if (central_pos != CENTRALDIRINVALID)
  156. + /* GODOT end */
  157. {
  158. uLong uS;
  159. ZPOS64_T uL64;
  160. @@ -687,7 +733,9 @@ local unzFile unzOpenInternal (const void *path,
  161. else
  162. {
  163. central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
  164. - if (central_pos==0)
  165. + /* GODOT start */
  166. + if (central_pos==CENTRALDIRINVALID)
  167. + /* GODOT end */
  168. err=UNZ_ERRNO;
  169. us.isZip64 = 0;