Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minizip: use single ZREAD64 call in unz64local_getShort/Long/Long64 #557

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 41 additions & 75 deletions contrib/minizip/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,21 @@ 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 OF((
Expand All @@ -267,30 +266,21 @@ 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 OF((
Expand All @@ -303,46 +293,22 @@ 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 */
Expand Down Expand Up @@ -1162,7 +1128,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;
Expand Down