@@ -2184,7 +2184,7 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
21842184 goto err_oldpath ;
21852185 }
21862186
2187- phar_flush_ex (phar , NULL , 1 , & error );
2187+ phar_flush_ex (phar , NULL , true , & error );
21882188
21892189 if (error ) {
21902190 zend_hash_str_del (& (PHAR_G (phar_fname_map )), newpath , phar -> fname_len );
@@ -4133,7 +4133,7 @@ PHP_METHOD(Phar, delMetadata)
41334133}
41344134/* }}} */
41354135
4136- static zend_result phar_extract_file (bool overwrite , phar_entry_info * entry , char * dest , size_t dest_len , char * * error ) /* {{{ */
4136+ ZEND_ATTRIBUTE_NONNULL static zend_result phar_extract_file (bool overwrite , phar_entry_info * entry , const zend_string * dest , char * * error ) /* {{{ */
41374137{
41384138 php_stream_statbuf ssb ;
41394139 size_t len ;
@@ -4161,7 +4161,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
41614161 if (virtual_file_ex (& new_state , ZSTR_VAL (entry -> filename ), NULL , CWD_EXPAND ) != 0 ||
41624162 new_state .cwd_length <= 1 ) {
41634163 if (EINVAL == errno && ZSTR_LEN (entry -> filename ) > 50 ) {
4164- spprintf (error , 4096 , "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem" , ZSTR_VAL (entry -> filename ), dest );
4164+ spprintf (error , 4096 , "Cannot extract \"%.50s...\" to \"%s...\", extracted filename is too long for filesystem" , ZSTR_VAL (entry -> filename ), ZSTR_VAL ( dest ) );
41654165 } else {
41664166 spprintf (error , 4096 , "Cannot extract \"%s\", internal error" , ZSTR_VAL (entry -> filename ));
41674167 }
@@ -4183,7 +4183,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
41834183 }
41844184#endif
41854185
4186- len = spprintf (& fullpath , 0 , "%s/%s" , dest , filename );
4186+ len = spprintf (& fullpath , 0 , "%s/%s" , ZSTR_VAL ( dest ) , filename );
41874187
41884188 if (len >= MAXPATHLEN ) {
41894189 /* truncate for error message */
@@ -4224,9 +4224,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
42244224 slash = zend_memrchr (filename , '/' , filename_len );
42254225
42264226 if (slash ) {
4227- fullpath [dest_len + (slash - filename ) + 1 ] = '\0' ;
4227+ fullpath [ZSTR_LEN ( dest ) + (slash - filename ) + 1 ] = '\0' ;
42284228 } else {
4229- fullpath [dest_len ] = '\0' ;
4229+ fullpath [ZSTR_LEN ( dest ) ] = '\0' ;
42304230 }
42314231
42324232 if (FAILURE == php_stream_stat_path (fullpath , & ssb )) {
@@ -4248,9 +4248,9 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
42484248 }
42494249
42504250 if (slash ) {
4251- fullpath [dest_len + (slash - filename ) + 1 ] = '/' ;
4251+ fullpath [ZSTR_LEN ( dest ) + (slash - filename ) + 1 ] = '/' ;
42524252 } else {
4253- fullpath [dest_len ] = '/' ;
4253+ fullpath [ZSTR_LEN ( dest ) ] = '/' ;
42544254 }
42554255
42564256 filename = NULL ;
@@ -4270,9 +4270,10 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
42704270 }
42714271
42724272 if ((phar_get_fp_type (entry ) == PHAR_FP && (entry -> flags & PHAR_ENT_COMPRESSION_MASK )) || !phar_get_efp (entry , 0 )) {
4273- if (FAILURE == phar_open_entry_fp (entry , error , 1 )) {
4274- if (error ) {
4275- spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer: %s" , ZSTR_VAL (entry -> filename ), fullpath , * error );
4273+ char * open_entry_error = NULL ;
4274+ if (FAILURE == phar_open_entry_fp (entry , & open_entry_error , 1 )) {
4275+ if (open_entry_error ) {
4276+ spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer: %s" , ZSTR_VAL (entry -> filename ), fullpath , open_entry_error );
42764277 } else {
42774278 spprintf (error , 4096 , "Cannot extract \"%s\" to \"%s\", unable to open internal file pointer" , ZSTR_VAL (entry -> filename ), fullpath );
42784279 }
@@ -4310,28 +4311,28 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
43104311}
43114312/* }}} */
43124313
4313- static int extract_helper (phar_archive_data * archive , zend_string * search , char * pathto , size_t pathto_len , bool overwrite , char * * error ) { /* {{{ */
4314+ ZEND_ATTRIBUTE_NONNULL_ARGS ( 1 , 3 , 5 ) static int extract_helper (const phar_archive_data * archive , zend_string * search , const zend_string * pathto , bool overwrite , char * * error ) { /* {{{ */
43144315 int extracted = 0 ;
43154316 phar_entry_info * entry ;
43164317
43174318 if (!search ) {
43184319 /* nothing to match -- extract all files */
43194320 ZEND_HASH_MAP_FOREACH_PTR (& archive -> manifest , entry ) {
4320- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4321+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
43214322 extracted ++ ;
43224323 } ZEND_HASH_FOREACH_END ();
43234324 } else if (ZSTR_LEN (search ) > 0 && '/' == ZSTR_VAL (search )[ZSTR_LEN (search ) - 1 ]) {
43244325 /* ends in "/" -- extract all entries having that prefix */
43254326 ZEND_HASH_MAP_FOREACH_PTR (& archive -> manifest , entry ) {
43264327 if (!zend_string_starts_with (entry -> filename , search )) continue ;
4327- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4328+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
43284329 extracted ++ ;
43294330 } ZEND_HASH_FOREACH_END ();
43304331 } else {
43314332 /* otherwise, looking for an exact match */
43324333 entry = zend_hash_find_ptr (& archive -> manifest , search );
43334334 if (NULL == entry ) return 0 ;
4334- if (FAILURE == phar_extract_file (overwrite , entry , pathto , pathto_len , error )) return -1 ;
4335+ if (FAILURE == phar_extract_file (overwrite , entry , pathto , error )) return -1 ;
43354336 return 1 ;
43364337 }
43374338
@@ -4344,17 +4345,16 @@ PHP_METHOD(Phar, extractTo)
43444345{
43454346 php_stream * fp ;
43464347 php_stream_statbuf ssb ;
4347- char * pathto ;
4348+ zend_string * path_to ;
43484349 zend_string * filename = NULL ;
4349- size_t pathto_len ;
43504350 int ret ;
43514351 zval * zval_file ;
43524352 HashTable * files_ht = NULL ;
43534353 bool overwrite = 0 ;
43544354 char * error = NULL ;
43554355
43564356 ZEND_PARSE_PARAMETERS_START (1 , 3 )
4357- Z_PARAM_PATH ( pathto , pathto_len )
4357+ Z_PARAM_PATH_STR ( path_to )
43584358 Z_PARAM_OPTIONAL
43594359 Z_PARAM_ARRAY_HT_OR_STR_OR_NULL (files_ht , filename )
43604360 Z_PARAM_BOOL (overwrite )
@@ -4372,30 +4372,30 @@ PHP_METHOD(Phar, extractTo)
43724372
43734373 php_stream_close (fp );
43744374
4375- if (pathto_len < 1 ) {
4375+ if (ZSTR_LEN ( path_to ) < 1 ) {
43764376 zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 ,
43774377 "Invalid argument, extraction path must be non-zero length" );
43784378 RETURN_THROWS ();
43794379 }
43804380
4381- if (pathto_len >= MAXPATHLEN ) {
4382- char * tmp = estrndup (pathto , 50 );
4381+ if (ZSTR_LEN ( path_to ) >= MAXPATHLEN ) {
4382+ char * tmp = estrndup (ZSTR_VAL ( path_to ) , 50 );
43834383 /* truncate for error message */
43844384 zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 , "Cannot extract to \"%s...\", destination directory is too long for filesystem" , tmp );
43854385 efree (tmp );
43864386 RETURN_THROWS ();
43874387 }
43884388
4389- if (php_stream_stat_path (pathto , & ssb ) < 0 ) {
4390- ret = php_stream_mkdir (pathto , 0777 , PHP_STREAM_MKDIR_RECURSIVE , NULL );
4389+ if (php_stream_stat_path (ZSTR_VAL ( path_to ) , & ssb ) < 0 ) {
4390+ ret = php_stream_mkdir (ZSTR_VAL ( path_to ) , 0777 , PHP_STREAM_MKDIR_RECURSIVE , NULL );
43914391 if (!ret ) {
43924392 zend_throw_exception_ex (spl_ce_RuntimeException , 0 ,
4393- "Unable to create path \"%s\" for extraction" , pathto );
4393+ "Unable to create path \"%s\" for extraction" , ZSTR_VAL ( path_to ) );
43944394 RETURN_THROWS ();
43954395 }
43964396 } else if (!(ssb .sb .st_mode & S_IFDIR )) {
43974397 zend_throw_exception_ex (spl_ce_RuntimeException , 0 ,
4398- "Unable to use path \"%s\" for extraction, it is a file, must be a directory" , pathto );
4398+ "Unable to use path \"%s\" for extraction, it is a file, must be a directory" , ZSTR_VAL ( path_to ) );
43994399 RETURN_THROWS ();
44004400 }
44014401
@@ -4411,7 +4411,7 @@ PHP_METHOD(Phar, extractTo)
44114411 "Invalid argument, array of filenames to extract contains non-string value" );
44124412 RETURN_THROWS ();
44134413 }
4414- switch (extract_helper (phar_obj -> archive , Z_STR_P (zval_file ), pathto , pathto_len , overwrite , & error )) {
4414+ switch (extract_helper (phar_obj -> archive , Z_STR_P (zval_file ), path_to , overwrite , & error )) {
44154415 case -1 :
44164416 zend_throw_exception_ex (phar_ce_PharException , 0 , "Extraction from phar \"%s\" failed: %s" ,
44174417 phar_obj -> archive -> fname , error );
@@ -4427,7 +4427,7 @@ PHP_METHOD(Phar, extractTo)
44274427 RETURN_TRUE ;
44284428 }
44294429
4430- ret = extract_helper (phar_obj -> archive , filename , pathto , pathto_len , overwrite , & error );
4430+ ret = extract_helper (phar_obj -> archive , filename , path_to , overwrite , & error );
44314431 if (-1 == ret ) {
44324432 zend_throw_exception_ex (phar_ce_PharException , 0 , "Extraction from phar \"%s\" failed: %s" ,
44334433 phar_obj -> archive -> fname , error );
0 commit comments