php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
phar.c File Reference
#include "phar_internal.h"
#include "php_phar.h"
#include "SAPI.h"
#include "func_interceptors.h"
#include "ext/standard/crc32.h"
#include "ext/standard/php_var.h"
#include "ext/standard/php_string.h"
#include "ext/standard/info.h"
#include "zend_smart_str.h"
#include "stub.h"

Go to the source code of this file.

Macros

#define PHAR_MAIN   1
 
#define MAPPHAR_ALLOC_FAIL(msg)
 
#define MAPPHAR_FAIL(msg)
 
#define PHAR_GET_32(buffer, var)
 
#define PHAR_GET_16(buffer, var)
 
#define PHAR_ZIP_16(var)
 
#define PHAR_ZIP_32(var)
 
#define MANIFEST_FIXED_LEN   18
 
#define SAFE_PHAR_GET_32(buffer, endbuffer, var)
 
#define MAX_WBITS   15
 
#define IS_DIRECTORY_UP(element, len)
 
#define IS_DIRECTORY_CURRENT(element, len)
 
#define IS_BACKSLASH(c)
 
#define PHAR_SET_MIME(mimetype, ret, fileext)
 

Functions

 if (ZSTR_LEN(entry->name)==sizeof("phar.readonly") -1)
 
 if (stage==ZEND_INI_STAGE_STARTUP)
 
else if (old &&!ini)
 
void phar_destroy_phar_data (phar_archive_data *phar)
 
bool phar_archive_delref (phar_archive_data *phar)
 
void destroy_phar_manifest_entry_int (phar_entry_info *entry)
 
void destroy_phar_manifest_entry (zval *zv)
 
void phar_entry_delref (phar_entry_data *idata)
 
void phar_entry_remove (phar_entry_data *idata, char **error)
 
void phar_metadata_tracker_try_ensure_has_serialized_data (phar_metadata_tracker *tracker, bool persistent)
 
zend_result phar_metadata_tracker_unserialize_or_copy (phar_metadata_tracker *tracker, zval *metadata, bool persistent, HashTable *unserialize_options, const char *method_name)
 
bool phar_metadata_tracker_has_data (const phar_metadata_tracker *tracker, bool persistent)
 
void phar_metadata_tracker_free (phar_metadata_tracker *tracker, bool persistent)
 
void phar_metadata_tracker_copy (phar_metadata_tracker *dest, const phar_metadata_tracker *source, bool persistent)
 
void phar_metadata_tracker_clone (phar_metadata_tracker *tracker)
 
void phar_parse_metadata_lazy (const char *buffer, phar_metadata_tracker *tracker, uint32_t zip_metadata_len, bool persistent)
 
zend_result phar_open_or_create_filename (char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data **pphar, char **error)
 
zend_result phar_create_or_parse_filename (char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data **pphar, char **error)
 
zend_result phar_open_from_filename (char *fname, size_t fname_len, char *alias, size_t alias_len, uint32_t options, phar_archive_data **pphar, char **error)
 
zend_result phar_detect_phar_fname_ext (const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, int is_complete)
 
char * phar_fix_filepath (char *path, size_t *new_len, int use_cwd)
 
zend_result phar_split_fname (const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create)
 
zend_result phar_open_executed_filename (char *alias, size_t alias_len, char **error)
 
zend_result phar_postprocess_file (phar_entry_data *idata, uint32_t crc32, char **error, int process_zip)
 
zend_stringphar_create_default_stub (const char *index_php, const char *web_index, char **error)
 
void phar_flush (phar_archive_data *phar, char **error)
 
void phar_flush_ex (phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error)
 
 memset (phar_globals, 0, sizeof(zend_phar_globals))
 
 phar_restore_orig_functions ()
 
 phar_object_init ()
 
 phar_intercept_functions_init ()
 
 phar_save_orig_functions ()
 
return php_register_url_stream_wrapper ("phar", &php_stream_phar_wrapper)
 
 phar_intercept_functions_shutdown ()
 
 if (zend_compile_file==phar_compile_file)
 
 if (PHAR_G(manifest_cached))
 
 UNREGISTER_INI_ENTRIES ()
 
