@@ -122,7 +122,7 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
122
122
# define CWD_STATE_FREE (s ) efree(s)
123
123
124
124
/* {{{ 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 )
126
126
{
127
127
php_stream_statbuf ssb ;
128
128
struct zip_file * zf ;
@@ -140,6 +140,12 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
140
140
cwd_state new_state ;
141
141
zend_string * file_basename ;
142
142
143
+ if (idx < 0 ) {
144
+ idx = zip_name_locate (za , file , 0 );
145
+ if (idx < 0 ) {
146
+ return 0 ;
147
+ }
148
+ }
143
149
new_state .cwd = CWD_STATE_ALLOC (1 );
144
150
new_state .cwd [0 ] = '\0' ;
145
151
new_state .cwd_length = 0 ;
@@ -155,7 +161,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
155
161
}
156
162
path_cleaned_len = strlen (path_cleaned );
157
163
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 ) {
159
165
CWD_STATE_FREE (new_state .cwd );
160
166
return 0 ;
161
167
}
@@ -230,7 +236,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, size_t
230
236
return 0 ;
231
237
}
232
238
233
- zf = zip_fopen (za , file , 0 );
239
+ zf = zip_fopen_index (za , idx , 0 );
234
240
if (zf == NULL ) {
235
241
n = -1 ;
236
242
goto done ;
@@ -2819,7 +2825,7 @@ PHP_METHOD(ZipArchive, extractTo)
2819
2825
uint32_t nelems , i ;
2820
2826
2821
2827
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 )) {
2823
2829
RETURN_FALSE ;
2824
2830
}
2825
2831
} else if (files_ht ) {
@@ -2834,7 +2840,7 @@ PHP_METHOD(ZipArchive, extractTo)
2834
2840
case IS_LONG :
2835
2841
break ;
2836
2842
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 )) {
2838
2844
RETURN_FALSE ;
2839
2845
}
2840
2846
break ;
@@ -2851,8 +2857,8 @@ PHP_METHOD(ZipArchive, extractTo)
2851
2857
}
2852
2858
2853
2859
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 )) {
2856
2862
RETURN_FALSE ;
2857
2863
}
2858
2864
}
0 commit comments