Rizin
unix-like reverse engineering framework and cli tools
unzip.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "unzip.h"
#include <errno.h>

Go to the source code of this file.

Classes

struct  unz_file_info64_internal_s
 
struct  file_in_zip64_read_info_s
 
struct  unz64_s
 

Macros

#define NOUNCRYPT
 
#define local   static
 
#define CASESENSITIVITYDEFAULT_NO
 
#define UNZ_BUFSIZE   (16384)
 
#define UNZ_MAXFILENAMEINZIP   (256)
 
#define ALLOC(size)   (malloc(size))
 
#define TRYFREE(p)   {if (p) free(p);}
 
#define SIZECENTRALDIRITEM   (0x2e)
 
#define SIZEZIPLOCALHEADER   (0x1e)
 
#define CASESENSITIVITYDEFAULTVALUE   2
 
#define STRCMPCASENOSENTIVEFUNCTION   strcmpcasenosensitive_internal
 
#define BUFREADCOMMENT   (0x400)
 

Typedefs

typedef struct unz_file_info64_internal_s unz_file_info64_internal
 

Functions

int unz64local_getByte OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi))
 
int unz64local_getByte (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
 
int unz64local_getShort OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX))
 
int unz64local_getShort (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
int unz64local_getLong (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
 
int unz64local_getLong64 OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX))
 
int unz64local_getLong64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
 
int strcmpcasenosensitive_internal (const char *fileName1, const char *fileName2)
 
int ZEXPORT unzStringFileNameCompare (const char *fileName1, const char *fileName2, int iCaseSensitivity)
 
ZPOS64_T unz64local_SearchCentralDir OF ((const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream))
 
ZPOS64_T unz64local_SearchCentralDir (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
ZPOS64_T unz64local_SearchCentralDir64 (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
 
unzFile unzOpenInternal (const void *path, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, int is64bitOpenFunction)
 
unzFile ZEXPORT unzOpen2 (const char *path, zlib_filefunc_def *pzlib_filefunc32_def)
 
unzFile ZEXPORT unzOpen2_64 (const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
 
unzFile ZEXPORT unzOpen (const char *path)
 
unzFile ZEXPORT unzOpen64 (const void *path)
 
int ZEXPORT unzClose (unzFile file)
 
int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64 *pglobal_info)
 
int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info32)
 
void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz *ptm)
 
int unz64local_GetCurrentFileInfoInternal OF ((unzFile file, unz_file_info64 *pfile_info, unz_file_info64_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize))
 
int unz64local_GetCurrentFileInfoInternal (unzFile file, unz_file_info64 *pfile_info, unz_file_info64_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
 
int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
 
int ZEXPORT unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
 
int ZEXPORT unzGoToFirstFile (unzFile file)
 
int ZEXPORT unzGoToNextFile (unzFile file)
 
int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
 
int ZEXPORT unzGetFilePos64 (unzFile file, unz64_file_pos *file_pos)
 
int ZEXPORT unzGetFilePos (unzFile file, unz_file_pos *file_pos)
 
int ZEXPORT unzGoToFilePos64 (unzFile file, const unz64_file_pos *file_pos)
 
int ZEXPORT unzGoToFilePos (unzFile file, unz_file_pos *file_pos)
 
int unz64local_CheckCurrentFileCoherencyHeader (unz64_s *s, uInt *piSizeVar, ZPOS64_T *poffset_local_extrafield, uInt *psize_local_extrafield)
 
int ZEXPORT unzOpenCurrentFile3 (unzFile file, int *method, int *level, int raw, const char *password)
 
int ZEXPORT unzOpenCurrentFile (unzFile file)
 
int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char *password)
 
int ZEXPORT unzOpenCurrentFile2 (unzFile file, int *method, int *level, int raw)
 
ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 (unzFile file)
 
int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
 
z_off_t ZEXPORT unztell (unzFile file)
 
ZPOS64_T ZEXPORT unztell64 (unzFile file)
 
int ZEXPORT unzeof (unzFile file)
 
int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
 
int ZEXPORT unzCloseCurrentFile (unzFile file)
 
int ZEXPORT unzGetGlobalComment (unzFile file, char *szComment, uLong uSizeBuf)
 
ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file)
 
uLong ZEXPORT unzGetOffset (unzFile file)
 
int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos)
 
int ZEXPORT unzSetOffset (unzFile file, uLong pos)
 

Variables

const char unz_copyright []
 

Macro Definition Documentation

◆ ALLOC

#define ALLOC (   size)    (malloc(size))

Definition at line 112 of file unzip.c.

◆ BUFREADCOMMENT

#define BUFREADCOMMENT   (0x400)

Definition at line 405 of file unzip.c.

◆ CASESENSITIVITYDEFAULT_NO

#define CASESENSITIVITYDEFAULT_NO

Definition at line 98 of file unzip.c.

◆ CASESENSITIVITYDEFAULTVALUE

#define CASESENSITIVITYDEFAULTVALUE   2

Definition at line 372 of file unzip.c.

◆ local

#define local   static

Definition at line 91 of file unzip.c.

◆ NOUNCRYPT

#define NOUNCRYPT

Definition at line 72 of file unzip.c.

◆ SIZECENTRALDIRITEM

#define SIZECENTRALDIRITEM   (0x2e)

Definition at line 118 of file unzip.c.

◆ SIZEZIPLOCALHEADER

#define SIZEZIPLOCALHEADER   (0x1e)

Definition at line 119 of file unzip.c.

◆ STRCMPCASENOSENTIVEFUNCTION

#define STRCMPCASENOSENTIVEFUNCTION   strcmpcasenosensitive_internal

Definition at line 378 of file unzip.c.

◆ TRYFREE

#define TRYFREE (   p)    {if (p) free(p);}

Definition at line 115 of file unzip.c.

◆ UNZ_BUFSIZE

#define UNZ_BUFSIZE   (16384)

Definition at line 104 of file unzip.c.

◆ UNZ_MAXFILENAMEINZIP

#define UNZ_MAXFILENAMEINZIP   (256)

Definition at line 108 of file unzip.c.

Typedef Documentation

◆ unz_file_info64_internal

Function Documentation

◆ OF() [1/5]

ZPOS64_T unz64local_SearchCentralDir OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)  )

◆ OF() [2/5]

int unz64local_getByte OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)  )

◆ OF() [3/5]

int unz64local_getShort OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)  )

◆ OF() [4/5]

int unz64local_getLong64 OF ( (const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)  )

◆ OF() [5/5]

int unz64local_GetCurrentFileInfoInternal OF ( (unzFile file, unz_file_info64 *pfile_info, unz_file_info64_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)  )

◆ strcmpcasenosensitive_internal()

int strcmpcasenosensitive_internal ( const char *  fileName1,
const char *  fileName2 
)

Definition at line 349 of file unzip.c.

350 {
351  for (;;)
352  {
353  char c1=*(fileName1++);
354  char c2=*(fileName2++);
355  if ((c1>='a') && (c1<='z'))
356  c1 -= 0x20;
357  if ((c2>='a') && (c2<='z'))
358  c2 -= 0x20;
359  if (c1=='\0')
360  return ((c2=='\0') ? 0 : -1);
361  if (c2=='\0')
362  return 1;
363  if (c1<c2)
364  return -1;
365  if (c1>c2)
366  return 1;
367  }
368 }
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c1
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c2

References c1, and c2.

◆ unz64local_CheckCurrentFileCoherencyHeader()

int unz64local_CheckCurrentFileCoherencyHeader ( unz64_s s,
uInt piSizeVar,
ZPOS64_T poffset_local_extrafield,
uInt psize_local_extrafield 
)

Definition at line 1385 of file unzip.c.

1388 {
1389  uLong uMagic,uData,uFlags;
1390  uLong size_filename;
1391  uLong size_extra_field;
1392  int err=UNZ_OK;
1393 
1394  *piSizeVar = 0;
1395  *poffset_local_extrafield = 0;
1396  *psize_local_extrafield = 0;
1397 
1398  if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
1399  s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
1400  return UNZ_ERRNO;
1401 
1402 
1403  if (err==UNZ_OK)
1404  {
1405  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
1406  err=UNZ_ERRNO;
1407  else if (uMagic!=0x04034b50)
1409  }
1410 
1411  if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1412  err=UNZ_ERRNO;
1413 /*
1414  else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
1415  err=UNZ_BADZIPFILE;
1416 */
1417  if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
1418  err=UNZ_ERRNO;
1419 
1420  if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
1421  err=UNZ_ERRNO;
1422  else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1424 
1425  if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1426 /* #ifdef HAVE_BZIP2 */
1427  (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1428 /* #endif */
1429  (s->cur_file_info.compression_method!=Z_DEFLATED))
1431 
1432  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1433  err=UNZ_ERRNO;
1434 
1435  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1436  err=UNZ_ERRNO;
1437  else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
1439 
1440  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1441  err=UNZ_ERRNO;
1442  else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
1444 
1445  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1446  err=UNZ_ERRNO;
1447  else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
1449 
1450  if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1451  err=UNZ_ERRNO;
1452  else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1454 
1455  *piSizeVar += (uInt)size_filename;
1456 
1457  if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1458  err=UNZ_ERRNO;
1459  *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1460  SIZEZIPLOCALHEADER + size_filename;
1461  *psize_local_extrafield = (uInt)size_extra_field;
1462 
1463  *piSizeVar += (uInt)size_extra_field;
1464 
1465  return err;
1466 }
static bool err
Definition: armass.c:435
#define ZSEEK64(filefunc, filestream, pos, mode)
Definition: ioapi.h:204
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:116
static RzSocket * s
Definition: rtr.c:28
#define SIZEZIPLOCALHEADER
Definition: unzip.c:119
int unz64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: unzip.c:266
int unz64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
Definition: unzip.c:239
#define UNZ_BADZIPFILE
Definition: unzip.h:79
#define UNZ_ERRNO
Definition: unzip.h:76
#define UNZ_OK
Definition: unzip.h:74
#define Z_BZIP2ED
Definition: unzip.h:62
unsigned long uLong
Definition: zconf.h:394
unsigned int uInt
Definition: zconf.h:393
#define Z_DEFLATED
Definition: zlib.h:209