void phar_request_initialize (void)
 
 if (PHAR_G(request_init))
 
 PHAR_G (request_done)
 
 php_info_print_table_start ()
 
 php_info_print_table_row (2, "Phar: PHP Archive support", "enabled")
 
 php_info_print_table_row (2, "Phar API version", PHP_PHAR_API_VERSION)
 
 php_info_print_table_row (2, "Phar-based phar archives", "enabled")
 
 php_info_print_table_row (2, "Tar-based phar archives", "enabled")
 
 php_info_print_table_row (2, "ZIP-based phar archives", "enabled")
 
 if (PHAR_G(has_zlib))
 
 if (PHAR_G(has_bz2))
 
 if (zend_hash_str_exists(&module_registry, "openssl", sizeof("openssl") -1))
 
 php_info_print_table_end ()
 
 php_info_print_box_start (0)
 
 PUTS ("Phar based on pear/PHP_Archive, original concept by Davey Shafik.")
 
 PUTS (!sapi_module.phpinfo_as_text?"<br />":"\n")
 
 PUTS ("Phar fully realized by Gregory Beaver and Marcus Boerger.")
 
 PUTS ("Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.")
 
 php_info_print_box_end ()
 
 DISPLAY_INI_ENTRIES ()
 

Variables

 else
 
 ini = zend_ini_parse_bool(new_value)
 
return SUCCESS
 
HashTable cached_phars
 
HashTable cached_alias
 
zend_op_array *(* phar_orig_compile_file )(zend_file_handle *file_handle, int type) = zend_compile_file
 
HT_INVALIDATEphar_globals
 
phar_globals readonly = 1
 
 zend_compile_file = phar_compile_file
 
 zend_resolve_path = phar_resolve_path
 
zend_module_entry phar_module_entry
 

Macro Definition Documentation

◆ IS_BACKSLASH

#define IS_BACKSLASH ( c)
Value:
((c) == '/')

Definition at line 2123 of file phar.c.

◆ IS_DIRECTORY_CURRENT

#define IS_DIRECTORY_CURRENT ( element,
len )
Value:
(len == 1 && element[0] == '.')
size_t len
Definition apprentice.c:174

Definition at line 2120 of file phar.c.

◆ IS_DIRECTORY_UP

#define IS_DIRECTORY_UP ( element,
len )
Value:
(len >= 2 && !php_check_dots(element, len))

Definition at line 2117 of file phar.c.

◆ MANIFEST_FIXED_LEN

#define MANIFEST_FIXED_LEN   18

Size of fixed fields in the manifest. See: https://www.php.net/manual/en/phar.fileformat.phar.php

Definition at line 716 of file phar.c.

◆ MAPPHAR_ALLOC_FAIL

#define MAPPHAR_ALLOC_FAIL ( msg)
Value:
if (fp) {\
php_stream_close(fp);\
}\
if (error) {\
spprintf(error, 0, msg, fname);\
}\
return FAILURE;
error($message)
Definition ext_skel.php:22
char * msg
Definition phpdbg.h:289
@ FAILURE
Definition zend_types.h:61

Definition at line 441 of file phar.c.

◆ MAPPHAR_FAIL

#define MAPPHAR_FAIL ( msg)
Value:
efree(savebuf);\
if (mydata) {\
phar_destroy_phar_data(mydata);\
}\
if (signature) {\
pefree(signature, PHAR_G(persist));\
}\
MAPPHAR_ALLOC_FAIL(msg)
#define PHAR_G(v)
bool persist
#define efree(ptr)
Definition zend_alloc.h:155

Definition at line 450 of file phar.c.

◆ MAX_WBITS

#define MAX_WBITS   15

◆ PHAR_GET_16

#define PHAR_GET_16 ( buffer,
var )
Value:
var = *(uint16_t*)(buffer); \
buffer += 2
Definition file.h:177

Definition at line 475 of file phar.c.

◆ PHAR_GET_32

#define PHAR_GET_32 ( buffer,
var )
Value:
memcpy(&var, buffer, sizeof(var)); \
buffer += 4
memcpy(ptr1, ptr2, size)

Definition at line 472 of file phar.c.

◆ PHAR_MAIN

#define PHAR_MAIN   1

Definition at line 20 of file phar.c.

◆ PHAR_SET_MIME

#define PHAR_SET_MIME ( mimetype,
ret,
fileext )
Value:
mime.mime = mimetype; \
mime.len = sizeof((mimetype))+1; \
mime.type = ret; \
zend_hash_str_add_mem(&phar_globals->mime_types, fileext, sizeof(fileext)-1, (void *)&mime, sizeof(phar_mime_type)); \
HT_INVALIDATE & phar_globals
Definition phar.c:3343
struct _phar_mime_type phar_mime_type
zval * ret

