| OLD | NEW |
| 1 /* unzip.c -- IO for uncompress .zip files using zlib | 1 /* unzip.c -- IO for uncompress .zip files using zlib |
| 2 Version 1.1, February 14h, 2010 | 2 Version 1.1, February 14h, 2010 |
| 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html
) | 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html
) |
| 4 | 4 |
| 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) | 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) |
| 6 | 6 |
| 7 Modifications of Unzip for Zip64 | 7 Modifications of Unzip for Zip64 |
| 8 Copyright (C) 2007-2008 Even Rouault | 8 Copyright (C) 2007-2008 Even Rouault |
| 9 | 9 |
| 10 Modifications for Zip64 support on both zip and unzip | 10 Modifications for Zip64 support on both zip and unzip |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 unz_file_info64 cur_file_info; /* public info about the current file in zip*
/ | 181 unz_file_info64 cur_file_info; /* public info about the current file in zip*
/ |
| 182 unz_file_info64_internal cur_file_info_internal; /* private info about it*/ | 182 unz_file_info64_internal cur_file_info_internal; /* private info about it*/ |
| 183 file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current | 183 file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current |
| 184 file if we are decompressing it */ | 184 file if we are decompressing it */ |
| 185 int encrypted; | 185 int encrypted; |
| 186 | 186 |
| 187 int isZip64; | 187 int isZip64; |
| 188 | 188 |
| 189 # ifndef NOUNCRYPT | 189 # ifndef NOUNCRYPT |
| 190 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | 190 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
| 191 const unsigned long* pcrc_32_tab; | 191 const z_crc_t* pcrc_32_tab; |
| 192 # endif | 192 # endif |
| 193 } unz64_s; | 193 } unz64_s; |
| 194 | 194 |
| 195 | 195 |
| 196 #ifndef NOUNCRYPT | 196 #ifndef NOUNCRYPT |
| 197 #include "crypt.h" | 197 #include "crypt.h" |
| 198 #endif | 198 #endif |
| 199 | 199 |
| 200 /* =========================================================================== | 200 /* =========================================================================== |
| 201 Read a byte from a gz_stream; update next_in and avail_in. Return EOF | 201 Read a byte from a gz_stream; update next_in and avail_in. Return EOF |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 { | 794 { |
| 795 return unzOpenInternal(path, NULL, 0); | 795 return unzOpenInternal(path, NULL, 0); |
| 796 } | 796 } |
| 797 | 797 |
| 798 extern unzFile ZEXPORT unzOpen64 (const void *path) | 798 extern unzFile ZEXPORT unzOpen64 (const void *path) |
| 799 { | 799 { |
| 800 return unzOpenInternal(path, NULL, 1); | 800 return unzOpenInternal(path, NULL, 1); |
| 801 } | 801 } |
| 802 | 802 |
| 803 /* | 803 /* |
| 804 Close a ZipFile opened with unzipOpen. | 804 Close a ZipFile opened with unzOpen. |
| 805 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later)
, | 805 If there is files inside the .Zip opened with unzOpenCurrentFile (see later), |
| 806 these files MUST be closed with unzipCloseCurrentFile before call unzipClose
. | 806 these files MUST be closed with unzCloseCurrentFile before call unzClose. |
| 807 return UNZ_OK if there is no problem. */ | 807 return UNZ_OK if there is no problem. */ |
| 808 extern int ZEXPORT unzClose (unzFile file) | 808 extern int ZEXPORT unzClose (unzFile file) |
| 809 { | 809 { |
| 810 unz64_s* s; | 810 unz64_s* s; |
| 811 if (file==NULL) | 811 if (file==NULL) |
| 812 return UNZ_PARAMERROR; | 812 return UNZ_PARAMERROR; |
| 813 s=(unz64_s*)file; | 813 s=(unz64_s*)file; |
| 814 | 814 |
| 815 if (s->pfile_in_zip_read!=NULL) | 815 if (s->pfile_in_zip_read!=NULL) |
| 816 unzCloseCurrentFile(file); | 816 unzCloseCurrentFile(file); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 err=UNZ_ERRNO; | 1033 err=UNZ_ERRNO; |
| 1034 | 1034 |
| 1035 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) !=
UNZ_OK) | 1035 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) !=
UNZ_OK) |
| 1036 err=UNZ_ERRNO; | 1036 err=UNZ_ERRNO; |
| 1037 | 1037 |
| 1038 /* ZIP64 extra fields */ | 1038 /* ZIP64 extra fields */ |
| 1039 if (headerId == 0x0001) | 1039 if (headerId == 0x0001) |
| 1040 { | 1040 { |
| 1041 uLong uL; | 1041 uLong uL; |
| 1042 | 1042 |
| 1043 if(file_info.unc
ompressed_size == (ZPOS64_T)(unsigned long)-1) | 1043 if(file_info.unc
ompressed_size == MAXU32) |
| 1044 { | 1044 { |
| 1045 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) !=
UNZ_OK) | 1045 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) !=
UNZ_OK) |
| 1046
err=UNZ_ERRNO; | 1046
err=UNZ_ERRNO; |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 if(file_info.com
pressed_size == (ZPOS64_T)(unsigned long)-1) | 1049 if(file_info.com
pressed_size == MAXU32) |
| 1050 { | 1050 { |
| 1051 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UN
Z_OK) | 1051 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UN
Z_OK) |
| 1052
err=UNZ_ERRNO; | 1052
err=UNZ_ERRNO; |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 if(file_info_int
ernal.offset_curfile == (ZPOS64_T)(unsigned long)-1) | 1055 if(file_info_int
ernal.offset_curfile == MAXU32) |
| 1056 { | 1056 { |
| 1057 /* Relat
ive Header offset */ | 1057 /* Relat
ive Header offset */ |
| 1058 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfil
e) != UNZ_OK) | 1058 if (unz6
4local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfil
e) != UNZ_OK) |
| 1059
err=UNZ_ERRNO; | 1059
err=UNZ_ERRNO; |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 if(file_info.dis
k_num_start == (unsigned long)-1) | 1062 if(file_info.dis
k_num_start == MAXU32) |
| 1063 { | 1063 { |
| 1064 /* Disk
Start Number */ | 1064 /* Disk
Start Number */ |
| 1065 if (unz6
4local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) | 1065 if (unz6
4local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) |
| 1066
err=UNZ_ERRNO; | 1066
err=UNZ_ERRNO; |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 } | 1069 } |
| 1070 else | 1070 else |
| 1071 { | 1071 { |
| 1072 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_
SEEK_CUR)!=0) | 1072 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_
SEEK_CUR)!=0) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 char * szFileName, uLong fileNameBuffe
rSize, | 1138 char * szFileName, uLong fileNameBuffe
rSize, |
| 1139 void *extraField, uLong extraFieldBuff
erSize, | 1139 void *extraField, uLong extraFieldBuff
erSize, |
| 1140 char* szComment, uLong commentBufferS
ize) | 1140 char* szComment, uLong commentBufferS
ize) |
| 1141 { | 1141 { |
| 1142 int err; | 1142 int err; |
| 1143 unz_file_info64 file_info64; | 1143 unz_file_info64 file_info64; |
| 1144 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, | 1144 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, |
| 1145 szFileName,fileNameBufferSize, | 1145 szFileName,fileNameBufferSize, |
| 1146 extraField,extraFieldBufferSize, | 1146 extraField,extraFieldBufferSize, |
| 1147 szComment,commentBufferSize); | 1147 szComment,commentBufferSize); |
| 1148 if (err==UNZ_OK) | 1148 if ((err==UNZ_OK) && (pfile_info != NULL)) |
| 1149 { | 1149 { |
| 1150 pfile_info->version = file_info64.version; | 1150 pfile_info->version = file_info64.version; |
| 1151 pfile_info->version_needed = file_info64.version_needed; | 1151 pfile_info->version_needed = file_info64.version_needed; |
| 1152 pfile_info->flag = file_info64.flag; | 1152 pfile_info->flag = file_info64.flag; |
| 1153 pfile_info->compression_method = file_info64.compression_method; | 1153 pfile_info->compression_method = file_info64.compression_method; |
| 1154 pfile_info->dosDate = file_info64.dosDate; | 1154 pfile_info->dosDate = file_info64.dosDate; |
| 1155 pfile_info->crc = file_info64.crc; | 1155 pfile_info->crc = file_info64.crc; |
| 1156 | 1156 |
| 1157 pfile_info->size_filename = file_info64.size_filename; | 1157 pfile_info->size_filename = file_info64.size_filename; |
| 1158 pfile_info->size_file_extra = file_info64.size_file_extra; | 1158 pfile_info->size_file_extra = file_info64.size_file_extra; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, | 1216 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, |
| 1217 &s->cur_file_info_internal, | 1217 &s->cur_file_info_internal, |
| 1218 NULL,0,NULL,0,NULL,0); | 1218 NULL,0,NULL,0,NULL,0); |
| 1219 s->current_file_ok = (err == UNZ_OK); | 1219 s->current_file_ok = (err == UNZ_OK); |
| 1220 return err; | 1220 return err; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 | 1223 |
| 1224 /* | 1224 /* |
| 1225 Try locate the file szFileName in the zipfile. | 1225 Try locate the file szFileName in the zipfile. |
| 1226 For the iCaseSensitivity signification, see unzipStringFileNameCompare | 1226 For the iCaseSensitivity signification, see unzStringFileNameCompare |
| 1227 | 1227 |
| 1228 return value : | 1228 return value : |
| 1229 UNZ_OK if the file is found. It becomes the current file. | 1229 UNZ_OK if the file is found. It becomes the current file. |
| 1230 UNZ_END_OF_LIST_OF_FILE if the file is not found | 1230 UNZ_END_OF_LIST_OF_FILE if the file is not found |
| 1231 */ | 1231 */ |
| 1232 extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCas
eSensitivity) | 1232 extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCas
eSensitivity) |
| 1233 { | 1233 { |
| 1234 unz64_s* s; | 1234 unz64_s* s; |
| 1235 int err; | 1235 int err; |
| 1236 | 1236 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1689 file_in_zip64_read_info_s* pfile_in_zip_read_info; | 1689 file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 1690 if (file==NULL) | 1690 if (file==NULL) |
| 1691 return UNZ_PARAMERROR; | 1691 return UNZ_PARAMERROR; |
| 1692 s=(unz64_s*)file; | 1692 s=(unz64_s*)file; |
| 1693 pfile_in_zip_read_info=s->pfile_in_zip_read; | 1693 pfile_in_zip_read_info=s->pfile_in_zip_read; |
| 1694 | 1694 |
| 1695 if (pfile_in_zip_read_info==NULL) | 1695 if (pfile_in_zip_read_info==NULL) |
| 1696 return UNZ_PARAMERROR; | 1696 return UNZ_PARAMERROR; |
| 1697 | 1697 |
| 1698 | 1698 |
| 1699 if ((pfile_in_zip_read_info->read_buffer == NULL)) | 1699 if (pfile_in_zip_read_info->read_buffer == NULL) |
| 1700 return UNZ_END_OF_LIST_OF_FILE; | 1700 return UNZ_END_OF_LIST_OF_FILE; |
| 1701 if (len==0) | 1701 if (len==0) |
| 1702 return 0; | 1702 return 0; |
| 1703 | 1703 |
| 1704 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; | 1704 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; |
| 1705 | 1705 |
| 1706 pfile_in_zip_read_info->stream.avail_out = (uInt)len; | 1706 pfile_in_zip_read_info->stream.avail_out = (uInt)len; |
| 1707 | 1707 |
| 1708 if ((len>pfile_in_zip_read_info->rest_read_compressed+ | 1708 if ((len>pfile_in_zip_read_info->rest_read_compressed+ |
| 1709 pfile_in_zip_read_info->stream.avail_in) && | 1709 pfile_in_zip_read_info->stream.avail_in) && |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 | 1986 |
| 1987 if (ZREAD64(pfile_in_zip_read_info->z_filefunc, | 1987 if (ZREAD64(pfile_in_zip_read_info->z_filefunc, |
| 1988 pfile_in_zip_read_info->filestream, | 1988 pfile_in_zip_read_info->filestream, |
| 1989 buf,read_now)!=read_now) | 1989 buf,read_now)!=read_now) |
| 1990 return UNZ_ERRNO; | 1990 return UNZ_ERRNO; |
| 1991 | 1991 |
| 1992 return (int)read_now; | 1992 return (int)read_now; |
| 1993 } | 1993 } |
| 1994 | 1994 |
| 1995 /* | 1995 /* |
| 1996 Close the file in zip opened with unzipOpenCurrentFile | 1996 Close the file in zip opened with unzOpenCurrentFile |
| 1997 Return UNZ_CRCERROR if all the file was read but the CRC is not good | 1997 Return UNZ_CRCERROR if all the file was read but the CRC is not good |
| 1998 */ | 1998 */ |
| 1999 extern int ZEXPORT unzCloseCurrentFile (unzFile file) | 1999 extern int ZEXPORT unzCloseCurrentFile (unzFile file) |
| 2000 { | 2000 { |
| 2001 int err=UNZ_OK; | 2001 int err=UNZ_OK; |
| 2002 | 2002 |
| 2003 unz64_s* s; | 2003 unz64_s* s; |
| 2004 file_in_zip64_read_info_s* pfile_in_zip_read_info; | 2004 file_in_zip64_read_info_s* pfile_in_zip_read_info; |
| 2005 if (file==NULL) | 2005 if (file==NULL) |
| 2006 return UNZ_PARAMERROR; | 2006 return UNZ_PARAMERROR; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 &s->cur_file_info_internal, | 2111 &s->cur_file_info_internal, |
| 2112 NULL,0,NULL,0,NULL,0); | 2112 NULL,0,NULL,0,NULL,0); |
| 2113 s->current_file_ok = (err == UNZ_OK); | 2113 s->current_file_ok = (err == UNZ_OK); |
| 2114 return err; | 2114 return err; |
| 2115 } | 2115 } |
| 2116 | 2116 |
| 2117 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) | 2117 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) |
| 2118 { | 2118 { |
| 2119 return unzSetOffset64(file,pos); | 2119 return unzSetOffset64(file,pos); |
| 2120 } | 2120 } |
| OLD | NEW |