References err, s, SIZEZIPLOCALHEADER, unz64local_getLong(), unz64local_getShort(), UNZ_BADZIPFILE, UNZ_ERRNO, UNZ_OK, Z_BZIP2ED, Z_DEFLATED, ZLIB_FILEFUNC_SEEK_SET, and ZSEEK64.

Referenced by unzOpenCurrentFile3().

◆ unz64local_DosDateToTmuDate()

void unz64local_DosDateToTmuDate ( ZPOS64_T  ulDosDate,
tm_unz ptm 
)

Definition at line 852 of file unzip.c.

853 {
854  ZPOS64_T uDate;
855  uDate = (ZPOS64_T)(ulDosDate>>16);
856  ptm->tm_mday = (int)(uDate&0x1f) ;
857  ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
858  ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;
859 
860  ptm->tm_hour = (int) ((ulDosDate &0xF800)/0x800);
861  ptm->tm_min = (int) ((ulDosDate&0x7E0)/0x20) ;
862  ptm->tm_sec = (int) (2*(ulDosDate&0x1f)) ;
863 }
unsigned long long int ZPOS64_T
Definition: ioapi.h:99
static int
Definition: sfsocketcall.h:114
int tm_mday
Definition: unzip.h:89
int tm_mon
Definition: unzip.h:90
int tm_hour
Definition: unzip.h:88
int tm_year
Definition: unzip.h:91
int tm_sec
Definition: unzip.h:86
int tm_min
Definition: unzip.h:87

References int, tm_unz_s::tm_hour, tm_unz_s::tm_mday, tm_unz_s::tm_min, tm_unz_s::tm_mon, tm_unz_s::tm_sec, and tm_unz_s::tm_year.

Referenced by unz64local_GetCurrentFileInfoInternal().

◆ unz64local_getByte()

int unz64local_getByte ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
int pi 
)

Definition at line 212 of file unzip.c.

213 {
214  unsigned char c;
215  int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
216  if (err==1)
217  {
218  *pi = (int)c;
219  return UNZ_OK;
220  }
221  else
222  {
223  if (ZERROR64(*pzlib_filefunc_def,filestream))
224  return UNZ_ERRNO;
225  else
226  return UNZ_EOF;
227  }
228 }
#define ZERROR64(filefunc, filestream)
Definition: ioapi.h:194
#define ZREAD64(filefunc, filestream, buf, size)
Definition: ioapi.h:189
#define c(i)
Definition: sha256.c:43
#define UNZ_EOF
Definition: unzip.h:77

References c, err, int, UNZ_EOF, UNZ_ERRNO, UNZ_OK, ZERROR64, and ZREAD64.

Referenced by unz64local_getLong(), unz64local_getLong64(), and unz64local_getShort().

◆ unz64local_GetCurrentFileInfoInternal()

int unz64local_GetCurrentFileInfoInternal ( unzFile  file,
unz_file_info64 pfile_info,
unz_file_info64_internal pfile_info_internal,
char *  szFileName,
uLong  fileNameBufferSize,
void *  extraField,
uLong  extraFieldBufferSize,
char *  szComment,
uLong  commentBufferSize 
)

Definition at line 879 of file unzip.c.

889 {
890  unz64_s* s;
891  unz_file_info64 file_info;
892  unz_file_info64_internal file_info_internal;
893  int err=UNZ_OK;
894  uLong uMagic;
895  long lSeek=0;
896  uLong uL;
897 
898  if (file==NULL)
899  return UNZ_PARAMERROR;
900  s=(unz64_s*)file;
901  if (ZSEEK64(s->z_filefunc, s->filestream,
902  s->pos_in_central_dir+s->byte_before_the_zipfile,
904  err=UNZ_ERRNO;
905 
906 
907  /* we check the magic */
908  if (err==UNZ_OK)
909  {
910  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
911  err=UNZ_ERRNO;
912  else if (uMagic!=0x02014b50)
914  }
915 
916  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
917  err=UNZ_ERRNO;
918 
919  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
920  err=UNZ_ERRNO;
921 
922  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
923  err=UNZ_ERRNO;
924 
925  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
926  err=UNZ_ERRNO;
927 
928  if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
929  err=UNZ_ERRNO;
930 
931  unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
932 
933  if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
934  err=UNZ_ERRNO;
935 
936  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
937  err=UNZ_ERRNO;
938  file_info.compressed_size = uL;
939 
940  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
941  err=UNZ_ERRNO;
942  file_info.uncompressed_size = uL;
943 
944  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
945  err=UNZ_ERRNO;
946 
947  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
948  err=UNZ_ERRNO;
949 
950  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
951  err=UNZ_ERRNO;
952 
953  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
954  err=UNZ_ERRNO;
955 
956  if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
957  err=UNZ_ERRNO;
958 
959  if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
960  err=UNZ_ERRNO;
961 
962  // relative offset of local header
963  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
964  err=UNZ_ERRNO;
965  file_info_internal.offset_curfile = uL;
966 
967  lSeek+=file_info.size_filename;
968  if ((err==UNZ_OK) && (szFileName!=NULL))
969  {
970  uLong uSizeRead ;
971  if (file_info.size_filename<fileNameBufferSize)
972  {
973  *(szFileName+file_info.size_filename)='\0';
974  uSizeRead = file_info.size_filename;
975  }
976  else
977  uSizeRead = fileNameBufferSize;
978 
979  if ((file_info.size_filename>0) && (fileNameBufferSize>0))
980  if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
981  err=UNZ_ERRNO;
982  lSeek -= uSizeRead;
983  }
984 
985  // Read extrafield
986  if ((err==UNZ_OK) && (extraField!=NULL))
987  {
988  ZPOS64_T uSizeRead ;
989  if (file_info.size_file_extra<extraFieldBufferSize)
990  uSizeRead = file_info.size_file_extra;
991  else
992  uSizeRead = extraFieldBufferSize;
993 
994  if (lSeek!=0)
995  {
996  if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
997  lSeek=0;
998  else
999  err=UNZ_ERRNO;
1000  }
1001 
1002  if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
1003  if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
1004  err=UNZ_ERRNO;
1005 
1006  lSeek += file_info.size_file_extra - (uLong)uSizeRead;
1007  }
1008  else
1009  lSeek += file_info.size_file_extra;
1010 
1011 
1012  if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
1013  {
1014  uLong acc = 0;
1015 
1016  // since lSeek now points to after the extra field we need to move back
1017  lSeek -= file_info.size_file_extra;
1018 
1019  if (lSeek!=0)
1020  {
1021  if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1022  lSeek=0;
1023  else
1024  err=UNZ_ERRNO;
1025  }
1026 
1027  while(acc < file_info.size_file_extra)
1028  {
1029  uLong headerId;
1030  uLong dataSize;
1031 
1032  if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
1033  err=UNZ_ERRNO;
1034 
1035  if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
1036  err=UNZ_ERRNO;
1037 
1038  /* ZIP64 extra fields */
1039  if (headerId == 0x0001)
1040  {
1041  uLong uL;
1042 
1043  if(file_info.uncompressed_size == MAXU32)
1044  {
1045  if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1046  err=UNZ_ERRNO;
1047  }
1048 
1049  if(file_info.compressed_size == MAXU32)
1050  {
1051  if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1052  err=UNZ_ERRNO;
1053  }
1054 
1055  if(file_info_internal.offset_curfile == MAXU32)
1056  {
1057  /* Relative Header offset */
1058  if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1059  err=UNZ_ERRNO;
1060  }
1061 
1062  if(file_info.disk_num_start == MAXU32)
1063  {
1064  /* Disk Start Number */
1065  if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1066  err=UNZ_ERRNO;
1067  }
1068 
1069  }
1070  else
1071  {
1072  if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
1073  err=UNZ_ERRNO;
1074  }
1075 
1076  acc += 2 + 2 + dataSize;
1077  }
1078  }
1079 
1080  if ((err==UNZ_OK) && (szComment!=NULL))
1081  {
1082  uLong uSizeRead ;
1083  if (file_info.size_file_comment<commentBufferSize)
1084  {
1085  *(szComment+file_info.size_file_comment)='\0';
1086  uSizeRead = file_info.size_file_comment;
1087  }
1088  else
1089  uSizeRead = commentBufferSize;
1090 
1091  if (lSeek!=0)
1092  {
1093  if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1094  lSeek=0;
1095  else
1096  err=UNZ_ERRNO;
1097  }
1098 
1099  if ((file_info.size_file_comment>0) && (commentBufferSize>0))
1100  if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
1101  err=UNZ_ERRNO;
1102  lSeek+=file_info.size_file_comment - uSizeRead;
1103  }
1104  else
1105  lSeek+=file_info.size_file_comment;
1106 
1107 
1108  if ((err==UNZ_OK) && (pfile_info!=NULL))
1109  *pfile_info=file_info;
1110 
1111  if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
1112  *pfile_info_internal=file_info_internal;
1113 
1114  return err;
1115 }
#define NULL
Definition: cris-opc.c:27
#define ZLIB_FILEFUNC_SEEK_CUR
Definition: ioapi.h:114
#define MAXU32
Definition: ioapi.h:106
Definition: gzappend.c:170
Definition: unzip.c:166
uLong size_file_extra
Definition: unzip.h:122
uLong internal_fa
Definition: unzip.h:126
uLong version
Definition: unzip.h:113
ZPOS64_T uncompressed_size
Definition: unzip.h:120
uLong dosDate
Definition: unzip.h:117
tm_unz tmu_date
Definition: unzip.h:129
uLong size_filename
Definition: unzip.h:121
uLong compression_method
Definition: unzip.h:116
uLong external_fa
Definition: unzip.h:127
uLong version_needed
Definition: unzip.h:114
uLong disk_num_start
Definition: unzip.h:125
ZPOS64_T compressed_size
Definition: unzip.h:119
uLong size_file_comment
Definition: unzip.h:123
void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz *ptm)
Definition: unzip.c:852
int unz64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
Definition: unzip.c:302
#define UNZ_PARAMERROR
Definition: unzip.h:78

References unz_file_info64_s::compressed_size, unz_file_info64_s::compression_method, unz_file_info64_s::crc, unz_file_info64_s::disk_num_start, unz_file_info64_s::dosDate, err, unz_file_info64_s::external_fa, unz_file_info64_s::flag, unz_file_info64_s::internal_fa, MAXU32, NULL, unz_file_info64_internal_s::offset_curfile, s, unz_file_info64_s::size_file_comment, unz_file_info64_s::size_file_extra, unz_file_info64_s::size_filename, unz_file_info64_s::tmu_date, unz_file_info64_s::uncompressed_size, unz64local_DosDateToTmuDate(), unz64local_getLong(), unz64local_getLong64(), unz64local_getShort(), UNZ_BADZIPFILE, UNZ_ERRNO, UNZ_OK, UNZ_PARAMERROR, unz_file_info64_s::version, unz_file_info64_s::version_needed, ZLIB_FILEFUNC_SEEK_CUR, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, and ZSEEK64.

Referenced by unzGetCurrentFileInfo(), unzGetCurrentFileInfo64(), unzGoToFilePos64(), unzGoToFirstFile(), unzGoToNextFile(), and unzSetOffset64().

◆ unz64local_getLong()

int unz64local_getLong ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
uLong pX 
)