Definition at line 3350 of file phar.c.

◆ PHAR_ZIP_16

#define PHAR_ZIP_16 ( var)
Value:
((uint16_t)((((uint16_t)var[0]) & 0xff) | \
(((uint16_t)var[1]) & 0xff) << 8))

Definition at line 479 of file phar.c.

◆ PHAR_ZIP_32

#define PHAR_ZIP_32 ( var)
Value:
((uint32_t)((((uint32_t)var[0]) & 0xff) | \
(((uint32_t)var[1]) & 0xff) << 8 | \
(((uint32_t)var[2]) & 0xff) << 16 | \
(((uint32_t)var[3]) & 0xff) << 24))

Definition at line 481 of file phar.c.

◆ SAFE_PHAR_GET_32

#define SAFE_PHAR_GET_32 ( buffer,
endbuffer,
var )
Value:
if (UNEXPECTED(buffer + 4 > endbuffer)) { \
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest header)"); \
} \
PHAR_GET_32(buffer, var);
#define UNEXPECTED(condition)

Definition at line 718 of file phar.c.

Function Documentation

◆ destroy_phar_manifest_entry()

void destroy_phar_manifest_entry ( zval * zv)

Definition at line 384 of file phar.c.

◆ destroy_phar_manifest_entry_int()

void destroy_phar_manifest_entry_int ( phar_entry_info * entry)

destructor for the manifest hash, frees each file's entry

Definition at line 355 of file phar.c.

◆ DISPLAY_INI_ENTRIES()

DISPLAY_INI_ENTRIES ( )

◆ if() [1/9]

else if ( old &&! ini)

Definition at line 72 of file phar.c.

◆ if() [2/9]

if ( PHAR_G(has_bz2) )

Definition at line 3541 of file phar.c.

◆ if() [3/9]

if ( PHAR_G(has_zlib) )

Definition at line 3535 of file phar.c.

◆ if() [4/9]

Definition at line 3436 of file phar.c.

◆ if() [5/9]

Definition at line 3484 of file phar.c.

◆ if() [6/9]

if ( stage = ZEND_INI_STAGE_STARTUP)

Definition at line 66 of file phar.c.

◆ if() [7/9]

if ( zend_compile_file = = phar_compile_file)

Definition at line 3432 of file phar.c.

◆ if() [8/9]

