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.
This commit is contained in:
parent
aa154e3da0
commit
be7aa11551
@ -197,30 +197,6 @@ typedef struct
|
||||
#include "crypt.h"
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
|
||||
for end of file.
|
||||
IN assertion: the stream s has been successfully opened for reading.
|
||||
*/
|
||||
|
||||
|
||||
local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) {
|
||||
unsigned char c;
|
||||
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
|
||||
if (err==1)
|
||||
{
|
||||
*pi = (int)c;
|
||||
return UNZ_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return UNZ_ERRNO;
|
||||
else
|
||||
return UNZ_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
Reads a long in LSB order from the given gz_stream. Sets
|
||||
@ -229,97 +205,63 @@ local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, v
|
||||
local int unz64local_getShort(const zlib_filefunc64_32_def* pzlib_filefunc_def,
|
||||
voidpf filestream,
|
||||
uLong *pX) {
|
||||
uLong x ;
|
||||
int i = 0;
|
||||
int err;
|
||||
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x = (uLong)i;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((uLong)i)<<8;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
*pX = x;
|
||||
unsigned char c[2];
|
||||
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,2);
|
||||
if (err==2)
|
||||
{
|
||||
*pX = c[0] | ((uLong)c[1] << 8);
|
||||
return UNZ_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pX = 0;
|
||||
return err;
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return UNZ_ERRNO;
|
||||
else
|
||||
return UNZ_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
local int unz64local_getLong(const zlib_filefunc64_32_def* pzlib_filefunc_def,
|
||||
voidpf filestream,
|
||||
uLong *pX) {
|
||||
uLong x ;
|
||||
int i = 0;
|
||||
int err;
|
||||
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x = (uLong)i;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((uLong)i)<<8;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((uLong)i)<<16;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x += ((uLong)i)<<24;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
*pX = x;
|
||||
unsigned char c[4];
|
||||
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,4);
|
||||
if (err==4)
|
||||
{
|
||||
*pX = c[0] | ((uLong)c[1] << 8) | ((uLong)c[2] << 16) | ((uLong)c[3] << 24);
|
||||
return UNZ_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pX = 0;
|
||||
return err;
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return UNZ_ERRNO;
|
||||
else
|
||||
return UNZ_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
local int unz64local_getLong64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
|
||||
voidpf filestream,
|
||||
ZPOS64_T *pX) {
|
||||
ZPOS64_T x ;
|
||||
int i = 0;
|
||||
int err;
|
||||
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x = (ZPOS64_T)i;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<8;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<16;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<24;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<32;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<40;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<48;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
x |= ((ZPOS64_T)i)<<56;
|
||||
|
||||
if (err==UNZ_OK)
|
||||
*pX = x;
|
||||
unsigned char c[8];
|
||||
int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,c,8);
|
||||
if (err==8)
|
||||
{
|
||||
*pX = c[0] | ((ZPOS64_T)c[1] << 8) | ((ZPOS64_T)c[2] << 16) | ((ZPOS64_T)c[3] << 24)
|
||||
| ((ZPOS64_T)c[4] << 32) | ((ZPOS64_T)c[5] << 40) | ((ZPOS64_T)c[6] << 48) | ((ZPOS64_T)c[7] << 56);
|
||||
return UNZ_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pX = 0;
|
||||
return err;
|
||||
if (ZERROR64(*pzlib_filefunc_def,filestream))
|
||||
return UNZ_ERRNO;
|
||||
else
|
||||
return UNZ_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
/* My own strcmpi / strcasecmp */
|
||||
@ -1108,7 +1050,7 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,
|
||||
pfile_info->internal_fa = file_info64.internal_fa;
|
||||
pfile_info->external_fa = file_info64.external_fa;
|
||||
|
||||
pfile_info->tmu_date = file_info64.tmu_date,
|
||||
pfile_info->tmu_date = file_info64.tmu_date;
|
||||
|
||||
|
||||
pfile_info->compressed_size = (uLong)file_info64.compressed_size;
|
||||
|
Loading…
Reference in New Issue
Block a user