Definition at line 266 of file unzip.c.

269 {
270  uLong x ;
271  int i = 0;
272  int err;
273 
274  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
275  x = (uLong)i;
276 
277  if (err==UNZ_OK)
278  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
279  x |= ((uLong)i)<<8;
280 
281  if (err==UNZ_OK)
282  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
283  x |= ((uLong)i)<<16;
284 
285  if (err==UNZ_OK)
286  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
287  x += ((uLong)i)<<24;
288 
289  if (err==UNZ_OK)
290  *pX = x;
291  else
292  *pX = 0;
293  return err;
294 }
lzma_index ** i
Definition: index.h:629
int x
Definition: mipsasm.c:20
int unz64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
Definition: unzip.c:212

References err, i, unz64local_getByte(), UNZ_OK, and x.

Referenced by unz64local_CheckCurrentFileCoherencyHeader(), unz64local_GetCurrentFileInfoInternal(), unz64local_SearchCentralDir64(), and unzOpenInternal().

◆ unz64local_getLong64()

int unz64local_getLong64 ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
ZPOS64_T pX 
)

Definition at line 302 of file unzip.c.

305 {
306  ZPOS64_T x ;
307  int i = 0;
308  int err;
309 
310  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
311  x = (ZPOS64_T)i;
312 
313  if (err==UNZ_OK)
314  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
315  x |= ((ZPOS64_T)i)<<8;
316 
317  if (err==UNZ_OK)
318  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
319  x |= ((ZPOS64_T)i)<<16;
320 
321  if (err==UNZ_OK)
322  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
323  x |= ((ZPOS64_T)i)<<24;
324 
325  if (err==UNZ_OK)
326  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
327  x |= ((ZPOS64_T)i)<<32;
328 
329  if (err==UNZ_OK)
330  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
331  x |= ((ZPOS64_T)i)<<40;
332 
333  if (err==UNZ_OK)
334  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
335  x |= ((ZPOS64_T)i)<<48;
336 
337  if (err==UNZ_OK)
338  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
339  x |= ((ZPOS64_T)i)<<56;
340 
341  if (err==UNZ_OK)
342  *pX = x;
343  else
344  *pX = 0;
345  return err;
346 }

References err, i, unz64local_getByte(), UNZ_OK, and x.

Referenced by unz64local_GetCurrentFileInfoInternal(), unz64local_SearchCentralDir64(), and unzOpenInternal().

◆ unz64local_getShort()

int unz64local_getShort ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream,
uLong pX 
)

Definition at line 239 of file unzip.c.

242 {
243  uLong x ;
244  int i = 0;
245  int err;
246 
247  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
248  x = (uLong)i;
249 
250  if (err==UNZ_OK)
251  err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
252  x |= ((uLong)i)<<8;
253 
254  if (err==UNZ_OK)
255  *pX = x;
256  else
257  *pX = 0;
258  return err;
259 }

References err, i, unz64local_getByte(), UNZ_OK, and x.

Referenced by unz64local_CheckCurrentFileCoherencyHeader(), unz64local_GetCurrentFileInfoInternal(), and unzOpenInternal().

◆ unz64local_SearchCentralDir()

ZPOS64_T unz64local_SearchCentralDir ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)

Definition at line 413 of file unzip.c.

414 {
415  unsigned char* buf;
416  ZPOS64_T uSizeFile;
417  ZPOS64_T uBackRead;
418  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
419  ZPOS64_T uPosFound=0;
420 
421  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
422  return 0;
423 
424 
425  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
426 
427  if (uMaxBack>uSizeFile)
428  uMaxBack = uSizeFile;
429 
430  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
431  if (buf==NULL)
432  return 0;
433 
434  uBackRead = 4;
435  while (uBackRead<uMaxBack)
436  {
437  uLong uReadSize;
438  ZPOS64_T uReadPos ;
439  int i;
440  if (uBackRead+BUFREADCOMMENT>uMaxBack)
441  uBackRead = uMaxBack;
442  else
443  uBackRead+=BUFREADCOMMENT;
444  uReadPos = uSizeFile-uBackRead ;
445 
446  uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
447  (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
448  if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
449  break;
450 
451  if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
452  break;
453 
454  for (i=(int)uReadSize-3; (i--)>0;)
455  if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
456  ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
457  {
458  uPosFound = uReadPos+(unsigned)i;
459  break;
460  }
461 
462  if (uPosFound!=0)
463  break;
464  }
465  TRYFREE(buf);
466  return uPosFound;
467 }
voidpf void * buf
Definition: ioapi.h:138
#define ZTELL64(filefunc, filestream)
Definition: ioapi.h:203
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:115
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
Definition: sflib.h:97
#define BUFREADCOMMENT
Definition: unzip.c:405
#define TRYFREE(p)
Definition: unzip.c:115
#define ALLOC(size)
Definition: unzip.c:112

References ALLOC, BUFREADCOMMENT, i, NULL, TRYFREE, unsigned, ZLIB_FILEFUNC_SEEK_END, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, ZSEEK64, and ZTELL64.

Referenced by unzOpenInternal().

◆ unz64local_SearchCentralDir64()

ZPOS64_T unz64local_SearchCentralDir64 ( const zlib_filefunc64_32_def pzlib_filefunc_def,
voidpf  filestream 
)

Definition at line 478 of file unzip.c.

480 {
481  unsigned char* buf;
482  ZPOS64_T uSizeFile;
483  ZPOS64_T uBackRead;
484  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
485  ZPOS64_T uPosFound=0;
486  uLong uL;
487  ZPOS64_T relativeOffset;
488 
489  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
490  return 0;
491 
492 
493  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
494 
495  if (uMaxBack>uSizeFile)
496  uMaxBack = uSizeFile;
497 
498  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
499  if (buf==NULL)
500  return 0;
501 
502  uBackRead = 4;
503  while (uBackRead<uMaxBack)
504  {
505  uLong uReadSize;
506  ZPOS64_T uReadPos;
507  int i;
508  if (uBackRead+BUFREADCOMMENT>uMaxBack)
509  uBackRead = uMaxBack;
510  else
511  uBackRead+=BUFREADCOMMENT;
512  uReadPos = uSizeFile-uBackRead ;
513 
514  uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
515  (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
516  if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
517  break;
518 
519  if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
520  break;
521 
522  for (i=(int)uReadSize-3; (i--)>0;)
523  if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
524  ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
525  {
526  uPosFound = uReadPos+(unsigned)i;
527  break;
528  }
529 
530  if (uPosFound!=0)
531  break;
532  }
533  TRYFREE(buf);
534  if (uPosFound == 0)
535  return 0;
536 
537  /* Zip64 end of central directory locator */
538  if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
539  return 0;
540 
541  /* the signature, already checked */
542  if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
543  return 0;
544 
545  /* number of the disk with the start of the zip64 end of central directory */
546  if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
547  return 0;
548  if (uL != 0)
549  return 0;
550 
551  /* relative offset of the zip64 end of central directory record */
552  if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
553  return 0;
554 
555  /* total number of disks */
556  if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
557  return 0;
558  if (uL != 1)
559  return 0;
560 
561  /* Goto end of central directory record */
562  if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
563  return 0;
564 
565  /* the signature */
566  if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
567  return 0;
568 
569  if (uL != 0x06064b50)
570  return 0;
571 
572  return relativeOffset;
573 }

References ALLOC, BUFREADCOMMENT, i, NULL, TRYFREE, unsigned, unz64local_getLong(), unz64local_getLong64(), UNZ_OK, ZLIB_FILEFUNC_SEEK_END, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, ZSEEK64, and ZTELL64.

Referenced by unzOpenInternal().

◆ unzClose()

int ZEXPORT unzClose ( unzFile  file)

Definition at line 808 of file unzip.c.

809 {
810  unz64_s* s;
811  if (file==NULL)
812  return UNZ_PARAMERROR;
813  s=(unz64_s*)file;
814 
815  if (s->pfile_in_zip_read!=NULL)
817 
818  ZCLOSE64(s->z_filefunc, s->filestream);
819  TRYFREE(s);
820  return UNZ_OK;
821 }
#define ZCLOSE64(filefunc, filestream)
Definition: ioapi.h:193
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:2007

References NULL, s, TRYFREE, UNZ_OK, UNZ_PARAMERROR, unzCloseCurrentFile(), and ZCLOSE64.

Referenced by main().

◆ unzCloseCurrentFile()

int ZEXPORT unzCloseCurrentFile ( unzFile  file)

Definition at line 2007 of file unzip.c.

2008 {
2009  int err=UNZ_OK;
2010 
2011  unz64_s* s;
2012  file_in_zip64_read_info_s* pfile_in_zip_read_info;
2013  if (file==NULL)
2014  return UNZ_PARAMERROR;
2015  s=(unz64_s*)file;
2016  pfile_in_zip_read_info=s->pfile_in_zip_read;
2017 
2018  if (pfile_in_zip_read_info==NULL)
2019  return UNZ_PARAMERROR;
2020 
2021 
2022  if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
2023  (!pfile_in_zip_read_info->raw))
2024  {
2025  if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
2026  err=UNZ_CRCERROR;
2027  }
2028 
2029 
2030  TRYFREE(pfile_in_zip_read_info->read_buffer);
2031  pfile_in_zip_read_info->read_buffer = NULL;
2032  if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
2033  inflateEnd(&pfile_in_zip_read_info->stream);
2034 #ifdef HAVE_BZIP2
2035  else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
2036  BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2037 #endif
2038 
2039 
2040  pfile_in_zip_read_info->stream_initialised = 0;
2041  TRYFREE(pfile_in_zip_read_info);
2042 
2043  s->pfile_in_zip_read=NULL;
2044 
2045  return err;
2046 }
int ZEXPORT inflateEnd(z_streamp strm)
Definition: inflate.c:1301
ZPOS64_T rest_read_uncompressed
Definition: unzip.c:154
#define UNZ_CRCERROR
Definition: unzip.h:81

References file_in_zip64_read_info_s::crc32, file_in_zip64_read_info_s::crc32_wait, err, inflateEnd(), NULL, file_in_zip64_read_info_s::raw, file_in_zip64_read_info_s::read_buffer, file_in_zip64_read_info_s::rest_read_uncompressed, s, file_in_zip64_read_info_s::stream, file_in_zip64_read_info_s::stream_initialised, TRYFREE, UNZ_CRCERROR, UNZ_OK, UNZ_PARAMERROR, Z_BZIP2ED, and Z_DEFLATED.

Referenced by do_extract_currentfile(), unzClose(), and unzOpenCurrentFile3().

◆ unzeof()

int ZEXPORT unzeof ( unzFile  file)

Definition at line 1927 of file unzip.c.

1928 {
1929  unz64_s* s;
1930  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1931  if (file==NULL)
1932  return UNZ_PARAMERROR;
1933  s=(unz64_s*)file;
1934  pfile_in_zip_read_info=s->pfile_in_zip_read;
1935 
1936  if (pfile_in_zip_read_info==NULL)
1937  return UNZ_PARAMERROR;
1938 
1939  if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1940  return 1;
1941  else
1942  return 0;
1943 }

References NULL, file_in_zip64_read_info_s::rest_read_uncompressed, s, and UNZ_PARAMERROR.

◆ unzGetCurrentFileInfo()

int ZEXPORT unzGetCurrentFileInfo ( unzFile  file,
unz_file_info pfile_info,
char *  szFileName,
uLong  fileNameBufferSize,
void *  extraField,
uLong  extraFieldBufferSize,
char *  szComment,
uLong  commentBufferSize 
)

Definition at line 1136 of file unzip.c.

1141 {
1142  int err;
1143  unz_file_info64 file_info64;
1145  szFileName,fileNameBufferSize,
1146  extraField,extraFieldBufferSize,
1147  szComment,commentBufferSize);
1148  if ((err==UNZ_OK) && (pfile_info != NULL))
1149  {
1150  pfile_info->version = file_info64.version;
1151  pfile_info->version_needed = file_info64.version_needed;
1152  pfile_info->flag = file_info64.flag;
1153  pfile_info->compression_method = file_info64.compression_method;
1154  pfile_info->dosDate = file_info64.dosDate;
1155  pfile_info->crc = file_info64.crc;
1156 
1157  pfile_info->size_filename = file_info64.size_filename;
1158  pfile_info->size_file_extra = file_info64.size_file_extra;
1159  pfile_info->size_file_comment = file_info64.size_file_comment;
1160 
1161  pfile_info->disk_num_start = file_info64.disk_num_start;
1162  pfile_info->internal_fa = file_info64.internal_fa;
1163  pfile_info->external_fa = file_info64.external_fa;
1164 
1165  pfile_info->tmu_date = file_info64.tmu_date,
1166 
1167 
1168  pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1169  pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1170 
1171  }
1172  return err;
1173 }
uLong dosDate
Definition: unzip.h:138
uLong version_needed
Definition: unzip.h:135
uLong compressed_size
Definition: unzip.h:140
uLong size_file_extra
Definition: unzip.h:143
uLong version
Definition: unzip.h:134
uLong crc
Definition: unzip.h:139
uLong uncompressed_size
Definition: unzip.h:141
uLong internal_fa
Definition: unzip.h:147
uLong compression_method
Definition: unzip.h:137
uLong disk_num_start
Definition: unzip.h:146
tm_unz tmu_date
Definition: unzip.h:150
uLong flag
Definition: unzip.h:136
uLong external_fa
Definition: unzip.h:148
uLong size_filename
Definition: unzip.h:142
uLong size_file_comment
Definition: unzip.h:144
int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *pfile_info, unz_file_info64_internal *pfile_info_internal, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:879

