Changeset 7130 for trunk/wp-admin/includes/class-pclzip.php
- Timestamp:
- 03/02/2008 08:17:30 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/class-pclzip.php (modified) (68 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-pclzip.php
r6919 r7130 28 28 // ----- Constants 29 29 define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); 30 30 31 31 // ----- File list separator 32 32 // In version 1.x of PclZip, the separator for file list is a space … … 127 127 //define( 'PCLZIP_OPT_CRYPT', 77018 ); 128 128 define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); 129 129 130 130 // ----- File description attributes 131 131 define( 'PCLZIP_ATT_FILE_NAME', 79001 ); … … 170 170 var $error_code = 1; 171 171 var $error_string = ''; 172 172 173 173 // ----- Current status of the magic_quotes_runtime 174 174 // This value store the php configuration for magic_quotes … … 316 316 $v_filedescr_list = array(); 317 317 $p_result_list = array(); 318 318 319 319 // ----- Look if the $p_filelist is really an array 320 320 if (is_array($p_filelist)) { 321 321 322 322 // ----- Look if the first element is also an array 323 323 // This will mean that this is a file description entry … … 325 325 $v_att_list = $p_filelist; 326 326 } 327 327 328 328 // ----- The list is a list of string names 329 329 else { … … 344 344 return 0; 345 345 } 346 346 347 347 // ----- Reformat the string list 348 348 if (sizeof($v_string_list) != 0) { … … 356 356 } 357 357 } 358 358 359 359 // ----- For each file in the list check the attributes 360 360 $v_supported_attributes … … 506 506 $v_filedescr_list = array(); 507 507 $p_result_list = array(); 508 508 509 509 // ----- Look if the $p_filelist is really an array 510 510 if (is_array($p_filelist)) { 511 511 512 512 // ----- Look if the first element is also an array 513 513 // This will mean that this is a file description entry … … 515 515 $v_att_list = $p_filelist; 516 516 } 517 517 518 518 // ----- The list is a list of string names 519 519 else { … … 534 534 return 0; 535 535 } 536 536 537 537 // ----- Reformat the string list 538 538 if (sizeof($v_string_list) != 0) { … … 541 541 } 542 542 } 543 543 544 544 // ----- For each file in the list check the attributes 545 545 $v_supported_attributes … … 991 991 // PCLZIP_OPT_BY_INDEX : 992 992 // PCLZIP_OPT_BY_NAME : 993 // PCLZIP_OPT_BY_EREG : 993 // PCLZIP_OPT_BY_EREG : 994 994 // PCLZIP_OPT_BY_PREG : 995 995 // Return Values : … … 1066 1066 { 1067 1067 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'"); 1068 1068 1069 1069 $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); 1070 1070 … … 1120 1120 { 1121 1121 $this->privSwapBackMagicQuotes(); 1122 1122 1123 1123 // ----- Error log 1124 1124 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); … … 1449 1449 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", ""); 1450 1450 $v_result=1; 1451 1451 1452 1452 // ----- Read the options 1453 1453 $i=0; … … 1646 1646 return PclZip::errorCode(); 1647 1647 } 1648 1648 1649 1649 // ----- Reduce the index list 1650 1650 // each index item in the list must be a couple with a start and … … 1657 1657 $v_item_list = explode("-", $v_work_list[$j]); 1658 1658 $v_size_item_list = sizeof($v_item_list); 1659 1659 1660 1660 // ----- TBC : Here we might check that each item is a 1661 1661 // real integer ... 1662 1662 1663 1663 // ----- Look for single value 1664 1664 if ($v_size_item_list == 1) { … … 1698 1698 $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; 1699 1699 } 1700 1700 1701 1701 // ----- Sort the items 1702 1702 if ($v_sort_flag) { … … 1830 1830 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", ""); 1831 1831 $v_result=1; 1832 1832 1833 1833 // ----- For each file in the list check the attributes 1834 1834 foreach ($p_file_list as $v_key => $v_value) { 1835 1835 1836 1836 // ----- Check if the option is supported 1837 1837 if (!isset($v_requested_options[$v_key])) { … … 1855 1855 $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); 1856 1856 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'"); 1857 1857 1858 1858 if ($p_filedescr['filename'] == '') { 1859 1859 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); … … 1923 1923 } 1924 1924 } 1925 1925 1926 1926 // end foreach 1927 1927 } 1928 1928 1929 1929 // ----- Return 1930 1930 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); … … 1945 1945 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", ""); 1946 1946 $v_result=1; 1947 1947 1948 1948 // ----- Create a result list 1949 1949 $v_result_list = array(); 1950 1950 1951 1951 // ----- Look each entry 1952 1952 for ($i=0; $i<sizeof($p_filedescr_list); $i++) { 1953 1953 // ----- Get filedescr 1954 1954 $v_descr = $p_filedescr_list[$i]; 1955 1955 1956 1956 // ----- Reduce the filename 1957 1957 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'"); … … 1959 1959 $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); 1960 1960 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'"); 1961 1961 1962 1962 // ----- Get type of descr 1963 1963 if (!file_exists($v_descr['filename'])) { … … 1988 1988 continue; 1989 1989 } 1990 1990 1991 1991 // ----- Calculate the stored filename 1992 1992 $this->privCalculateStoredFilename($v_descr, $p_options); 1993 1993 1994 1994 // ----- Add the descriptor in result list 1995 1995 $v_result_list[sizeof($v_result_list)] = $v_descr; 1996 1996 1997 1997 // ----- Look for folder 1998 1998 if ($v_descr['type'] == 'folder') { … … 2008 2008 continue; 2009 2009 } 2010 2010 2011 2011 // ----- Compose the full filename 2012 2012 $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; 2013 2013 2014 2014 // ----- Look for different stored filename 2015 2015 // Because the name of the folder was changed, the name of the … … 2018 2018 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; 2019 2019 } 2020 2020 2021 2021 $v_dirlist_nb++; 2022 2022 } … … 2026 2026 // TBC : unable to open folder in read mode 2027 2027 } 2028 2028 2029 2029 // ----- Expand each element of the list 2030 2030 if ($v_dirlist_nb != 0) { … … 2034 2034 return $v_result; 2035 2035 } 2036 2036 2037 2037 // ----- Concat the resulting list 2038 2038 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')"); … … 2043 2043 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand."); 2044 2044 } 2045 2045 2046 2046 // ----- Free local array 2047 2047 unset($v_dirlist_descr); 2048 2048 } 2049 2049 } 2050 2050 2051 2051 // ----- Get the result list 2052 2052 $p_filedescr_list = $v_result_list; … … 2069 2069 $v_result=1; 2070 2070 $v_list_detail = array(); 2071 2071 2072 2072 // ----- Magic quotes trick 2073 2073 $this->privDisableMagicQuotes(); … … 2430 2430 // Description : 2431 2431 // Parameters : 2432 // $p_filedescr_list : An array containing the file description 2432 // $p_filedescr_list : An array containing the file description 2433 2433 // or directory names to add in the zip 2434 2434 // $p_result_list : list of added files with their properties (specially the status field) … … 2450 2450 $p_filedescr_list[$j]['filename'] 2451 2451 = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); 2452 2452 2453 2453 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'"); 2454 2454 … … 2504 2504 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'"); 2505 2505 $v_result=1; 2506 2506 2507 2507 // ----- Working variable 2508 2508 $p_filename = $p_filedescr['filename']; … … 2517 2517 return PclZip::errorCode(); 2518 2518 } 2519 2520 // ----- Look for a stored different filename 2519 2520 // ----- Look for a stored different filename 2521 2521 if (isset($p_filedescr['stored_filename'])) { 2522 2522 $v_stored_filename = $p_filedescr['stored_filename']; … … 2584 2584 $p_header['status'] = "filtered"; 2585 2585 } 2586 2586 2587 2587 // ----- Check the path length 2588 2588 if (strlen($p_header['stored_filename']) > 0xFF) { … … 2631 2631 $p_header['compression'] = 8; 2632 2632 } 2633 2633 2634 2634 // ----- Look for encryption 2635 2635 /* … … 2637 2637 && ($p_options[PCLZIP_OPT_CRYPT] != "")) { 2638 2638 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ...."); 2639 2639 2640 2640 // Should be a random header 2641 2641 $v_header = 'xxxxxxxxxxxx'; … … 2645 2645 $p_header['crc'], 2646 2646 "test"); 2647 2647 2648 2648 $p_header['compressed_size'] += 12; 2649 2649 $p_header['flag'] = 1; 2650 2650 2651 2651 // ----- Add the header to the data 2652 2652 $v_content_compressed = $v_header.$v_content_compressed; … … 2663 2663 2664 2664 // ----- Write the compressed (or not) content 2665 @fwrite($this->zip_fd, 2665 @fwrite($this->zip_fd, 2666 2666 $v_content_compressed, $p_header['compressed_size']); 2667 2667 2668 2668 // ----- Close the file 2669 2669 @fclose($v_file); … … 2731 2731 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'"); 2732 2732 $v_result=1; 2733 2733 2734 2734 // ----- Working variables 2735 2735 $p_filename = $p_filedescr['filename']; … … 2758 2758 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'"); 2759 2759 } 2760 2760 2761 2761 // ----- Look for path and/or short name change 2762 2762 else { … … 2789 2789 if ( (substr($p_filename, 0, 2) == "./") 2790 2790 || (substr($p_remove_dir, 0, 2) == "./")) { 2791 2791 2792 2792 if ( (substr($p_filename, 0, 2) == "./") 2793 2793 && (substr($p_remove_dir, 0, 2) != "./")) { … … 2829 2829 $p_filedescr['stored_filename'] = $v_stored_filename; 2830 2830 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename'])); 2831 2831 2832 2832 // ----- Return 2833 2833 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); … … 2992 2992 // ----- Magic quotes trick 2993 2993 $this->privSwapBackMagicQuotes(); 2994 2994 2995 2995 // ----- Error log 2996 2996 PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); … … 3271 3271 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { 3272 3272 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'"); 3273 3273 3274 3274 // ----- Look if the index is in the list 3275 3275 for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { … … 3311 3311 3312 3312 $this->privSwapBackMagicQuotes(); 3313 3313 3314 3314 PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, 3315 3315 "Filename '".$v_header['stored_filename']."' is " … … 3321 3321 } 3322 3322 } 3323 3323 3324 3324 // ----- Check encrypted files 3325 3325 if (($v_extract) && (($v_header['flag'] & 1) == 1)) { … … 3358 3358 $v_extract = false; 3359 3359 } 3360 3360 3361 3361 // ----- Look for real extraction 3362 3362 if ($v_extract) … … 3412 3412 // ----- Next extracted file 3413 3413 $v_nb_extracted++; 3414 3414 3415 3415 // ----- Look for user callback abort 3416 3416 if ($v_result1 == 2) { … … 3564 3564 $p_entry['filename'] = $p_path."/".$p_entry['filename']; 3565 3565 } 3566 3566 3567 3567 // ----- Check a base_dir_restriction 3568 3568 if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { … … 3570 3570 $v_inclusion 3571 3571 = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], 3572 $p_entry['filename']); 3572 $p_entry['filename']); 3573 3573 if ($v_inclusion == 0) { 3574 3574 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction"); … … 3600 3600 $v_result = 1; 3601 3601 } 3602 3602 3603 3603 // ----- Look for abort result 3604 3604 if ($v_result == 2) { … … 3632 3632 // ----- Change the file status 3633 3633 $p_entry['status'] = "already_a_directory"; 3634 3634 3635 3635 // ----- Look for PCLZIP_OPT_STOP_ON_ERROR 3636 3636 // For historical reason first PclZip implementation does not stop … … 3765 3765 @fwrite($v_dest_file, $v_binary_data, $v_read_size); 3766 3766 */ 3767 @fwrite($v_dest_file, $v_buffer, $v_read_size); 3767 @fwrite($v_dest_file, $v_buffer, $v_read_size); 3768 3768 $v_size -= $v_read_size; 3769 3769 } … … 3774 3774 // ----- Change the file mtime 3775 3775 touch($p_entry['filename'], $p_entry['mtime']); 3776 3776 3777 3777 3778 3778 } … … 3787 3787 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes"); 3788 3788 $v_encryption_header = @fread($this->zip_fd, 12); 3789 3789 3790 3790 // ----- Read the encrypted & compressed file in a buffer 3791 3791 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes"); 3792 3792 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12); 3793 3793 3794 3794 // ----- Decrypt the buffer 3795 3795 $this->privDecrypt($v_encryption_header, $v_buffer, … … 3803 3803 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3804 3804 } 3805 3805 3806 3806 // ----- Decompress the file 3807 3807 $v_file_content = @gzinflate($v_buffer); … … 3813 3813 // TBC 3814 3814 $p_entry['status'] = "error"; 3815 3815 3816 3816 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); 3817 3817 return $v_result; 3818 3818 } 3819 3819 3820 3820 // ----- Opening destination file 3821 3821 if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { … … 3856 3856 $p_entry['status'] = "skipped"; 3857 3857 } 3858 3858 3859 3859 // ----- Look for post-extract callback 3860 3860 elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { … … 3965 3965 // ----- Read the compressed file in a buffer (one shot) 3966 3966 $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); 3967 3967 3968 3968 // ----- Decompress the file 3969 3969 $v_file_content = gzinflate($v_buffer); … … 4054 4054 // ----- Reading the file 4055 4055 $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); 4056 4056 4057 4057 // ----- Decompress the file 4058 4058 if (($p_string = @gzinflate($v_data)) === FALSE) { … … 4804 4804 return $v_result; 4805 4805 } 4806 4806 4807 4807 // ----- Check that local file header is same as central file header 4808 4808 if ($this->privCheckFileHeaders($v_local_header, … … 4897 4897 //@rename($v_zip_temp_name, $this->zipname); 4898 4898 PclZipUtilRename($v_zip_temp_name, $this->zipname); 4899 4899 4900 4900 // ----- Destroy the temporary archive 4901 4901 unset($v_temp_zip); 4902 4902 } 4903 4903 4904 4904 // ----- Remove every files : reset the file 4905 4905 else if ($v_central_dir['entries'] != 0) { … … 5316 5316 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size.""); 5317 5317 $v_result=1; 5318 5318 5319 5319 // ----- To Be Modified ;-) 5320 5320 $v_pwd = "test"; 5321 5321 5322 5322 $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, 5323 5323 $p_crc, $v_pwd); 5324 5324 5325 5325 // ----- Return 5326 5326 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result); … … 5472 5472 } 5473 5473 } 5474 5474 5475 5475 // ----- Look for skip 5476 5476 if ($v_skip > 0) { … … 5507 5507 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'"); 5508 5508 $v_result = 1; 5509 5509 5510 5510 // ----- Look for path beginning by ./ 5511 5511 if ( ($p_dir == '.') … … 5698 5698 { 5699 5699 //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'"); 5700 5700 5701 5701 $v_list = get_defined_constants(); 5702 5702 for (reset($v_list); $v_key = key($v_list); next($v_list)) { … … 5710 5710 } 5711 5711 } 5712 5712 5713 5713 $v_result = 'Unknown'; 5714 5714
Note: See TracChangeset
for help on using the changeset viewer.