| OLD | NEW |
| 1 /* zip.c -- IO on .zip files using zlib | 1 /* zip.c -- IO on .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 for Zip64 support | 7 Modifications for Zip64 support |
| 8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | 8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) |
| 9 | 9 |
| 10 For more info read MiniZip_info.txt | 10 For more info read MiniZip_info.txt |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ | 150 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ |
| 151 uLong dosDate; | 151 uLong dosDate; |
| 152 uLong crc32; | 152 uLong crc32; |
| 153 int encrypt; | 153 int encrypt; |
| 154 int zip64; /* Add ZIP64 extened information in the extra fiel
d */ | 154 int zip64; /* Add ZIP64 extened information in the extra fiel
d */ |
| 155 ZPOS64_T pos_zip64extrainfo; | 155 ZPOS64_T pos_zip64extrainfo; |
| 156 ZPOS64_T totalCompressedData; | 156 ZPOS64_T totalCompressedData; |
| 157 ZPOS64_T totalUncompressedData; | 157 ZPOS64_T totalUncompressedData; |
| 158 #ifndef NOCRYPT | 158 #ifndef NOCRYPT |
| 159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | 159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
| 160 const unsigned long* pcrc_32_tab; | 160 const z_crc_t* pcrc_32_tab; |
| 161 int crypt_header_size; | 161 int crypt_header_size; |
| 162 #endif | 162 #endif |
| 163 } curfile64_info; | 163 } curfile64_info; |
| 164 | 164 |
| 165 typedef struct | 165 typedef struct |
| 166 { | 166 { |
| 167 zlib_filefunc64_32_def z_filefunc; | 167 zlib_filefunc64_32_def z_filefunc; |
| 168 voidpf filestream; /* io structore of the zipfile */ | 168 voidpf filestream; /* io structore of the zipfile */ |
| 169 linkedlist_data central_dir;/* datablock with central dir in construction*/ | 169 linkedlist_data central_dir;/* datablock with central dir in construction*/ |
| 170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ | 170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 const char* password, uLong crcForCrypt
ing, | 1060 const char* password, uLong crcForCrypt
ing, |
| 1061 uLong versionMadeBy, uLong flagBase, in
t zip64) | 1061 uLong versionMadeBy, uLong flagBase, in
t zip64) |
| 1062 { | 1062 { |
| 1063 zip64_internal* zi; | 1063 zip64_internal* zi; |
| 1064 uInt size_filename; | 1064 uInt size_filename; |
| 1065 uInt size_comment; | 1065 uInt size_comment; |
| 1066 uInt i; | 1066 uInt i; |
| 1067 int err = ZIP_OK; | 1067 int err = ZIP_OK; |
| 1068 | 1068 |
| 1069 # ifdef NOCRYPT | 1069 # ifdef NOCRYPT |
| 1070 (crcForCrypting); |
| 1070 if (password != NULL) | 1071 if (password != NULL) |
| 1071 return ZIP_PARAMERROR; | 1072 return ZIP_PARAMERROR; |
| 1072 # endif | 1073 # endif |
| 1073 | 1074 |
| 1074 if (file == NULL) | 1075 if (file == NULL) |
| 1075 return ZIP_PARAMERROR; | 1076 return ZIP_PARAMERROR; |
| 1076 | 1077 |
| 1077 #ifdef HAVE_BZIP2 | 1078 #ifdef HAVE_BZIP2 |
| 1078 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) | 1079 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) |
| 1079 return ZIP_PARAMERROR; | 1080 return ZIP_PARAMERROR; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1107 { | 1108 { |
| 1108 if (zipfi->dosDate != 0) | 1109 if (zipfi->dosDate != 0) |
| 1109 zi->ci.dosDate = zipfi->dosDate; | 1110 zi->ci.dosDate = zipfi->dosDate; |
| 1110 else | 1111 else |
| 1111 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); | 1112 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 zi->ci.flag = flagBase; | 1115 zi->ci.flag = flagBase; |
| 1115 if ((level==8) || (level==9)) | 1116 if ((level==8) || (level==9)) |
| 1116 zi->ci.flag |= 2; | 1117 zi->ci.flag |= 2; |
| 1117 if ((level==2)) | 1118 if (level==2) |
| 1118 zi->ci.flag |= 4; | 1119 zi->ci.flag |= 4; |
| 1119 if ((level==1)) | 1120 if (level==1) |
| 1120 zi->ci.flag |= 6; | 1121 zi->ci.flag |= 6; |
| 1121 if (password != NULL) | 1122 if (password != NULL) |
| 1122 zi->ci.flag |= 1; | 1123 zi->ci.flag |= 1; |
| 1123 | 1124 |
| 1124 zi->ci.crc32 = 0; | 1125 zi->ci.crc32 = 0; |
| 1125 zi->ci.method = method; | 1126 zi->ci.method = method; |
| 1126 zi->ci.encrypt = 0; | 1127 zi->ci.encrypt = 0; |
| 1127 zi->ci.stream_initialised = 0; | 1128 zi->ci.stream_initialised = 0; |
| 1128 zi->ci.pos_in_buffered_data = 0; | 1129 zi->ci.pos_in_buffered_data = 0; |
| 1129 zi->ci.raw = raw; | 1130 zi->ci.raw = raw; |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 // Update the LocalFileHeader with the new values. | 1704 // Update the LocalFileHeader with the new values. |
| 1704 | 1705 |
| 1705 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); | 1706 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); |
| 1706 | 1707 |
| 1707 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,
ZLIB_FILEFUNC_SEEK_SET)!=0) | 1708 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,
ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1708 err = ZIP_ERRNO; | 1709 err = ZIP_ERRNO; |
| 1709 | 1710 |
| 1710 if (err==ZIP_OK) | 1711 if (err==ZIP_OK) |
| 1711 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /
* crc 32, unknown */ | 1712 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /
* crc 32, unknown */ |
| 1712 | 1713 |
| 1713 if(uncompressed_size >= 0xffffffff) | 1714 if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff ) |
| 1714 { | 1715 { |
| 1715 if(zi->ci.pos_zip64extrainfo > 0) | 1716 if(zi->ci.pos_zip64extrainfo > 0) |
| 1716 { | 1717 { |
| 1717 // Update the size in the ZIP64 extended field. | 1718 // Update the size in the ZIP64 extended field. |
| 1718 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo
+ 4,ZLIB_FILEFUNC_SEEK_SET)!=0) | 1719 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo
+ 4,ZLIB_FILEFUNC_SEEK_SET)!=0) |
| 1719 err = ZIP_ERRNO; | 1720 err = ZIP_ERRNO; |
| 1720 | 1721 |
| 1721 if (err==ZIP_OK) /* compressed size, unknown */ | 1722 if (err==ZIP_OK) /* compressed size, unknown */ |
| 1722 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompr
essed_size, 8); | 1723 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompr
essed_size, 8); |
| 1723 | 1724 |
| 1724 if (err==ZIP_OK) /* uncompressed size, unknown */ | 1725 if (err==ZIP_OK) /* uncompressed size, unknown */ |
| 1725 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compres
sed_size, 8); | 1726 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compres
sed_size, 8); |
| 1726 } | 1727 } |
| 1728 else |
| 1729 err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for z
ip64 info -> fatal |
| 1727 } | 1730 } |
| 1728 else | 1731 else |
| 1729 { | 1732 { |
| 1730 if (err==ZIP_OK) /* compressed size, unknown */ | 1733 if (err==ZIP_OK) /* compressed size, unknown */ |
| 1731 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compresse
d_size,4); | 1734 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compresse
d_size,4); |
| 1732 | 1735 |
| 1733 if (err==ZIP_OK) /* uncompressed size, unknown */ | 1736 if (err==ZIP_OK) /* uncompressed size, unknown */ |
| 1734 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompres
sed_size,4); | 1737 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompres
sed_size,4); |
| 1735 } | 1738 } |
| 1736 | 1739 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_central
dir,4); | 1848 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_central
dir,4); |
| 1846 | 1849 |
| 1847 if (err==ZIP_OK) /* offset of start of central directory with respect to the s
tarting disk number */ | 1850 if (err==ZIP_OK) /* offset of start of central directory with respect to the s
tarting disk number */ |
| 1848 { | 1851 { |
| 1849 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | 1852 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; |
| 1850 if(pos >= 0xffffffff) | 1853 if(pos >= 0xffffffff) |
| 1851 { | 1854 { |
| 1852 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xfffffff
f,4); | 1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xfffffff
f,4); |
| 1853 } | 1856 } |
| 1854 else | 1857 else |
| 1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLo
ng)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); | 1858 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centrald
ir_pos_inzip - zi->add_position_when_writting_offset),4); |
| 1856 } | 1859 } |
| 1857 | 1860 |
| 1858 return err; | 1861 return err; |
| 1859 } | 1862 } |
| 1860 | 1863 |
| 1861 int Write_GlobalComment(zip64_internal* zi, const char* global_comment) | 1864 int Write_GlobalComment(zip64_internal* zi, const char* global_comment) |
| 1862 { | 1865 { |
| 1863 int err = ZIP_OK; | 1866 int err = ZIP_OK; |
| 1864 uInt size_global_comment = 0; | 1867 uInt size_global_comment = 0; |
| 1865 | 1868 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 err = ZIP_ERRNO; | 1915 err = ZIP_ERRNO; |
| 1913 } | 1916 } |
| 1914 | 1917 |
| 1915 size_centraldir += ldi->filled_in_this_block; | 1918 size_centraldir += ldi->filled_in_this_block; |
| 1916 ldi = ldi->next_datablock; | 1919 ldi = ldi->next_datablock; |
| 1917 } | 1920 } |
| 1918 } | 1921 } |
| 1919 free_linkedlist(&(zi->central_dir)); | 1922 free_linkedlist(&(zi->central_dir)); |
| 1920 | 1923 |
| 1921 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | 1924 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; |
| 1922 if(pos >= 0xffffffff) | 1925 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) |
| 1923 { | 1926 { |
| 1924 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); | 1927 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); |
| 1925 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos
_inzip); | 1928 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos
_inzip); |
| 1926 | 1929 |
| 1927 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); | 1930 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); |
| 1928 } | 1931 } |
| 1929 | 1932 |
| 1930 if (err==ZIP_OK) | 1933 if (err==ZIP_OK) |
| 1931 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_po
s_inzip); | 1934 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_po
s_inzip); |
| 1932 | 1935 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 | 1998 |
| 1996 retVal = ZIP_OK; | 1999 retVal = ZIP_OK; |
| 1997 } | 2000 } |
| 1998 else | 2001 else |
| 1999 retVal = ZIP_ERRNO; | 2002 retVal = ZIP_ERRNO; |
| 2000 | 2003 |
| 2001 TRYFREE(pNewHeader); | 2004 TRYFREE(pNewHeader); |
| 2002 | 2005 |
| 2003 return retVal; | 2006 return retVal; |
| 2004 } | 2007 } |
| OLD | NEW |