References unz_file_info64_s::compressed_size, unz_file_info_s::compressed_size, unz_file_info64_s::compression_method, unz_file_info_s::compression_method, unz_file_info64_s::crc, unz_file_info_s::crc, unz_file_info64_s::disk_num_start, unz_file_info_s::disk_num_start, unz_file_info64_s::dosDate, unz_file_info_s::dosDate, err, unz_file_info64_s::external_fa, unz_file_info_s::external_fa, unz_file_info64_s::flag, unz_file_info_s::flag, unz_file_info64_s::internal_fa, unz_file_info_s::internal_fa, NULL, unz_file_info64_s::size_file_comment, unz_file_info_s::size_file_comment, unz_file_info64_s::size_file_extra, unz_file_info_s::size_file_extra, unz_file_info64_s::size_filename, unz_file_info_s::size_filename, unz_file_info64_s::tmu_date, unz_file_info_s::tmu_date, unz_file_info64_s::uncompressed_size, unz_file_info_s::uncompressed_size, unz64local_GetCurrentFileInfoInternal(), UNZ_OK, unz_file_info64_s::version, unz_file_info_s::version, unz_file_info64_s::version_needed, and unz_file_info_s::version_needed.

◆ unzGetCurrentFileInfo64()

int ZEXPORT unzGetCurrentFileInfo64 ( unzFile  file,
unz_file_info64 pfile_info,
char *  szFileName,
uLong  fileNameBufferSize,
void *  extraField,
uLong  extraFieldBufferSize,
char *  szComment,
uLong  commentBufferSize 
)

Definition at line 1124 of file unzip.c.

1129 {
1131  szFileName,fileNameBufferSize,
1132  extraField,extraFieldBufferSize,
1133  szComment,commentBufferSize);
1134 }

References NULL, and unz64local_GetCurrentFileInfoInternal().

Referenced by do_extract_currentfile(), do_list(), and unzLocateFile().

◆ unzGetCurrentFileZStreamPos64()

ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 ( unzFile  file)

Addition for GDAL : START

Definition at line 1658 of file unzip.c.

1659 {
1660  unz64_s* s;
1661  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1662  s=(unz64_s*)file;
1663  if (file==NULL)
1664  return 0; //UNZ_PARAMERROR;
1665  pfile_in_zip_read_info=s->pfile_in_zip_read;
1666  if (pfile_in_zip_read_info==NULL)
1667  return 0; //UNZ_PARAMERROR;
1668  return pfile_in_zip_read_info->pos_in_zipfile +
1669  pfile_in_zip_read_info->byte_before_the_zipfile;
1670 }
ZPOS64_T byte_before_the_zipfile
Definition: unzip.c:158
ZPOS64_T pos_in_zipfile
Definition: unzip.c:143

References file_in_zip64_read_info_s::byte_before_the_zipfile, NULL, file_in_zip64_read_info_s::pos_in_zipfile, and s.

◆ unzGetFilePos()

int ZEXPORT unzGetFilePos ( unzFile  file,
unz_file_pos file_pos 
)

Definition at line 1324 of file unzip.c.

1327 {
1328  unz64_file_pos file_pos64;
1329  int err = unzGetFilePos64(file,&file_pos64);
1330  if (err==UNZ_OK)
1331  {
1332  file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
1333  file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1334  }
1335  return err;
1336 }
ZPOS64_T num_of_file
Definition: unzip.h:275
ZPOS64_T pos_in_zip_directory
Definition: unzip.h:274
uLong num_of_file
Definition: unzip.h:261
uLong pos_in_zip_directory
Definition: unzip.h:260
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
Definition: unzip.c:1308

References err, unz_file_pos_s::num_of_file, unz64_file_pos_s::num_of_file, unz_file_pos_s::pos_in_zip_directory, unz64_file_pos_s::pos_in_zip_directory, UNZ_OK, and unzGetFilePos64().

◆ unzGetFilePos64()

int ZEXPORT unzGetFilePos64 ( unzFile  file,
unz64_file_pos file_pos 
)

Definition at line 1308 of file unzip.c.

1309 {
1310  unz64_s* s;
1311 
1312  if (file==NULL || file_pos==NULL)
1313  return UNZ_PARAMERROR;
1314  s=(unz64_s*)file;
1315  if (!s->current_file_ok)
1316  return UNZ_END_OF_LIST_OF_FILE;
1317 
1318  file_pos->pos_in_zip_directory = s->pos_in_central_dir;
1319  file_pos->num_of_file = s->num_file;
1320 
1321  return UNZ_OK;
1322 }
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:75

References NULL, unz64_file_pos_s::num_of_file, unz64_file_pos_s::pos_in_zip_directory, s, UNZ_END_OF_LIST_OF_FILE, UNZ_OK, and UNZ_PARAMERROR.

Referenced by unzGetFilePos().

◆ unzGetGlobalComment()

int ZEXPORT unzGetGlobalComment ( unzFile  file,
char *  szComment,
uLong  uSizeBuf 
)

Definition at line 2054 of file unzip.c.

2055 {
2056  unz64_s* s;
2057  uLong uReadThis ;
2058  if (file==NULL)
2059  return (int)UNZ_PARAMERROR;
2060  s=(unz64_s*)file;
2061 
2062  uReadThis = uSizeBuf;
2063  if (uReadThis>s->gi.size_comment)
2064  uReadThis = s->gi.size_comment;
2065 
2066  if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
2067  return UNZ_ERRNO;
2068 
2069  if (uReadThis>0)
2070  {
2071  *szComment='\0';
2072  if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
2073  return UNZ_ERRNO;
2074  }
2075 
2076  if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
2077  *(szComment+s->gi.size_comment)='\0';
2078  return (int)uReadThis;
2079 }

References NULL, s, UNZ_ERRNO, UNZ_PARAMERROR, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, and ZSEEK64.

◆ unzGetGlobalInfo()

int ZEXPORT unzGetGlobalInfo ( unzFile  file,
unz_global_info pglobal_info32 
)

Definition at line 838 of file unzip.c.

