@@ -122,7 +122,7 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
122122# define CWD_STATE_FREE (s ) efree(s)
123123
124124/* {{{ php_zip_extract_file */
125- static int php_zip_extract_file (struct zip * za , char * dest , char * file , size_t file_len )
125+ static int php_zip_extract_file (struct zip * za , char * dest , const char * file , size_t file_len , zip_int64_t idx )
126126{
127127 php_stream_statbuf ssb ;
128128 struct zip_file * zf ;
@@ -140,6 +140,12 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
140140 cwd_state new_state ;
141141 zend_string * file_basename ;
142142
143+ if (idx < 0 ) {
144+ idx = zip_name_locate (za , file , 0 );
145+ if (idx < 0 ) {
146+ return 0 ;
147+ }
148+ }
143149 new_state .cwd = CWD_STATE_ALLOC (1 );
144150 new_state .cwd [0 ] = '\0' ;
145151 new_state .cwd_length = 0 ;
@@ -155,7 +161,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
155161 }
156162 path_cleaned_len = strlen (path_cleaned );
157163
158- if (path_cleaned_len >= MAXPATHLEN || zip_stat (za , file , 0 , & sb ) != 0 ) {
164+ if (path_cleaned_len >= MAXPATHLEN || zip_stat_index (za , idx , 0 , & sb ) != 0 ) {
159165 CWD_STATE_FREE (new_state .cwd );
160166 return 0 ;
161167 }
@@ -230,7 +236,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
230236 return 0 ;
231237 }
232238
233- zf = zip_fopen (za , file , 0 );
239+ zf = zip_fopen_index (za , idx , 0 );
234240 if (zf == NULL ) {
235241 n = -1 ;
236242 goto done ;
@@ -2819,7 +2825,7 @@ PHP_METHOD(ZipArchive, extractTo)
28192825 uint32_t nelems , i ;
28202826
28212827 if (files_str ) {
2822- if (!php_zip_extract_file (intern , pathto , ZSTR_VAL (files_str ), ZSTR_LEN (files_str ))) {
2828+ if (!php_zip_extract_file (intern , pathto , ZSTR_VAL (files_str ), ZSTR_LEN (files_str ), -1 )) {
28232829 RETURN_FALSE ;
28242830 }
28252831 } else if (files_ht ) {
@@ -2834,7 +2840,7 @@ PHP_METHOD(ZipArchive, extractTo)
28342840 case IS_LONG :
28352841 break ;
28362842 case IS_STRING :
2837- if (!php_zip_extract_file (intern , pathto , Z_STRVAL_P (zval_file ), Z_STRLEN_P (zval_file ))) {
2843+ if (!php_zip_extract_file (intern , pathto , Z_STRVAL_P (zval_file ), Z_STRLEN_P (zval_file ), -1 )) {
28382844 RETURN_FALSE ;
28392845 }
28402846 break ;
@@ -2851,8 +2857,8 @@ PHP_METHOD(ZipArchive, extractTo)
28512857 }
28522858
28532859 for (i = 0 ; i < filecount ; i ++ ) {
2854- char * file = ( char * ) zip_get_name (intern , i , ZIP_FL_UNCHANGED );
2855- if (!file || !php_zip_extract_file (intern , pathto , file , strlen (file ))) {
2860+ const char * file = zip_get_name (intern , i , ZIP_FL_UNCHANGED );
2861+ if (!file || !php_zip_extract_file (intern , pathto , file , strlen (file ), i )) {
28562862 RETURN_FALSE ;
28572863 }
28582864 }
0 commit comments