diff options
| author | Eugene Golushkov <e.golushkov@nospam-gmail.com> | 2023-08-03 19:53:08 +0200 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2023-08-03 11:43:34 -0700 |
| commit | be7aa11551e86c9ac77ee1bff48300e59ba1e3c4 (patch) | |
| tree | c03943a46f5d22e2de6d8c858440137b23acfb9d | |
| parent | aa154e3da0d98629bbefe79cdfba8bc7178dc4ad (diff) | |
| download | zlib-be7aa11551e86c9ac77ee1bff48300e59ba1e3c4.tar.gz zlib-be7aa11551e86c9ac77ee1bff48300e59ba1e3c4.tar.bz2 zlib-be7aa11551e86c9ac77ee1bff48300e59ba1e3c4.zip | |
Read multiple bytes instead of byte-by-byte in minizip unzip.c.
Use a single ZREAD64 call in the unz64local_getShort/Long/Long64
implementation, rather than read it byte by byte.
| -rw-r--r-- | contrib/minizip/unzip.c | 134 |
1 files changed, 38 insertions, 96 deletions
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index c1c29863..7a35c866 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c | |||
| @@ -197,23 +197,24 @@ typedef struct | |||
| 197 | #include "crypt.h" | 197 | #include "crypt.h" |
| 198 | #endif | 198 | #endif |
| 199 | 199 | ||
| 200 | |||
| 200 | /* =========================================================================== | 201 | /* =========================================================================== |
| 201 | Read a byte from a gz_stream; update next_in and avail_in. Return EOF | 202 | Reads a long in LSB order from the given gz_stream. Sets |
| 202 | for end of file. | ||
| 203 | IN assertion: the stream s has been successfully opened for reading. | ||
| 204 | */ | 203 | */ |
| 205 | 204 | ||
| 206 | 205 | local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, | |
| 207 | local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) { | 206 | voidpf filestream, |
| 208 | unsigned char c; | 207 | uLong *pX) { |
| 209 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); | 208 | unsigned char c[2]; |
| 210 | if (err==1) | 209 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2); |
| 210 | if (err==2) | ||
| 211 | { | 211 | { |
| 212 | *pi = (int)c; | 212 | *pX = c[0] | ((uLong)c[1] << 8); |
| 213 | return UNZ_OK; | 213 | return UNZ_OK; |
| 214 | } | 214 | } |
| 215 | else | 215 | else |
| 216 | { | 216 | { |
| 217 | *pX = 0; | ||
| 217 | if (ZERROR64(*pzlib_filefunc_def,filestream)) | 218 | if (ZERROR64(*pzlib_filefunc_def,filestream)) |
| 218 | return UNZ_ERRNO; | 219 | return UNZ_ERRNO; |
| 219 | else | 220 | else |
| @@ -221,105 +222,46 @@ local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, v | |||
| 221 | } | 222 | } |
| 222 | } | 223 | } |
| 223 | 224 | ||
| 224 | |||
| 225 | /* =========================================================================== | ||
| 226 | Reads a long in LSB order from the given gz_stream. Sets | ||
| 227 | */ | ||
| 228 | |||
| 229 | local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def, | ||
| 230 | voidpf filestream, | ||
| 231 | uLong *pX) { | ||
| 232 | uLong x ; | ||
| 233 | int i = 0; | ||
| 234 | int err; | ||
| 235 | |||
| 236 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 237 | x = (uLong)i; | ||
| 238 | |||
| 239 | if (err==UNZ_OK) | ||
| 240 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 241 | x |= ((uLong)i)<<8; | ||
| 242 | |||
| 243 | if (err==UNZ_OK) | ||
| 244 | *pX = x; | ||
| 245 | else | ||
| 246 | *pX = 0; | ||
| 247 | return err; | ||
| 248 | } | ||
| 249 | |||
| 250 | local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, | 225 | local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 251 | voidpf filestream, | 226 | voidpf filestream, |
| 252 | uLong *pX) { | 227 | uLong *pX) { |
| 253 | uLong x ; | 228 | unsigned char c[4]; |
| 254 | int i = 0; | 229 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4); |
| 255 | int err; | 230 | if (err==4) |
| 256 | 231 | { | |
| 257 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | 232 | *pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24); |
| 258 | x = (uLong)i; | 233 | return UNZ_OK; |
| 259 | 234 | } | |
| 260 | if (err==UNZ_OK) | ||
| 261 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 262 | x |= ((uLong)i)<<8; | ||
| 263 | |||
| 264 | if (err==UNZ_OK) | ||
| 265 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 266 | x |= ((uLong)i)<<16; | ||
| 267 | |||
| 268 | if (err==UNZ_OK) | ||
| 269 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 270 | x += ((uLong)i)<<24; | ||
| 271 | |||
| 272 | if (err==UNZ_OK) | ||
| 273 | *pX = x; | ||
| 274 | else | 235 | else |
| 236 | { | ||
| 275 | *pX = 0; | 237 | *pX = 0; |
| 276 | return err; | 238 | if (ZERROR64(*pzlib_filefunc_def,filestream)) |
| 239 | return UNZ_ERRNO; | ||
| 240 | else | ||
| 241 | return UNZ_EOF; | ||
| 242 | } | ||
| 277 | } | 243 | } |
| 278 | 244 | ||
| 279 | 245 | ||
| 280 | local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, | 246 | local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def, |
| 281 | voidpf filestream, | 247 | voidpf filestream, |
| 282 | ZPOS64_T *pX) { | 248 | ZPOS64_T *pX) { |
| 283 | ZPOS64_T x ; | 249 | unsigned char c[8]; |
| 284 | int i = 0; | 250 | int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8); |
| 285 | int err; | 251 | if (err==8) |
| 286 | 252 | { | |
| 287 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | 253 | *pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24) |
| 288 | x = (ZPOS64_T)i; | 254 | | ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56); |
| 289 | 255 | return UNZ_OK; | |
| 290 | if (err==UNZ_OK) | 256 | } |
| 291 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 292 | x |= ((ZPOS64_T)i)<<8; | ||
| 293 | |||
| 294 | if (err==UNZ_OK) | ||
| 295 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 296 | x |= ((ZPOS64_T)i)<<16; | ||
| 297 | |||
| 298 | if (err==UNZ_OK) | ||
| 299 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 300 | x |= ((ZPOS64_T)i)<<24; | ||
| 301 | |||
| 302 | if (err==UNZ_OK) | ||
| 303 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 304 | x |= ((ZPOS64_T)i)<<32; | ||
| 305 | |||
| 306 | if (err==UNZ_OK) | ||
| 307 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 308 | x |= ((ZPOS64_T)i)<<40; | ||
| 309 | |||
| 310 | if (err==UNZ_OK) | ||
| 311 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 312 | x |= ((ZPOS64_T)i)<<48; | ||
| 313 | |||
| 314 | if (err==UNZ_OK) | ||
| 315 | err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); | ||
| 316 | x |= ((ZPOS64_T)i)<<56; | ||
| 317 | |||
| 318 | if (err==UNZ_OK) | ||
| 319 | *pX = x; | ||
| 320 | else | 257 | else |
| 258 | { | ||
| 321 | *pX = 0; | 259 | *pX = 0; |
| 322 | return err; | 260 | if (ZERROR64(*pzlib_filefunc_def,filestream)) |
| 261 | return UNZ_ERRNO; | ||
| 262 | else | ||
| 263 | return UNZ_EOF; | ||
| 264 | } | ||
| 323 | } | 265 | } |
| 324 | 266 | ||
| 325 | /* My own strcmpi / strcasecmp */ | 267 | /* My own strcmpi / strcasecmp */ |
| @@ -1108,7 +1050,7 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, | |||
| 1108 | pfile_info->internal_fa = file_info64.internal_fa; | 1050 | pfile_info->internal_fa = file_info64.internal_fa; |
| 1109 | pfile_info->external_fa = file_info64.external_fa; | 1051 | pfile_info->external_fa = file_info64.external_fa; |
| 1110 | 1052 | ||
| 1111 | pfile_info->tmu_date = file_info64.tmu_date, | 1053 | pfile_info->tmu_date = file_info64.tmu_date; |
| 1112 | 1054 | ||
| 1113 | 1055 | ||
| 1114 | pfile_info->compressed_size = (uLong)file_info64.compressed_size; | 1056 | pfile_info->compressed_size = (uLong)file_info64.compressed_size; |