839 {
840  unz64_s* s;
841  if (file==NULL)
842  return UNZ_PARAMERROR;
843  s=(unz64_s*)file;
844  /* to do : check if number_entry is not truncated */
845  pglobal_info32->number_entry = (uLong)s->gi.number_entry;
846  pglobal_info32->size_comment = s->gi.size_comment;
847  return UNZ_OK;
848 }
uLong size_comment
Definition: unzip.h:107
uLong number_entry
Definition: unzip.h:105

References NULL, unz_global_info_s::number_entry, s, unz_global_info_s::size_comment, UNZ_OK, and UNZ_PARAMERROR.

◆ unzGetGlobalInfo64()

int ZEXPORT unzGetGlobalInfo64 ( unzFile  file,
unz_global_info64 pglobal_info 
)

Definition at line 828 of file unzip.c.

829 {
830  unz64_s* s;
831  if (file==NULL)
832  return UNZ_PARAMERROR;
833  s=(unz64_s*)file;
834  *pglobal_info=s->gi;
835  return UNZ_OK;
836 }

References NULL, s, UNZ_OK, and UNZ_PARAMERROR.

Referenced by do_extract(), and do_list().

◆ unzGetLocalExtrafield()

int ZEXPORT unzGetLocalExtrafield ( unzFile  file,
voidp  buf,
unsigned  len 
)

Definition at line 1959 of file unzip.c.

1960 {
1961  unz64_s* s;
1962  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1963  uInt read_now;
1964  ZPOS64_T size_to_read;
1965 
1966  if (file==NULL)
1967  return UNZ_PARAMERROR;
1968  s=(unz64_s*)file;
1969  pfile_in_zip_read_info=s->pfile_in_zip_read;
1970 
1971  if (pfile_in_zip_read_info==NULL)
1972  return UNZ_PARAMERROR;
1973 
1974  size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1975  pfile_in_zip_read_info->pos_local_extrafield);
1976 
1977  if (buf==NULL)
1978  return (int)size_to_read;
1979 
1980  if (len>size_to_read)
1981  read_now = (uInt)size_to_read;
1982  else
1983  read_now = (uInt)len ;
1984 
1985  if (read_now==0)
1986  return 0;
1987 
1988  if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1989  pfile_in_zip_read_info->filestream,
1990  pfile_in_zip_read_info->offset_local_extrafield +
1991  pfile_in_zip_read_info->pos_local_extrafield,
1993  return UNZ_ERRNO;
1994 
1995  if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1996  pfile_in_zip_read_info->filestream,
1997  buf,read_now)!=read_now)
1998  return UNZ_ERRNO;
1999 
2000  return (int)read_now;
2001 }
size_t len
Definition: 6502dis.c:15
ZPOS64_T offset_local_extrafield
Definition: unzip.c:146
zlib_filefunc64_32_def z_filefunc
Definition: unzip.c:155
ZPOS64_T pos_local_extrafield
Definition: unzip.c:148

References file_in_zip64_read_info_s::filestream, len, NULL, file_in_zip64_read_info_s::offset_local_extrafield, file_in_zip64_read_info_s::pos_local_extrafield, s, file_in_zip64_read_info_s::size_local_extrafield, UNZ_ERRNO, UNZ_PARAMERROR, file_in_zip64_read_info_s::z_filefunc, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, and ZSEEK64.

◆ unzGetOffset()

uLong ZEXPORT unzGetOffset ( unzFile  file)

Definition at line 2097 of file unzip.c.

2098 {
2099  ZPOS64_T offset64;
2100 
2101  if (file==NULL)
2102  return 0; //UNZ_PARAMERROR;
2103  offset64 = unzGetOffset64(file);
2104  return (uLong)offset64;
2105 }
ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
Definition: unzip.c:2082

References NULL, and unzGetOffset64().

◆ unzGetOffset64()

ZPOS64_T ZEXPORT unzGetOffset64 ( unzFile  file)

Definition at line 2082 of file unzip.c.

2083 {
2084  unz64_s* s;
2085 
2086  if (file==NULL)
2087  return 0; //UNZ_PARAMERROR;
2088  s=(unz64_s*)file;
2089  if (!s->current_file_ok)
2090  return 0;
2091  if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
2092  if (s->num_file==s->gi.number_entry)
2093  return 0;
2094  return s->pos_in_central_dir;
2095 }

References NULL, and s.

Referenced by unzGetOffset().

◆ unzGoToFilePos()

int ZEXPORT unzGoToFilePos ( unzFile  file,
unz_file_pos file_pos 
)

Definition at line 1360 of file unzip.c.

1363 {
1364  unz64_file_pos file_pos64;
1365  if (file_pos == NULL)
1366  return UNZ_PARAMERROR;
1367 
1368  file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
1369  file_pos64.num_of_file = file_pos->num_of_file;
1370  return unzGoToFilePos64(file,&file_pos64);
1371 }
int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
Definition: unzip.c:1338

References NULL, unz_file_pos_s::num_of_file, unz64_file_pos_s::num_of_file, unz_file_pos_s::pos_in_zip_directory, unz64_file_pos_s::pos_in_zip_directory, UNZ_PARAMERROR, and unzGoToFilePos64().

◆ unzGoToFilePos64()

int ZEXPORT unzGoToFilePos64 ( unzFile  file,
const unz64_file_pos file_pos 
)

Definition at line 1338 of file unzip.c.

1339 {
1340  unz64_s* s;
1341  int err;
1342 
1343  if (file==NULL || file_pos==NULL)
1344  return UNZ_PARAMERROR;
1345  s=(unz64_s*)file;
1346 
1347  /* jump to the right spot */
1348  s->pos_in_central_dir = file_pos->pos_in_zip_directory;
1349  s->num_file = file_pos->num_of_file;
1350 
1351  /* set the current file */
1352  err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1353  &s->cur_file_info_internal,
1354  NULL,0,NULL,0,NULL,0);
1355  /* return results */
1356  s->current_file_ok = (err == UNZ_OK);
1357  return err;
1358 }

References err, NULL, unz64_file_pos_s::num_of_file, unz64_file_pos_s::pos_in_zip_directory, s, unz64local_GetCurrentFileInfoInternal(), UNZ_OK, and UNZ_PARAMERROR.

Referenced by unzGoToFilePos().

◆ unzGoToFirstFile()

int ZEXPORT unzGoToFirstFile ( unzFile  file)

Definition at line 1178 of file unzip.c.

1179 {
1180  int err=UNZ_OK;
1181  unz64_s* s;
1182  if (file==NULL)
1183  return UNZ_PARAMERROR;
1184  s=(unz64_s*)file;
1185  s->pos_in_central_dir=s->offset_central_dir;
1186  s->num_file=0;
1188  &s->cur_file_info_internal,
1189  NULL,0,NULL,0,NULL,0);
1190  s->current_file_ok = (err == UNZ_OK);
1191  return err;
1192 }

References err, NULL, s, unz64local_GetCurrentFileInfoInternal(), UNZ_OK, and UNZ_PARAMERROR.

Referenced by unzLocateFile(), and unzOpenInternal().

◆ unzGoToNextFile()

int ZEXPORT unzGoToNextFile ( unzFile  file)

Definition at line 1199 of file unzip.c.

1200 {
1201  unz64_s* s;
1202  int err;
1203 
1204  if (file==NULL)
1205  return UNZ_PARAMERROR;
1206  s=(unz64_s*)file;
1207  if (!s->current_file_ok)
1208  return UNZ_END_OF_LIST_OF_FILE;
1209  if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
1210  if (s->num_file+1==s->gi.number_entry)
1211  return UNZ_END_OF_LIST_OF_FILE;
1212 
1213  s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
1214  s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
1215  s->num_file++;
1216  err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1217  &s->cur_file_info_internal,
1218  NULL,0,NULL,0,NULL,0);
1219  s->current_file_ok = (err == UNZ_OK);
1220  return err;
1221 }
#define SIZECENTRALDIRITEM
Definition: unzip.c:118

References err, NULL, s, SIZECENTRALDIRITEM, unz64local_GetCurrentFileInfoInternal(), UNZ_END_OF_LIST_OF_FILE, UNZ_OK, and UNZ_PARAMERROR.

Referenced by do_extract(), do_list(), and unzLocateFile().

◆ unzLocateFile()

int ZEXPORT unzLocateFile ( unzFile  file,
const char *  szFileName,
int  iCaseSensitivity 
)

Definition at line 1232 of file unzip.c.

1233 {
1234  unz64_s* s;
1235  int err;
1236 
1237  /* We remember the 'current' position in the file so that we can jump
1238  * back there if we fail.
1239  */
1240  unz_file_info64 cur_file_infoSaved;
1241  unz_file_info64_internal cur_file_info_internalSaved;
1242  ZPOS64_T num_fileSaved;
1243  ZPOS64_T pos_in_central_dirSaved;
1244 
1245 
1246  if (file==NULL)
1247  return UNZ_PARAMERROR;
1248 
1249  if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
1250  return UNZ_PARAMERROR;
1251 
1252  s=(unz64_s*)file;
1253  if (!s->current_file_ok)
1254  return UNZ_END_OF_LIST_OF_FILE;
1255 
1256  /* Save the current state */
1257  num_fileSaved = s->num_file;
1258  pos_in_central_dirSaved = s->pos_in_central_dir;
1259  cur_file_infoSaved = s->cur_file_info;
1260  cur_file_info_internalSaved = s->cur_file_info_internal;
1261 
1263 
1264  while (err == UNZ_OK)
1265  {
1266  char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
1268  szCurrentFileName,sizeof(szCurrentFileName)-1,
1269  NULL,0,NULL,0);
1270  if (err == UNZ_OK)
1271  {
1272  if (unzStringFileNameCompare(szCurrentFileName,
1273  szFileName,iCaseSensitivity)==0)
1274  return UNZ_OK;
1276  }
1277  }
1278 
1279  /* We failed, so restore the state of the 'current file' to where we
1280  * were.
1281  */
1282  s->num_file = num_fileSaved ;
1283  s->pos_in_central_dir = pos_in_central_dirSaved ;
1284  s->cur_file_info = cur_file_infoSaved;
1285  s->cur_file_info_internal = cur_file_info_internalSaved;
1286  return err;
1287 }
int ZEXPORT unzStringFileNameCompare(const char *fileName1, const char *fileName2, int iCaseSensitivity)
Definition: unzip.c:390
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1124
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1178
#define UNZ_MAXFILENAMEINZIP
Definition: unzip.c:108
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1199

