@@ -367,7 +367,7 @@ void destroy_phar_manifest_entry_int(phar_entry_info *entry) /* {{{ */
367
367
368
368
phar_metadata_tracker_free (& entry -> metadata_tracker , entry -> is_persistent );
369
369
370
- pefree (entry -> filename , entry -> is_persistent );
370
+ zend_string_release_ex (entry -> filename , entry -> is_persistent );
371
371
372
372
if (entry -> link ) {
373
373
pefree (entry -> link , entry -> is_persistent );
@@ -424,7 +424,7 @@ void phar_entry_remove(phar_entry_data *idata, char **error) /* {{{ */
424
424
if (idata -> fp && idata -> fp != idata -> phar -> fp && idata -> fp != idata -> phar -> ufp && idata -> fp != idata -> internal_file -> fp ) {
425
425
php_stream_close (idata -> fp );
426
426
}
427
- zend_hash_str_del (& idata -> phar -> manifest , idata -> internal_file -> filename , idata -> internal_file -> filename_len );
427
+ zend_hash_del (& idata -> phar -> manifest , idata -> internal_file -> filename );
428
428
idata -> phar -> refcount -- ;
429
429
efree (idata );
430
430
} else {
@@ -1134,29 +1134,30 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname
1134
1134
MAPPHAR_FAIL ("internal corruption of phar \"%s\" (truncated manifest entry)" )
1135
1135
}
1136
1136
1137
- PHAR_GET_32 (buffer , entry .filename_len );
1137
+ uint32_t filename_len ;
1138
+ PHAR_GET_32 (buffer , filename_len );
1138
1139
1139
- if (entry . filename_len == 0 ) {
1140
+ if (filename_len == 0 ) {
1140
1141
MAPPHAR_FAIL ("zero-length filename encountered in phar \"%s\"" );
1141
1142
}
1142
1143
1143
1144
if (entry .is_persistent ) {
1144
1145
entry .manifest_pos = manifest_index ;
1145
1146
}
1146
1147
1147
- if (entry . filename_len > (size_t )(endbuffer - buffer - 24 )) {
1148
+ if (filename_len > (size_t )(endbuffer - buffer - 24 )) {
1148
1149
MAPPHAR_FAIL ("internal corruption of phar \"%s\" (truncated manifest entry)" );
1149
1150
}
1150
1151
1151
- if ((manifest_ver & PHAR_API_VER_MASK ) >= PHAR_API_MIN_DIR && buffer [entry . filename_len - 1 ] == '/' ) {
1152
+ if ((manifest_ver & PHAR_API_VER_MASK ) >= PHAR_API_MIN_DIR && buffer [filename_len - 1 ] == '/' ) {
1152
1153
entry .is_dir = 1 ;
1153
1154
} else {
1154
1155
entry .is_dir = 0 ;
1155
1156
}
1156
1157
1157
- phar_add_virtual_dirs (mydata , buffer , entry . filename_len );
1158
- entry . filename = pestrndup ( buffer , entry . filename_len , entry . is_persistent ) ;
1159
- buffer += entry . filename_len ;
1158
+ phar_add_virtual_dirs (mydata , buffer , filename_len );
1159
+ const char * filename_raw = buffer ;
1160
+ buffer += filename_len ;
1160
1161
PHAR_GET_32 (buffer , entry .uncompressed_filesize );
1161
1162
PHAR_GET_32 (buffer , entry .timestamp );
1162
1163
@@ -1176,13 +1177,15 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname
1176
1177
PHAR_GET_32 (buffer , entry .flags );
1177
1178
1178
1179
if (entry .is_dir ) {
1179
- entry . filename_len -- ;
1180
+ filename_len -- ;
1180
1181
entry .flags |= PHAR_ENT_PERM_DEF_DIR ;
1181
1182
}
1182
1183
1184
+ entry .filename = zend_string_init (filename_raw , filename_len , entry .is_persistent );
1185
+
1183
1186
PHAR_GET_32 (buffer , len );
1184
1187
if (len > (size_t )(endbuffer - buffer )) {
1185
- pefree (entry .filename , entry . is_persistent );
1188
+ zend_string_free (entry .filename );
1186
1189
MAPPHAR_FAIL ("internal corruption of phar \"%s\" (truncated manifest entry)" );
1187
1190
}
1188
1191
/* Don't implicitly call unserialize() on potentially untrusted input unless getMetadata() is called directly. */
@@ -1199,21 +1202,21 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname
1199
1202
case PHAR_ENT_COMPRESSED_GZ :
1200
1203
if (!PHAR_G (has_zlib )) {
1201
1204
phar_metadata_tracker_free (& entry .metadata_tracker , entry .is_persistent );
1202
- pefree (entry .filename , entry . is_persistent );
1205
+ zend_string_free (entry .filename );
1203
1206
MAPPHAR_FAIL ("zlib extension is required for gz compressed .phar file \"%s\"" );
1204
1207
}
1205
1208
break ;
1206
1209
case PHAR_ENT_COMPRESSED_BZ2 :
1207
1210
if (!PHAR_G (has_bz2 )) {
1208
1211
phar_metadata_tracker_free (& entry .metadata_tracker , entry .is_persistent );
1209
- pefree (entry .filename , entry . is_persistent );
1212
+ zend_string_free (entry .filename );
1210
1213
MAPPHAR_FAIL ("bz2 extension is required for bzip2 compressed .phar file \"%s\"" );
1211
1214
}
1212
1215
break ;
1213
1216
default :
1214
1217
if (entry .uncompressed_filesize != entry .compressed_filesize ) {
1215
1218
phar_metadata_tracker_free (& entry .metadata_tracker , entry .is_persistent );
1216
- pefree (entry .filename , entry . is_persistent );
1219
+ zend_string_free (entry .filename );
1217
1220
MAPPHAR_FAIL ("internal corruption of phar \"%s\" (compressed and uncompressed size does not match for uncompressed entry)" );
1218
1221
}
1219
1222
break ;
@@ -1223,10 +1226,11 @@ static zend_result phar_parse_pharfile(php_stream *fp, char *fname, size_t fname
1223
1226
/* if signature matched, no need to check CRC32 for each file */
1224
1227
entry .is_crc_checked = (manifest_flags & PHAR_HDR_SIGNATURE ? 1 : 0 );
1225
1228
phar_set_inode (& entry );
1229
+ // TODO: avoid copy
1226
1230
if (mydata -> is_persistent ) {
1227
- str = zend_string_init_interned (entry .filename , entry .filename_len , 1 );
1231
+ str = zend_string_init_interned (ZSTR_VAL ( entry .filename ), ZSTR_LEN ( entry .filename ) , 1 );
1228
1232
} else {
1229
- str = zend_string_init (entry .filename , entry .filename_len , 0 );
1233
+ str = zend_string_init (ZSTR_VAL ( entry .filename ), ZSTR_LEN ( entry .filename ) , 0 );
1230
1234
}
1231
1235
zend_hash_add_mem (& mydata -> manifest , str , (void * )& entry , sizeof (phar_entry_info ));
1232
1236
zend_string_release (str );
@@ -2390,14 +2394,14 @@ zend_result phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char *
2390
2394
phar_zip_data_desc desc ;
2391
2395
2392
2396
if (SUCCESS != phar_open_archive_fp (idata -> phar )) {
2393
- spprintf (error , 0 , "phar error: unable to open zip-based phar archive \"%s\" to verify local file header for file \"%s\"" , idata -> phar -> fname , entry -> filename );
2397
+ spprintf (error , 0 , "phar error: unable to open zip-based phar archive \"%s\" to verify local file header for file \"%s\"" , idata -> phar -> fname , ZSTR_VAL ( entry -> filename ) );
2394
2398
return FAILURE ;
2395
2399
}
2396
2400
php_stream_seek (phar_get_entrypfp (idata -> internal_file ), entry -> header_offset , SEEK_SET );
2397
2401
2398
2402
if (sizeof (local ) != php_stream_read (phar_get_entrypfp (idata -> internal_file ), (char * ) & local , sizeof (local ))) {
2399
2403
2400
- spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (cannot read local file header for file \"%s\")" , idata -> phar -> fname , entry -> filename );
2404
+ spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (cannot read local file header for file \"%s\")" , idata -> phar -> fname , ZSTR_VAL ( entry -> filename ) );
2401
2405
return FAILURE ;
2402
2406
}
2403
2407
@@ -2410,7 +2414,7 @@ zend_result phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char *
2410
2414
entry -> compressed_filesize , SEEK_SET );
2411
2415
if (sizeof (desc ) != php_stream_read (phar_get_entrypfp (idata -> internal_file ),
2412
2416
(char * ) & desc , sizeof (desc ))) {
2413
- spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (cannot read local data descriptor for file \"%s\")" , idata -> phar -> fname , entry -> filename );
2417
+ spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (cannot read local data descriptor for file \"%s\")" , idata -> phar -> fname , ZSTR_VAL ( entry -> filename ) );
2414
2418
return FAILURE ;
2415
2419
}
2416
2420
if (desc .signature [0 ] == 'P' && desc .signature [1 ] == 'K' ) {
@@ -2421,8 +2425,8 @@ zend_result phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char *
2421
2425
}
2422
2426
}
2423
2427
/* verify local header */
2424
- if (entry -> filename_len != PHAR_ZIP_16 (local .filename_len ) || entry -> crc32 != PHAR_ZIP_32 (local .crc32 ) || entry -> uncompressed_filesize != PHAR_ZIP_32 (local .uncompsize ) || entry -> compressed_filesize != PHAR_ZIP_32 (local .compsize )) {
2425
- spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (local header of file \"%s\" does not match central directory)" , idata -> phar -> fname , entry -> filename );
2428
+ if (ZSTR_LEN ( entry -> filename ) != PHAR_ZIP_16 (local .filename_len ) || entry -> crc32 != PHAR_ZIP_32 (local .crc32 ) || entry -> uncompressed_filesize != PHAR_ZIP_32 (local .uncompsize ) || entry -> compressed_filesize != PHAR_ZIP_32 (local .compsize )) {
2429
+ spprintf (error , 0 , "phar error: internal corruption of zip-based phar \"%s\" (local header of file \"%s\" does not match central directory)" , idata -> phar -> fname , ZSTR_VAL ( entry -> filename ) );
2426
2430
return FAILURE ;
2427
2431
}
2428
2432
@@ -2450,7 +2454,7 @@ zend_result phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char *
2450
2454
entry -> is_crc_checked = 1 ;
2451
2455
return SUCCESS ;
2452
2456
} else {
2453
- spprintf (error , 0 , "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")" , idata -> phar -> fname , entry -> filename );
2457
+ spprintf (error , 0 , "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")" , idata -> phar -> fname , ZSTR_VAL ( entry -> filename ) );
2454
2458
return FAILURE ;
2455
2459
}
2456
2460
}
@@ -2712,7 +2716,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2712
2716
}
2713
2717
/* after excluding deleted files, calculate manifest size in bytes and number of entries */
2714
2718
++ new_manifest_count ;
2715
- phar_add_virtual_dirs (phar , entry -> filename , entry -> filename_len );
2719
+ phar_add_virtual_dirs (phar , ZSTR_VAL ( entry -> filename ), ZSTR_LEN ( entry -> filename ) );
2716
2720
2717
2721
if (entry -> is_dir ) {
2718
2722
/* we use this to calculate API version, 1.1.1 is used for phars with directories */
@@ -2729,7 +2733,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2729
2733
}
2730
2734
2731
2735
/* 32 bits for filename length, length of filename, manifest + metadata, and add 1 for trailing / if a directory */
2732
- offset += 4 + entry -> filename_len + sizeof (entry_buffer ) + (entry -> metadata_tracker .str ? ZSTR_LEN (entry -> metadata_tracker .str ) : 0 ) + (entry -> is_dir ? 1 : 0 );
2736
+ offset += 4 + ZSTR_LEN ( entry -> filename ) + sizeof (entry_buffer ) + (entry -> metadata_tracker .str ? ZSTR_LEN (entry -> metadata_tracker .str ) : 0 ) + (entry -> is_dir ? 1 : 0 );
2733
2737
2734
2738
/* compress and rehash as necessary */
2735
2739
if ((oldfile && !entry -> is_modified ) || entry -> is_dir ) {
@@ -2757,7 +2761,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2757
2761
}
2758
2762
php_stream_close (newfile );
2759
2763
if (error ) {
2760
- spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , entry -> filename , phar -> fname );
2764
+ spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2761
2765
}
2762
2766
return ;
2763
2767
}
@@ -2778,11 +2782,11 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2778
2782
php_stream_close (newfile );
2779
2783
if (entry -> flags & PHAR_ENT_COMPRESSED_GZ ) {
2780
2784
if (error ) {
2781
- spprintf (error , 0 , "unable to gzip compress file \"%s\" to new phar \"%s\"" , entry -> filename , phar -> fname );
2785
+ spprintf (error , 0 , "unable to gzip compress file \"%s\" to new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2782
2786
}
2783
2787
} else {
2784
2788
if (error ) {
2785
- spprintf (error , 0 , "unable to bzip2 compress file \"%s\" to new phar \"%s\"" , entry -> filename , phar -> fname );
2789
+ spprintf (error , 0 , "unable to bzip2 compress file \"%s\" to new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2786
2790
}
2787
2791
}
2788
2792
return ;
@@ -2815,7 +2819,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2815
2819
}
2816
2820
php_stream_close (newfile );
2817
2821
if (error ) {
2818
- spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , entry -> filename , phar -> fname );
2822
+ spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2819
2823
}
2820
2824
goto cleanup ;
2821
2825
}
@@ -2826,7 +2830,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2826
2830
}
2827
2831
php_stream_close (newfile );
2828
2832
if (error ) {
2829
- spprintf (error , 0 , "unable to copy compressed file contents of file \"%s\" while creating new phar \"%s\"" , entry -> filename , phar -> fname );
2833
+ spprintf (error , 0 , "unable to copy compressed file contents of file \"%s\" while creating new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2830
2834
}
2831
2835
goto cleanup ;
2832
2836
}
@@ -2929,23 +2933,23 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2929
2933
2930
2934
if (entry -> is_dir ) {
2931
2935
/* add 1 for trailing slash */
2932
- phar_set_32 (entry_buffer , entry -> filename_len + 1 );
2936
+ phar_set_32 (entry_buffer , ZSTR_LEN ( entry -> filename ) + 1 );
2933
2937
} else {
2934
- phar_set_32 (entry_buffer , entry -> filename_len );
2938
+ phar_set_32 (entry_buffer , ZSTR_LEN ( entry -> filename ) );
2935
2939
}
2936
2940
2937
2941
if (4 != php_stream_write (newfile , entry_buffer , 4 )
2938
- || entry -> filename_len != php_stream_write (newfile , entry -> filename , entry -> filename_len )
2942
+ || ZSTR_LEN ( entry -> filename ) != php_stream_write (newfile , ZSTR_VAL ( entry -> filename ), ZSTR_LEN ( entry -> filename ) )
2939
2943
|| (entry -> is_dir && 1 != php_stream_write (newfile , "/" , 1 ))) {
2940
2944
if (must_close_old_file ) {
2941
2945
php_stream_close (oldfile );
2942
2946
}
2943
2947
php_stream_close (newfile );
2944
2948
if (error ) {
2945
2949
if (entry -> is_dir ) {
2946
- spprintf (error , 0 , "unable to write filename of directory \"%s\" to manifest of new phar \"%s\"" , entry -> filename , phar -> fname );
2950
+ spprintf (error , 0 , "unable to write filename of directory \"%s\" to manifest of new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2947
2951
} else {
2948
- spprintf (error , 0 , "unable to write filename of file \"%s\" to manifest of new phar \"%s\"" , entry -> filename , phar -> fname );
2952
+ spprintf (error , 0 , "unable to write filename of file \"%s\" to manifest of new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2949
2953
}
2950
2954
}
2951
2955
goto cleanup ;
@@ -2979,7 +2983,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
2979
2983
php_stream_close (newfile );
2980
2984
2981
2985
if (error ) {
2982
- spprintf (error , 0 , "unable to write temporary manifest of file \"%s\" to manifest of new phar \"%s\"" , entry -> filename , phar -> fname );
2986
+ spprintf (error , 0 , "unable to write temporary manifest of file \"%s\" to manifest of new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
2983
2987
}
2984
2988
2985
2989
goto cleanup ;
@@ -3020,7 +3024,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
3020
3024
}
3021
3025
php_stream_close (newfile );
3022
3026
if (error ) {
3023
- spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , entry -> filename , phar -> fname );
3027
+ spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
3024
3028
}
3025
3029
goto cleanup ;
3026
3030
}
@@ -3032,7 +3036,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
3032
3036
}
3033
3037
php_stream_close (newfile );
3034
3038
if (error ) {
3035
- spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , entry -> filename , phar -> fname );
3039
+ spprintf (error , 0 , "unable to seek to start of file \"%s\" while creating new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
3036
3040
}
3037
3041
goto cleanup ;
3038
3042
}
@@ -3048,7 +3052,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
3048
3052
php_stream_close (newfile );
3049
3053
3050
3054
if (error ) {
3051
- spprintf (error , 0 , "unable to write contents of file \"%s\" to new phar \"%s\"" , entry -> filename , phar -> fname );
3055
+ spprintf (error , 0 , "unable to write contents of file \"%s\" to new phar \"%s\"" , ZSTR_VAL ( entry -> filename ) , phar -> fname );
3052
3056
}
3053
3057
3054
3058
goto cleanup ;
0 commit comments