Mercurial > hg > orthanc
annotate OrthancFramework/Resources/ThirdParty/minizip/ioapi.c @ 5507:11a140c73bb6
upgraded to libjpeg 9f
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Jan 2024 18:02:58 +0100 |
parents | 8174e45f48d8 |
children |
rev | line source |
---|---|
102 | 1 /* ioapi.h -- IO base function header for compress/uncompress .zip |
2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | |
3 | |
4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) | |
5 | |
6 Modifications for Zip64 support | |
7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | |
8 | |
9 For more info read MiniZip_info.txt | |
10 | |
11 */ | |
12 | |
13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) | |
14 #define _CRT_SECURE_NO_WARNINGS | |
15 #endif | |
16 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
17 #if defined(__APPLE__) || defined(IOAPI_NO_64) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64) |
102 | 18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions |
19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode) | |
20 #define FTELLO_FUNC(stream) ftello(stream) | |
21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) | |
22 #else | |
23 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) | |
24 #define FTELLO_FUNC(stream) ftello64(stream) | |
25 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) | |
26 #endif | |
27 | |
28 | |
29 #include "ioapi.h" | |
30 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void*filename, int mode) { |
102 | 32 if (pfilefunc->zfile_func64.zopen64_file != NULL) |
33 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); | |
34 else | |
35 { | |
36 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); | |
37 } | |
38 } | |
39 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
40 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) { |
102 | 41 if (pfilefunc->zfile_func64.zseek64_file != NULL) |
42 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); | |
43 else | |
44 { | |
45 uLong offsetTruncated = (uLong)offset; | |
46 if (offsetTruncated != offset) | |
47 return -1; | |
48 else | |
49 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); | |
50 } | |
51 } | |
52 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
53 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream) { |
102 | 54 if (pfilefunc->zfile_func64.zseek64_file != NULL) |
55 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); | |
56 else | |
57 { | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
58 uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); |
102 | 59 if ((tell_uLong) == MAXU32) |
60 return (ZPOS64_T)-1; | |
61 else | |
62 return tell_uLong; | |
63 } | |
64 } | |
65 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
66 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32) { |
102 | 67 p_filefunc64_32->zfile_func64.zopen64_file = NULL; |
68 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; | |
69 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; | |
70 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; | |
71 p_filefunc64_32->zfile_func64.ztell64_file = NULL; | |
72 p_filefunc64_32->zfile_func64.zseek64_file = NULL; | |
73 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; | |
74 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; | |
75 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; | |
76 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; | |
77 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; | |
78 } | |
79 | |
80 | |
81 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
82 static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) { |
102 | 83 FILE* file = NULL; |
84 const char* mode_fopen = NULL; | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
85 (void)opaque; |
102 | 86 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
87 mode_fopen = "rb"; | |
88 else | |
89 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | |
90 mode_fopen = "r+b"; | |
91 else | |
92 if (mode & ZLIB_FILEFUNC_MODE_CREATE) | |
93 mode_fopen = "wb"; | |
94 | |
95 if ((filename!=NULL) && (mode_fopen != NULL)) | |
96 file = fopen(filename, mode_fopen); | |
97 return file; | |
98 } | |
99 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
100 static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void* filename, int mode) { |
102 | 101 FILE* file = NULL; |
102 const char* mode_fopen = NULL; | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
103 (void)opaque; |
102 | 104 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
105 mode_fopen = "rb"; | |
106 else | |
107 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | |
108 mode_fopen = "r+b"; | |
109 else | |
110 if (mode & ZLIB_FILEFUNC_MODE_CREATE) | |
111 mode_fopen = "wb"; | |
112 | |
113 if ((filename!=NULL) && (mode_fopen != NULL)) | |
114 file = FOPEN_FUNC((const char*)filename, mode_fopen); | |
115 return file; | |
116 } | |
117 | |
118 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
119 static uLong ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uLong size) { |
102 | 120 uLong ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
121 (void)opaque; |
102 | 122 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); |
123 return ret; | |
124 } | |
125 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
126 static uLong ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) { |
102 | 127 uLong ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
128 (void)opaque; |
102 | 129 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); |
130 return ret; | |
131 } | |
132 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
133 static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) { |
102 | 134 long ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
135 (void)opaque; |
102 | 136 ret = ftell((FILE *)stream); |
137 return ret; | |
138 } | |
139 | |
140 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
141 static ZPOS64_T ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) { |
102 | 142 ZPOS64_T ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
143 (void)opaque; |
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
144 ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream); |
102 | 145 return ret; |
146 } | |
147 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
148 static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) { |
102 | 149 int fseek_origin=0; |
150 long ret; | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
151 (void)opaque; |
102 | 152 switch (origin) |
153 { | |
154 case ZLIB_FILEFUNC_SEEK_CUR : | |
155 fseek_origin = SEEK_CUR; | |
156 break; | |
157 case ZLIB_FILEFUNC_SEEK_END : | |
158 fseek_origin = SEEK_END; | |
159 break; | |
160 case ZLIB_FILEFUNC_SEEK_SET : | |
161 fseek_origin = SEEK_SET; | |
162 break; | |
163 default: return -1; | |
164 } | |
165 ret = 0; | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
166 if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0) |
102 | 167 ret = -1; |
168 return ret; | |
169 } | |
170 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
171 static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { |
102 | 172 int fseek_origin=0; |
173 long ret; | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
174 (void)opaque; |
102 | 175 switch (origin) |
176 { | |
177 case ZLIB_FILEFUNC_SEEK_CUR : | |
178 fseek_origin = SEEK_CUR; | |
179 break; | |
180 case ZLIB_FILEFUNC_SEEK_END : | |
181 fseek_origin = SEEK_END; | |
182 break; | |
183 case ZLIB_FILEFUNC_SEEK_SET : | |
184 fseek_origin = SEEK_SET; | |
185 break; | |
186 default: return -1; | |
187 } | |
188 ret = 0; | |
189 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
190 if(FSEEKO_FUNC((FILE *)stream, (z_off64_t)offset, fseek_origin) != 0) |
102 | 191 ret = -1; |
192 | |
193 return ret; | |
194 } | |
195 | |
196 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
197 static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) { |
102 | 198 int ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
199 (void)opaque; |
102 | 200 ret = fclose((FILE *)stream); |
201 return ret; | |
202 } | |
203 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
204 static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) { |
102 | 205 int ret; |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
206 (void)opaque; |
102 | 207 ret = ferror((FILE *)stream); |
208 return ret; | |
209 } | |
210 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
211 void fill_fopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def) { |
102 | 212 pzlib_filefunc_def->zopen_file = fopen_file_func; |
213 pzlib_filefunc_def->zread_file = fread_file_func; | |
214 pzlib_filefunc_def->zwrite_file = fwrite_file_func; | |
215 pzlib_filefunc_def->ztell_file = ftell_file_func; | |
216 pzlib_filefunc_def->zseek_file = fseek_file_func; | |
217 pzlib_filefunc_def->zclose_file = fclose_file_func; | |
218 pzlib_filefunc_def->zerror_file = ferror_file_func; | |
219 pzlib_filefunc_def->opaque = NULL; | |
220 } | |
221 | |
5428
8174e45f48d8
Upgraded minizip library to stay away from CVE-2023-45853
Alain Mazy <am@osimis.io>
parents:
4044
diff
changeset
|
222 void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) { |
102 | 223 pzlib_filefunc_def->zopen64_file = fopen64_file_func; |
224 pzlib_filefunc_def->zread_file = fread_file_func; | |
225 pzlib_filefunc_def->zwrite_file = fwrite_file_func; | |
226 pzlib_filefunc_def->ztell64_file = ftell64_file_func; | |
227 pzlib_filefunc_def->zseek64_file = fseek64_file_func; | |
228 pzlib_filefunc_def->zclose_file = fclose_file_func; | |
229 pzlib_filefunc_def->zerror_file = ferror_file_func; | |
230 pzlib_filefunc_def->opaque = NULL; | |
231 } |