References err, NULL, s, UNZ_END_OF_LIST_OF_FILE, UNZ_MAXFILENAMEINZIP, UNZ_OK, UNZ_PARAMERROR, unzGetCurrentFileInfo64(), unzGoToFirstFile(), unzGoToNextFile(), and unzStringFileNameCompare().

Referenced by do_extract_onefile().

◆ unzOpen()

unzFile ZEXPORT unzOpen ( const char *  path)

Definition at line 793 of file unzip.c.

794 {
795  return unzOpenInternal(path, NULL, 0);
796 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_filefunc64_32_def, int is64bitOpenFunction)
Definition: unzip.c:584

References NULL, path, and unzOpenInternal().

◆ unzOpen2()

unzFile ZEXPORT unzOpen2 ( const char *  path,
zlib_filefunc_def pzlib_filefunc32_def 
)

Definition at line 765 of file unzip.c.

767 {
768  if (pzlib_filefunc32_def != NULL)
769  {
770  zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
771  fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
772  return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
773  }
774  else
775  return unzOpenInternal(path, NULL, 0);
776 }
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
Definition: ioapi.c:69

References fill_zlib_filefunc64_32_def_from_filefunc32(), NULL, path, and unzOpenInternal().

◆ unzOpen2_64()

unzFile ZEXPORT unzOpen2_64 ( const void *  path,
zlib_filefunc64_def pzlib_filefunc_def 
)

Definition at line 778 of file unzip.c.

780 {
781  if (pzlib_filefunc_def != NULL)
782  {
783  zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
784  zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
785  zlib_filefunc64_32_def_fill.ztell32_file = NULL;
786  zlib_filefunc64_32_def_fill.zseek32_file = NULL;
787  return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
788  }
789  else
790  return unzOpenInternal(path, NULL, 1);
791 }
seek_file_func zseek32_file
Definition: ioapi.h:185
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:182
tell_file_func ztell32_file
Definition: ioapi.h:184

References NULL, path, unzOpenInternal(), zlib_filefunc64_32_def_s::zfile_func64, zlib_filefunc64_32_def_s::zseek32_file, and zlib_filefunc64_32_def_s::ztell32_file.

Referenced by main().

◆ unzOpen64()

unzFile ZEXPORT unzOpen64 ( const void *  path)

Definition at line 798 of file unzip.c.

799 {
800  return unzOpenInternal(path, NULL, 1);
801 }

References NULL, path, and unzOpenInternal().

Referenced by main().

◆ unzOpenCurrentFile()

int ZEXPORT unzOpenCurrentFile ( unzFile  file)

Definition at line 1641 of file unzip.c.

1642 {
1643  return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1644 }
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
Definition: unzip.c:1472

References NULL, and unzOpenCurrentFile3().

◆ unzOpenCurrentFile2()

int ZEXPORT unzOpenCurrentFile2 ( unzFile  file,
int method,
int level,
int  raw 
)

Definition at line 1651 of file unzip.c.

1652 {
1653  return unzOpenCurrentFile3(file, method, level, raw, NULL);
1654 }
static int level
Definition: vmenus.c:2424

References level, NULL, and unzOpenCurrentFile3().

◆ unzOpenCurrentFile3()

int ZEXPORT unzOpenCurrentFile3 ( unzFile  file,
int method,
int level,
int  raw,
const char *  password 
)

Definition at line 1472 of file unzip.c.