if ( zend_hash_str_exists(&, "", ""openssl- 1)

Definition at line 3549 of file phar.c.

◆ if() [9/9]

if ( ZSTR_LEN(entry->name) = sizeof("phar.readonly")-1)

Definition at line 57 of file phar.c.

◆ memset()

memset ( phar_globals ,
0 ,
sizeof(zend_phar_globals)  )

◆ phar_archive_delref()

bool phar_archive_delref ( phar_archive_data * phar)

Delete refcount and destruct if needed. On destruct return 1 else 0.

Definition at line 246 of file phar.c.

◆ phar_create_default_stub()

zend_string * phar_create_default_stub ( const char * index_php,
const char * web_index,
char ** error )

Definition at line 2485 of file phar.c.

◆ phar_create_or_parse_filename()

zend_result phar_create_or_parse_filename ( char * fname,
size_t fname_len,
char * alias,
size_t alias_len,
bool is_data,
uint32_t options,
phar_archive_data ** pphar,
char ** error )

Definition at line 1389 of file phar.c.

◆ phar_destroy_phar_data()

void phar_destroy_phar_data ( phar_archive_data * phar)

When all uses of a phar have been concluded, this frees the manifest and the phar slot

Definition at line 195 of file phar.c.

◆ phar_detect_phar_fname_ext()

zend_result phar_detect_phar_fname_ext ( const char * filename,
size_t filename_len,
const char ** ext_str,
size_t * ext_len,
int executable,
int for_create,
int is_complete )

Definition at line 1967 of file phar.c.

◆ phar_entry_delref()

void phar_entry_delref ( phar_entry_data * idata)

Definition at line 392 of file phar.c.

◆ phar_entry_remove()

void phar_entry_remove ( phar_entry_data * idata,
char ** error )

Removes an entry, either by actually removing it or by marking it.

Definition at line 417 of file phar.c.

◆ phar_fix_filepath()

char * phar_fix_filepath ( char * path,
size_t * new_len,
int use_cwd )

Remove .. and . references within a phar filename

Definition at line 2128 of file phar.c.

◆ phar_flush()

void phar_flush ( phar_archive_data * phar,
char ** error )

Definition at line 2524 of file phar.c.

◆ phar_flush_ex()

void phar_flush_ex ( phar_archive_data * phar,
zend_string * user_stub,
bool is_default_stub,
char ** error )

Save phar contents to disk

if user_stub is NULL the default or existing stub should be used

Definition at line 2533 of file phar.c.

◆ PHAR_G()

PHAR_G ( request_done )

◆ phar_intercept_functions_init()

phar_intercept_functions_init ( )

Definition at line 891 of file func_interceptors.c.

◆ phar_intercept_functions_shutdown()

phar_intercept_functions_shutdown ( )

Definition at line 928 of file func_interceptors.c.

◆ phar_metadata_tracker_clone()

void phar_metadata_tracker_clone ( phar_metadata_tracker * tracker)

Copy constructor for a non-persistent clone.

Definition at line 684 of file phar.c.

◆ phar_metadata_tracker_copy()

void phar_metadata_tracker_copy ( phar_metadata_tracker * dest,
const phar_metadata_tracker * source,
bool persistent )

Free memory used to track the metadata and set all fields to be null/undef.

Definition at line 666 of file phar.c.

◆ phar_metadata_tracker_free()

void phar_metadata_tracker_free ( phar_metadata_tracker * tracker,
bool persistent )

Free memory used to track the metadata and set all fields to be null/undef.

Definition at line 644 of file phar.c.

◆ phar_metadata_tracker_has_data()

bool phar_metadata_tracker_has_data ( const phar_metadata_tracker * tracker,
bool persistent )

Check if this has any data, serialized or as a raw value.

Definition at line 634 of file phar.c.

◆ phar_metadata_tracker_try_ensure_has_serialized_data()

void phar_metadata_tracker_try_ensure_has_serialized_data ( phar_metadata_tracker * tracker,
bool persistent )

Attempt to serialize the data. Callers are responsible for handling EG(exception) if one occurs.

Definition at line 567 of file phar.c.

◆ phar_metadata_tracker_unserialize_or_copy()

zend_result phar_metadata_tracker_unserialize_or_copy ( phar_metadata_tracker * tracker,
zval * metadata,
bool persistent,
HashTable * unserialize_options,
const char * method_name )

Parse out metadata when phar_metadata_tracker_has_data is true.

Precondition: phar_metadata_tracker_has_data is true

Definition at line 593 of file phar.c.

◆ phar_object_init()

phar_object_init ( )

Definition at line 5127 of file phar_object.c.

◆ phar_open_executed_filename()

zend_result phar_open_executed_filename ( char * alias,
size_t alias_len,
char ** error )

Invoked when a user calls Phar::mapPhar() from within an executing .phar to set up its manifest directly

Definition at line 2317 of file phar.c.

◆ phar_open_from_filename()

zend_result phar_open_from_filename ( char * fname,
size_t fname_len,
char * alias,
size_t alias_len,
uint32_t options,
phar_archive_data ** pphar,
char ** error )

Return an already opened filename.

Or scan a phar file for the required __HALT_COMPILER(); ?> token and verify that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS or FAILURE is returned and pphar is set to a pointer to the phar's manifest

Definition at line 1543 of file phar.c.

◆ phar_open_or_create_filename()

zend_result phar_open_or_create_filename ( char * fname,
size_t fname_len,
char * alias,
size_t alias_len,
bool is_data,
uint32_t options,
phar_archive_data ** pphar,
char ** error )

Create or open a phar for writing

Definition at line 1310 of file phar.c.

◆ phar_parse_metadata_lazy()

void phar_parse_metadata_lazy ( const char * buffer,
phar_metadata_tracker * tracker,
uint32_t zip_metadata_len,
bool persistent )

Parse out metadata from the manifest for a single file, saving it into a string.

Meta-data is in this format: [len32][data...]

data is the serialized zval

Definition at line 702 of file phar.c.

◆ phar_postprocess_file()

zend_result phar_postprocess_file ( phar_entry_data * idata,
uint32_t crc32,
char ** error,
int process_zip )

Validate the CRC32 of a file opened from within the phar

Definition at line 2378 of file phar.c.

◆ phar_request_initialize()

void phar_request_initialize ( void )

Definition at line 3446 of file phar.c.

◆ phar_restore_orig_functions()

phar_restore_orig_functions ( )

Definition at line 1009 of file func_interceptors.c.

◆ phar_save_orig_functions()

phar_save_orig_functions ( )

Definition at line 982 of file func_interceptors.c.

◆ phar_split_fname()

zend_result phar_split_fname ( const char * filename,
size_t filename_len,
char ** arch,
size_t * arch_len,
char ** entry,
size_t * entry_len,
int executable,
int for_create )

Process a phar stream name, ensuring we can handle any of:

  • whatever.phar
  • whatever.phar.gz
  • whatever.phar.bz2
  • whatever.phar.php

Optionally the name might start with 'phar://'

This is used by phar_parse_url()

Definition at line 2240 of file phar.c.

◆ php_info_print_box_end()

php_info_print_box_end ( )

Definition at line 1100 of file info.c.

◆ php_info_print_box_start()

php_info_print_box_start ( 0 )

◆ php_info_print_table_end()

php_info_print_table_end ( )

Definition at line 1074 of file info.c.

◆ php_info_print_table_row() [1/5]

php_info_print_table_row ( 2 ,
"Phar API version" ,
PHP_PHAR_API_VERSION  )

◆ php_info_print_table_row() [2/5]

php_info_print_table_row ( 2 ,
"Phar-based phar archives" ,
"enabled"  )

◆ php_info_print_table_row() [3/5]

php_info_print_table_row ( 2 ,
"Phar: PHP Archive support" ,
"enabled"  )

◆ php_info_print_table_row() [4/5]

php_info_print_table_row ( 2 ,
"Tar-based phar archives" ,
"enabled"  )

◆ php_info_print_table_row() [5/5]

php_info_print_table_row ( 2 ,
"ZIP-based phar archives" ,
"enabled"  )

◆ php_info_print_table_start()

php_info_print_table_start ( )

Definition at line 1064 of file info.c.

◆ php_register_url_stream_wrapper()

return php_register_url_stream_wrapper ( "phar" ,
& php_stream_phar_wrapper )

◆ PUTS() [1/4]

PUTS ( !sapi_module.phpinfo_as_text?"<br />":"\n" )

◆ PUTS() [2/4]

PUTS ( "Phar based on pear/ PHP_Archive,
original concept by Davey Shafik."  )

◆ PUTS() [3/4]

PUTS ( "Phar fully realized by Gregory Beaver and Marcus Boerger." )

◆ PUTS() [4/4]

PUTS ( "Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle." )

◆ UNREGISTER_INI_ENTRIES()

UNREGISTER_INI_ENTRIES ( )

Variable Documentation

◆ cached_alias

HashTable cached_alias

Definition at line 91 of file phar.c.

◆ cached_phars

HashTable cached_phars

Definition at line 90 of file phar.c.

◆ else

else
Initial value:
{
bool require_hash_orig

Definition at line 59 of file phar.c.

◆ ini

ini = zend_ini_parse_bool(new_value)

Definition at line 63 of file phar.c.

◆ phar_globals

zend_hash_init & phar_globals

Definition at line 3343 of file phar.c.

◆ phar_module_entry

zend_module_entry phar_module_entry
Initial value:
= {
phar_deps,
"Phar",
PHP_MINIT(phar),
PHP_MINFO(phar),
PHP_GINIT(phar),
PHP_GSHUTDOWN(phar),
NULL,
}
#define NULL
Definition gdcache.h:45
#define PHP_GINIT
Definition php.h:397
#define PHP_MINFO
Definition php.h:396
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_RSHUTDOWN
Definition php.h:395
#define PHP_MINIT
Definition php.h:392
#define PHP_MODULE_GLOBALS
Definition php.h:408
#define PHP_GSHUTDOWN
Definition php.h:398
#define PHP_PHAR_VERSION
Definition php_phar.h:23
#define STANDARD_MODULE_PROPERTIES_EX
#define STANDARD_MODULE_HEADER_EX

Definition at line 3581 of file phar.c.

◆ phar_orig_compile_file

phar_orig_compile_file ( zend_file_handle * file_handle,
int type ) = zend_compile_file

Definition at line 3244 of file phar.c.

◆ readonly

phar_globals readonly = 1

Definition at line 3346 of file phar.c.

◆ SUCCESS

return SUCCESS

Definition at line 85 of file phar.c.

◆ zend_compile_file

zend_compile_file = phar_compile_file

Definition at line 3412 of file phar.c.

◆ zend_resolve_path

zend_resolve_path = phar_resolve_path

Definition at line 3415 of file phar.c.