1474 {
1475  int err=UNZ_OK;
1476  uInt iSizeVar;
1477  unz64_s* s;
1478  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1479  ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
1480  uInt size_local_extrafield; /* size of the local extra field */
1481 # ifndef NOUNCRYPT
1482  char source[12];
1483 # else
1484  if (password != NULL)
1485  return UNZ_PARAMERROR;
1486 # endif
1487 
1488  if (file==NULL)
1489  return UNZ_PARAMERROR;
1490  s=(unz64_s*)file;
1491  if (!s->current_file_ok)
1492  return UNZ_PARAMERROR;
1493 
1494  if (s->pfile_in_zip_read != NULL)
1496 
1497  if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1498  return UNZ_BADZIPFILE;
1499 
1500  pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
1501  if (pfile_in_zip_read_info==NULL)
1502  return UNZ_INTERNALERROR;
1503 
1504  pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1505  pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1506  pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1507  pfile_in_zip_read_info->pos_local_extrafield=0;
1508  pfile_in_zip_read_info->raw=raw;
1509 
1510  if (pfile_in_zip_read_info->read_buffer==NULL)
1511  {
1512  TRYFREE(pfile_in_zip_read_info);
1513  return UNZ_INTERNALERROR;
1514  }
1515 
1516  pfile_in_zip_read_info->stream_initialised=0;
1517 
1518  if (method!=NULL)
1519  *method = (int)s->cur_file_info.compression_method;
1520 
1521  if (level!=NULL)
1522  {
1523  *level = 6;
1524  switch (s->cur_file_info.flag & 0x06)
1525  {
1526  case 6 : *level = 1; break;
1527  case 4 : *level = 2; break;
1528  case 2 : *level = 9; break;
1529  }
1530  }
1531 
1532  if ((s->cur_file_info.compression_method!=0) &&
1533 /* #ifdef HAVE_BZIP2 */
1534  (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1535 /* #endif */
1536  (s->cur_file_info.compression_method!=Z_DEFLATED))
1537 
1539 
1540  pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1541  pfile_in_zip_read_info->crc32=0;
1542  pfile_in_zip_read_info->total_out_64=0;
1543  pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1544  pfile_in_zip_read_info->filestream=s->filestream;
1545  pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1546  pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1547 
1548  pfile_in_zip_read_info->stream.total_out = 0;
1549 
1550  if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
1551  {
1552 #ifdef HAVE_BZIP2
1553  pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
1554  pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
1555  pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
1556  pfile_in_zip_read_info->bstream.state = (voidpf)0;
1557 
1558  pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1559  pfile_in_zip_read_info->stream.zfree = (free_func)0;
1560  pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1561  pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1562  pfile_in_zip_read_info->stream.avail_in = 0;
1563 
1564  err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1565  if (err == Z_OK)
1566  pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1567  else
1568  {
1569  TRYFREE(pfile_in_zip_read_info);
1570  return err;
1571  }
1572 #else
1573  pfile_in_zip_read_info->raw=1;
1574 #endif
1575  }
1576  else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
1577  {
1578  pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1579  pfile_in_zip_read_info->stream.zfree = (free_func)0;
1580  pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1581  pfile_in_zip_read_info->stream.next_in = 0;
1582  pfile_in_zip_read_info->stream.avail_in = 0;
1583 
1584  err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1585  if (err == Z_OK)
1586  pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1587  else
1588  {
1589  TRYFREE(pfile_in_zip_read_info);
1590  return err;
1591  }
1592  /* windowBits is passed < 0 to tell that there is no zlib header.
1593  * Note that in this case inflate *requires* an extra "dummy" byte
1594  * after the compressed stream in order to complete decompression and
1595  * return Z_STREAM_END.
1596  * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1597  * size of both compressed and uncompressed data
1598  */
1599  }
1600  pfile_in_zip_read_info->rest_read_compressed =
1601  s->cur_file_info.compressed_size ;
1602  pfile_in_zip_read_info->rest_read_uncompressed =
1603  s->cur_file_info.uncompressed_size ;
1604 
1605 
1606  pfile_in_zip_read_info->pos_in_zipfile =
1607  s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1608  iSizeVar;
1609 
1610  pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1611 
1612  s->pfile_in_zip_read = pfile_in_zip_read_info;
1613  s->encrypted = 0;
1614 
1615 # ifndef NOUNCRYPT
1616  if (password != NULL)
1617  {
1618  int i;
1619  s->pcrc_32_tab = get_crc_table();
1620  init_keys(password,s->keys,s->pcrc_32_tab);
1621  if (ZSEEK64(s->z_filefunc, s->filestream,
1622  s->pfile_in_zip_read->pos_in_zipfile +
1623  s->pfile_in_zip_read->byte_before_the_zipfile,
1624  SEEK_SET)!=0)
1625  return UNZ_INTERNALERROR;
1626  if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
1627  return UNZ_INTERNALERROR;
1628 
1629  for (i = 0; i<12; i++)
1630  zdecode(s->keys,s->pcrc_32_tab,source[i]);
1631 
1632  s->pfile_in_zip_read->pos_in_zipfile+=12;
1633  s->encrypted=1;
1634  }
1635 # endif
1636 
1637 
1638  return UNZ_OK;
1639 }
#define zdecode(pkeys, pcrc_32_tab, c)
Definition: crypt.h:77
static void init_keys(const char *passwd, unsigned long *pkeys, const z_crc_t *pcrc_32_tab)
Definition: crypt.h:66
#define MAX_WBITS
Definition: flirt.c:105
const char * source
Definition: lz4.h:699
ZPOS64_T rest_read_compressed
Definition: unzip.c:153
uInt avail_in
Definition: zlib.h:88
alloc_func zalloc
Definition: zlib.h:98
z_const Bytef * next_in
Definition: zlib.h:87
free_func zfree
Definition: zlib.h:99
voidpf opaque
Definition: zlib.h:100
uLong total_out
Definition: zlib.h:93
int unz64local_CheckCurrentFileCoherencyHeader(unz64_s *s, uInt *piSizeVar, ZPOS64_T *poffset_local_extrafield, uInt *psize_local_extrafield)
Definition: unzip.c:1385
#define UNZ_BUFSIZE
Definition: unzip.c:104
#define UNZ_INTERNALERROR
Definition: unzip.h:80
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
Byte FAR * voidpf
Definition: zconf.h:413
#define SEEK_SET
Definition: zip.c:88
const z_crc_t FAR *ZEXPORT get_crc_table()
Definition: crc32.c:586
#define inflateInit2(strm, windowBits)
Definition: zlib.h:1817
#define Z_OK
Definition: zlib.h:177

References ALLOC, z_stream_s::avail_in, file_in_zip64_read_info_s::byte_before_the_zipfile, file_in_zip64_read_info_s::compression_method, file_in_zip64_read_info_s::crc32, file_in_zip64_read_info_s::crc32_wait, err, file_in_zip64_read_info_s::filestream, get_crc_table(), i, if(), inflateInit2, init_keys(), int, level, MAX_WBITS, z_stream_s::next_in, NULL, file_in_zip64_read_info_s::offset_local_extrafield, z_stream_s::opaque, file_in_zip64_read_info_s::pos_in_zipfile, file_in_zip64_read_info_s::pos_local_extrafield, file_in_zip64_read_info_s::raw, file_in_zip64_read_info_s::read_buffer, file_in_zip64_read_info_s::rest_read_compressed, file_in_zip64_read_info_s::rest_read_uncompressed, s, SEEK_SET, file_in_zip64_read_info_s::size_local_extrafield, SIZEZIPLOCALHEADER, source, file_in_zip64_read_info_s::stream, file_in_zip64_read_info_s::stream_initialised, z_stream_s::total_out, file_in_zip64_read_info_s::total_out_64, TRYFREE, unz64local_CheckCurrentFileCoherencyHeader(), UNZ_BADZIPFILE, UNZ_BUFSIZE, UNZ_INTERNALERROR, UNZ_OK, UNZ_PARAMERROR, unzCloseCurrentFile(), Z_BZIP2ED, Z_DEFLATED, file_in_zip64_read_info_s::z_filefunc, Z_OK, z_stream_s::zalloc, zdecode, z_stream_s::zfree, ZREAD64, and ZSEEK64.

Referenced by unzOpenCurrentFile(), unzOpenCurrentFile2(), and unzOpenCurrentFilePassword().

◆ unzOpenCurrentFilePassword()

int ZEXPORT unzOpenCurrentFilePassword ( unzFile  file,
const char *  password 
)

Definition at line 1646 of file unzip.c.

1647 {
1648  return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1649 }

References NULL, and unzOpenCurrentFile3().

Referenced by do_extract_currentfile().

◆ unzOpenInternal()

unzFile unzOpenInternal ( const void *  path,
zlib_filefunc64_32_def pzlib_filefunc64_32_def,
int  is64bitOpenFunction 
)

Definition at line 584 of file unzip.c.

587 {
588  unz64_s us;
589  unz64_s *s;
590  ZPOS64_T central_pos;
591  uLong uL;
592 
593  uLong number_disk; /* number of the current dist, used for
594  spaning ZIP, unsupported, always 0*/
595  uLong number_disk_with_CD; /* number the the disk with central dir, used
596  for spaning ZIP, unsupported, always 0*/
597  ZPOS64_T number_entry_CD; /* total number of entries in
598  the central dir
599  (same than number_entry on nospan) */
600 
601  int err=UNZ_OK;
602 
603  if (unz_copyright[0]!=' ')
604  return NULL;
605 
608  if (pzlib_filefunc64_32_def==NULL)
610  else
611  us.z_filefunc = *pzlib_filefunc64_32_def;
612  us.is64bitOpenFunction = is64bitOpenFunction;
613 
614 
615 
616  us.filestream = ZOPEN64(us.z_filefunc,
617  path,
620  if (us.filestream==NULL)
621  return NULL;
622 
624  if (central_pos)
625  {
626  uLong uS;
627  ZPOS64_T uL64;
628 
629  us.isZip64 = 1;
630 
631  if (ZSEEK64(us.z_filefunc, us.filestream,
632  central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
633  err=UNZ_ERRNO;
634 
635  /* the signature, already checked */
637  err=UNZ_ERRNO;
638 
639  /* size of zip64 end of central directory record */
640  if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
641  err=UNZ_ERRNO;
642 
643  /* version made by */
645  err=UNZ_ERRNO;
646 
647  /* version needed to extract */
649  err=UNZ_ERRNO;
650 
651  /* number of this disk */
652  if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
653  err=UNZ_ERRNO;
654 
655  /* number of the disk with the start of the central directory */
656  if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
657  err=UNZ_ERRNO;
658 
659  /* total number of entries in the central directory on this disk */
661  err=UNZ_ERRNO;
662 
663  /* total number of entries in the central directory */
664  if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
665  err=UNZ_ERRNO;
666 
667  if ((number_entry_CD!=us.gi.number_entry) ||
668  (number_disk_with_CD!=0) ||
669  (number_disk!=0))
671 
672  /* size of the central directory */
674  err=UNZ_ERRNO;
675 
676  /* offset of start of central directory with respect to the
677  starting disk number */
679  err=UNZ_ERRNO;
680 
681  us.gi.size_comment = 0;
682  }
683  else
684  {
685  central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
686  if (central_pos==0)
687  err=UNZ_ERRNO;
688 
689  us.isZip64 = 0;
690 
691  if (ZSEEK64(us.z_filefunc, us.filestream,
692  central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
693  err=UNZ_ERRNO;
694 
695  /* the signature, already checked */
697  err=UNZ_ERRNO;
698 
699  /* number of this disk */
700  if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
701  err=UNZ_ERRNO;
702 
703  /* number of the disk with the start of the central directory */
704  if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
705  err=UNZ_ERRNO;
706 
707  /* total number of entries in the central dir on this disk */
709  err=UNZ_ERRNO;
710  us.gi.number_entry = uL;
711 
712  /* total number of entries in the central dir */
714  err=UNZ_ERRNO;
715  number_entry_CD = uL;
716 
717  if ((number_entry_CD!=us.gi.number_entry) ||
718  (number_disk_with_CD!=0) ||
719  (number_disk!=0))
721 
722  /* size of the central directory */
724  err=UNZ_ERRNO;
725  us.size_central_dir = uL;
726 
727  /* offset of start of central directory with respect to the
728  starting disk number */
730  err=UNZ_ERRNO;
731  us.offset_central_dir = uL;
732 
733  /* zipfile comment length */
735  err=UNZ_ERRNO;
736  }
737 
738  if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
739  (err==UNZ_OK))
741 
742  if (err!=UNZ_OK)
743  {
745  return NULL;
746  }
747 
748  us.byte_before_the_zipfile = central_pos -
750  us.central_pos = central_pos;
751  us.pfile_in_zip_read = NULL;
752  us.encrypted = 0;
753 
754 
755  s=(unz64_s*)ALLOC(sizeof(unz64_s));
756  if( s != NULL)
757  {
758  *s=us;
760  }
761  return (unzFile)s;
762 }
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: ioapi.c:247
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition: ioapi.h:122
#define ZOPEN64(filefunc, filename, mode)
Definition: ioapi.h:202
#define ZLIB_FILEFUNC_MODE_READ
Definition: ioapi.h:118
zlib_filefunc64_32_def z_filefunc
Definition: unzip.c:167
int is64bitOpenFunction
Definition: unzip.c:168
unz_global_info64 gi
Definition: unzip.c:170
ZPOS64_T central_pos
Definition: unzip.c:175
file_in_zip64_read_info_s * pfile_in_zip_read
Definition: unzip.c:183
ZPOS64_T offset_central_dir
Definition: unzip.c:178
ZPOS64_T size_central_dir
Definition: unzip.c:177
int encrypted
Definition: unzip.c:185
voidpf filestream
Definition: unzip.c:169
ZPOS64_T byte_before_the_zipfile
Definition: unzip.c:171
int isZip64
Definition: unzip.c:187
ZPOS64_T number_entry
Definition: unzip.h:98
uLong size_comment
Definition: unzip.h:100
ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: unzip.c:413
ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
Definition: unzip.c:478
const char unz_copyright[]
Definition: unzip.c:122
voidp unzFile
Definition: unzip.h:70

References ALLOC, unz64_s::byte_before_the_zipfile, unz64_s::central_pos, unz64_s::encrypted, err, unz64_s::filestream, fill_fopen64_filefunc(), unz64_s::gi, unz64_s::is64bitOpenFunction, unz64_s::isZip64, NULL, unz_global_info64_s::number_entry, unz64_s::offset_central_dir, path, unz64_s::pfile_in_zip_read, s, unz64_s::size_central_dir, unz_global_info64_s::size_comment, unz64local_getLong(), unz64local_getLong64(), unz64local_getShort(), unz64local_SearchCentralDir(), unz64local_SearchCentralDir64(), UNZ_BADZIPFILE, unz_copyright, UNZ_ERRNO, UNZ_OK, unzGoToFirstFile(), unz64_s::z_filefunc, ZCLOSE64, zlib_filefunc64_32_def_s::zfile_func64, ZLIB_FILEFUNC_MODE_EXISTING, ZLIB_FILEFUNC_MODE_READ, ZLIB_FILEFUNC_SEEK_SET, ZOPEN64, zlib_filefunc64_32_def_s::zseek32_file, ZSEEK64, and zlib_filefunc64_32_def_s::ztell32_file.

Referenced by unzOpen(), unzOpen2(), unzOpen2_64(), and unzOpen64().

◆ unzReadCurrentFile()

int ZEXPORT unzReadCurrentFile ( unzFile  file,
voidp  buf,
unsigned  len 
)

Addition for GDAL : END

Definition at line 1684 of file unzip.c.

1685 {
1686  int err=UNZ_OK;
1687  uInt iRead = 0;
1688  unz64_s* s;
1689  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1690  if (file==NULL)
1691  return UNZ_PARAMERROR;
1692  s=(unz64_s*)file;
1693  pfile_in_zip_read_info=s->pfile_in_zip_read;
1694 
1695  if (pfile_in_zip_read_info==NULL)
1696  return UNZ_PARAMERROR;
1697 
1698 
1699  if (pfile_in_zip_read_info->read_buffer == NULL)
1700  return UNZ_END_OF_LIST_OF_FILE;
1701  if (len==0)
1702  return 0;
1703 
1704  pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1705 
1706  pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1707 
1708  if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1709  (!(pfile_in_zip_read_info->raw)))
1710  pfile_in_zip_read_info->stream.avail_out =
1711  (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1712 
1713  if ((len>pfile_in_zip_read_info->rest_read_compressed+
1714  pfile_in_zip_read_info->stream.avail_in) &&
1715  (pfile_in_zip_read_info->raw))
1716  pfile_in_zip_read_info->stream.avail_out =
1717  (uInt)pfile_in_zip_read_info->rest_read_compressed+
1718  pfile_in_zip_read_info->stream.avail_in;
1719 
1720  while (pfile_in_zip_read_info->stream.avail_out>0)
1721  {
1722  if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1723  (pfile_in_zip_read_info->rest_read_compressed>0))
1724  {
1725  uInt uReadThis = UNZ_BUFSIZE;
1726  if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1727  uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1728  if (uReadThis == 0)
1729  return UNZ_EOF;
1730  if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1731  pfile_in_zip_read_info->filestream,
1732  pfile_in_zip_read_info->pos_in_zipfile +
1733  pfile_in_zip_read_info->byte_before_the_zipfile,
1735  return UNZ_ERRNO;
1736  if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1737  pfile_in_zip_read_info->filestream,
1738  pfile_in_zip_read_info->read_buffer,
1739  uReadThis)!=uReadThis)
1740  return UNZ_ERRNO;
1741 
1742 
1743 # ifndef NOUNCRYPT
1744  if(s->encrypted)
1745  {
1746  uInt i;
1747  for(i=0;i<uReadThis;i++)
1748  pfile_in_zip_read_info->read_buffer[i] =
1749  zdecode(s->keys,s->pcrc_32_tab,
1750  pfile_in_zip_read_info->read_buffer[i]);
1751  }
1752 # endif
1753 
1754 
1755  pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1756 
1757  pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1758 
1759  pfile_in_zip_read_info->stream.next_in =
1760  (Bytef*)pfile_in_zip_read_info->read_buffer;
1761  pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1762  }
1763 
1764  if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1765  {
1766  uInt uDoCopy,i ;
1767 
1768  if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1769  (pfile_in_zip_read_info->rest_read_compressed == 0))
1770  return (iRead==0) ? UNZ_EOF : (int)iRead;
1771 
1772  if (pfile_in_zip_read_info->stream.avail_out <
1773  pfile_in_zip_read_info->stream.avail_in)
1774  uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1775  else
1776  uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1777 
1778  for (i=0;i<uDoCopy;i++)
1779  *(pfile_in_zip_read_info->stream.next_out+i) =
1780  *(pfile_in_zip_read_info->stream.next_in+i);
1781 
1782  pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
1783 
1784  pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1785  pfile_in_zip_read_info->stream.next_out,
1786  uDoCopy);
1787  pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1788  pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1789  pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1790  pfile_in_zip_read_info->stream.next_out += uDoCopy;
1791  pfile_in_zip_read_info->stream.next_in += uDoCopy;
1792  pfile_in_zip_read_info->stream.total_out += uDoCopy;
1793  iRead += uDoCopy;
1794  }
1795  else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
1796  {
1797 #ifdef HAVE_BZIP2
1798  uLong uTotalOutBefore,uTotalOutAfter;
1799  const Bytef *bufBefore;
1800  uLong uOutThis;
1801 
1802  pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
1803  pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
1804  pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
1805  pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
1806  pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
1807  pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
1808  pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
1809  pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
1810 
1811  uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
1812  bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
1813 
1814  err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
1815 
1816  uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
1817  uOutThis = uTotalOutAfter-uTotalOutBefore;
1818 
1819  pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1820 
1821  pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
1822  pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
1823  iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1824 
1825  pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
1826  pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
1827  pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
1828  pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
1829  pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
1830  pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
1831 
1832  if (err==BZ_STREAM_END)
1833  return (iRead==0) ? UNZ_EOF : iRead;
1834  if (err!=BZ_OK)
1835  break;
1836 #endif
1837  } // end Z_BZIP2ED
1838  else
1839  {
1840  ZPOS64_T uTotalOutBefore,uTotalOutAfter;
1841  const Bytef *bufBefore;
1842  ZPOS64_T uOutThis;
1843  int flush=Z_SYNC_FLUSH;
1844 
1845  uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1846  bufBefore = pfile_in_zip_read_info->stream.next_out;
1847 
1848  /*
1849  if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1850  pfile_in_zip_read_info->stream.avail_out) &&
1851  (pfile_in_zip_read_info->rest_read_compressed == 0))
1852  flush = Z_FINISH;
1853  */
1854  err=inflate(&pfile_in_zip_read_info->stream,flush);
1855 
1856  if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
1857  err = Z_DATA_ERROR;
1858 
1859  uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1860  /* Detect overflow, because z_stream.total_out is uLong (32 bits) */
1861  if (uTotalOutAfter<uTotalOutBefore)
1862  uTotalOutAfter += 1LL << 32; /* Add maximum value of uLong + 1 */
1863  uOutThis = uTotalOutAfter-uTotalOutBefore;
1864 
1865  pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1866 
1867  pfile_in_zip_read_info->crc32 =
1868  crc32(pfile_in_zip_read_info->crc32,bufBefore,
1869  (uInt)(uOutThis));
1870 
1871  pfile_in_zip_read_info->rest_read_uncompressed -=
1872  uOutThis;
1873 
1874  iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1875 
1876  if (err==Z_STREAM_END)
1877  return (iRead==0) ? UNZ_EOF : (int)iRead;
1878  if (err!=Z_OK)
1879  break;
1880  }
1881  }
1882 
1883  if (err==Z_OK)
1884  return (int)iRead;
1885  return err;
1886 }
int ZEXPORT inflate(z_streamp strm, int flush)
Definition: inflate.c:623
while(len< limit &&buf1[len]==buf2[len])++len
uInt avail_out
Definition: zlib.h:92
uLong total_in
Definition: zlib.h:89
Bytef * next_out
Definition: zlib.h:91
z_const char * msg
Definition: zlib.h:95
Byte FAR Bytef
Definition: zconf.h:400
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:1063
#define Z_STREAM_END
Definition: zlib.h:178
#define Z_DATA_ERROR
Definition: zlib.h:182
#define Z_SYNC_FLUSH
Definition: zlib.h:170

References z_stream_s::avail_in, z_stream_s::avail_out, file_in_zip64_read_info_s::byte_before_the_zipfile, file_in_zip64_read_info_s::compression_method, file_in_zip64_read_info_s::crc32, crc32(), err, file_in_zip64_read_info_s::filestream, i, if(), inflate(), int, len, z_stream_s::msg, z_stream_s::next_in, z_stream_s::next_out, NULL, file_in_zip64_read_info_s::pos_in_zipfile, file_in_zip64_read_info_s::raw, file_in_zip64_read_info_s::read_buffer, file_in_zip64_read_info_s::rest_read_compressed, file_in_zip64_read_info_s::rest_read_uncompressed, s, file_in_zip64_read_info_s::stream, z_stream_s::total_in, z_stream_s::total_out, file_in_zip64_read_info_s::total_out_64, UNZ_BUFSIZE, UNZ_END_OF_LIST_OF_FILE, UNZ_EOF, UNZ_ERRNO, UNZ_OK, UNZ_PARAMERROR, while(), Z_BZIP2ED, Z_DATA_ERROR, file_in_zip64_read_info_s::z_filefunc, Z_OK, Z_STREAM_END, Z_SYNC_FLUSH, zdecode, ZLIB_FILEFUNC_SEEK_SET, ZREAD64, and ZSEEK64.

Referenced by do_extract_currentfile().

◆ unzSetOffset()

int ZEXPORT unzSetOffset ( unzFile  file,
uLong  pos 
)

Definition at line 2125 of file unzip.c.

2126 {
2127  return unzSetOffset64(file,pos);
2128 }
int pos
Definition: main.c:11
int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
Definition: unzip.c:2107

References pos, and unzSetOffset64().

◆ unzSetOffset64()

int ZEXPORT unzSetOffset64 ( unzFile  file,
ZPOS64_T  pos 
)

Definition at line 2107 of file unzip.c.

2108 {
2109  unz64_s* s;
2110  int err;
2111 
2112  if (file==NULL)
2113  return UNZ_PARAMERROR;
2114  s=(unz64_s*)file;
2115 
2116  s->pos_in_central_dir = pos;
2117  s->num_file = s->gi.number_entry; /* hack */
2118  err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
2119  &s->cur_file_info_internal,
2120  NULL,0,NULL,0,NULL,0);
2121  s->current_file_ok = (err == UNZ_OK);
2122  return err;
2123 }

References err, NULL, pos, s, unz64local_GetCurrentFileInfoInternal(), UNZ_OK, and UNZ_PARAMERROR.

Referenced by unzSetOffset().

◆ unzStringFileNameCompare()

int ZEXPORT unzStringFileNameCompare ( const char *  fileName1,
const char *  fileName2,
int  iCaseSensitivity 
)

Definition at line 390 of file unzip.c.

394 {
395  if (iCaseSensitivity==0)
396  iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
397 
398  if (iCaseSensitivity==1)
399  return strcmp(fileName1,fileName2);
400 
401  return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
402 }
#define CASESENSITIVITYDEFAULTVALUE
Definition: unzip.c:372
#define STRCMPCASENOSENTIVEFUNCTION
Definition: unzip.c:378

References CASESENSITIVITYDEFAULTVALUE, and STRCMPCASENOSENTIVEFUNCTION.

Referenced by unzLocateFile().

◆ unztell()

z_off_t ZEXPORT unztell ( unzFile  file)

Definition at line 1892 of file unzip.c.

1893 {
1894  unz64_s* s;
1895  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1896  if (file==NULL)
1897  return UNZ_PARAMERROR;
1898  s=(unz64_s*)file;
1899  pfile_in_zip_read_info=s->pfile_in_zip_read;
1900 
1901  if (pfile_in_zip_read_info==NULL)
1902  return UNZ_PARAMERROR;
1903 
1904  return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1905 }
#define z_off_t
Definition: zconf.h:504

References NULL, s, file_in_zip64_read_info_s::stream, z_stream_s::total_out, UNZ_PARAMERROR, and z_off_t.

◆ unztell64()

ZPOS64_T ZEXPORT unztell64 ( unzFile  file)

Definition at line 1907 of file unzip.c.

1908 {
1909 
1910  unz64_s* s;
1911  file_in_zip64_read_info_s* pfile_in_zip_read_info;
1912  if (file==NULL)
1913  return (ZPOS64_T)-1;
1914  s=(unz64_s*)file;
1915  pfile_in_zip_read_info=s->pfile_in_zip_read;
1916 
1917  if (pfile_in_zip_read_info==NULL)
1918  return (ZPOS64_T)-1;
1919 
1920  return pfile_in_zip_read_info->total_out_64;
1921 }

References NULL, s, and file_in_zip64_read_info_s::total_out_64.

Variable Documentation

◆ unz_copyright

const char unz_copyright[]
Initial value:
=
" unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"

Definition at line 122 of file unzip.c.

Referenced by unzOpenInternal().