You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: archive/phar_without_stub.ksy
+121-30
Original file line number
Diff line number
Diff line change
@@ -11,17 +11,45 @@ meta:
11
11
- /serialization/php_serialized_value
12
12
endian: le
13
13
doc: |
14
-
A phar (PHP archive) file. The phar format is a custom archive format from the PHP ecosystem that is used to package a complete PHP library or application into a single self-contained archive. All phar archives start with an executable PHP stub, which can be used to allow executing or including phar files as if they were regular PHP scripts. PHP 5.3 and later include the phar extension, which adds native support for reading and manipulating phar files.
14
+
A phar (PHP archive) file. The phar format is a custom archive format
15
+
from the PHP ecosystem that is used to package a complete PHP library
16
+
or application into a single self-contained archive.
17
+
All phar archives start with an executable PHP stub, which can be used to
18
+
allow executing or including phar files as if they were regular PHP scripts.
19
+
PHP 5.3 and later include the phar extension, which adds native support for
20
+
reading and manipulating phar files.
15
21
16
-
The phar format was originally developed as part of the PEAR library PHP_Archive, first released in 2005. Later, a native PHP extension named "phar" was developed, which was first released on PECL in 2007, and is included with PHP 5.3 and later. The phar extension has effectively superseded the PHP_Archive library, which has not been updated since 2010. The phar extension is also no longer released independently on PECL; it is now developed and released as part of PHP itself.
22
+
The phar format was originally developed as part of the PEAR library
23
+
PHP_Archive, first released in 2005. Later, a native PHP extension
24
+
named "phar" was developed, which was first released on PECL in 2007,
25
+
and is included with PHP 5.3 and later. The phar extension has effectively
26
+
superseded the PHP_Archive library, which has not been updated since 2010.
27
+
The phar extension is also no longer released independently on PECL;
28
+
it is now developed and released as part of PHP itself.
17
29
18
-
Because of current limitations in Kaitai Struct (see kaitai-io/kaitai_struct#158 and kaitai-io/kaitai_struct#538), the executable PHP stub that precedes the rest of the archive is not handled by this spec. Before parsing a phar using this spec, the stub must be removed manually.
30
+
Because of current limitations in Kaitai Struct
31
+
(seekaitai-io/kaitai_struct#158 and kaitai-io/kaitai_struct#538),
32
+
the executable PHP stub that precedes the rest of the archive is not handled
33
+
by this spec. Before parsing a phar using this spec, the stub must be
34
+
removed manually.
19
35
20
-
A phar's stub is terminated by the special token `__HALT_COMPILER();` (which may be followed by at most one space, the PHP tag end `?>`, and an optional line terminator). The stub termination sequence is immediately followed by the remaining parts of the phar format, as described in this spec.
36
+
A phar's stub is terminated by the special token `__HALT_COMPILER();`
37
+
(which may be followed by at most one space, the PHP tag end `?>`,
38
+
and an optional line terminator). The stub termination sequence is
39
+
immediately followed by the remaining parts of the phar format,
40
+
as described in this spec.
21
41
22
-
The phar stub usually contains code that loads the phar and runs a contained PHP file, but this is not required. A minimal valid phar stub is `<?php __HALT_COMPILER();` - such a stub makes it impossible to execute the phar directly, but still allows loading or manipulating it using the phar extension.
42
+
The phar stub usually contains code that loads the phar and runs
43
+
a contained PHP file, but this is not required. A minimal valid phar stub
44
+
is `<?php __HALT_COMPILER();` - such a stub makes it impossible to execute
45
+
the phar directly, but still allows loading or manipulating it using the
46
+
phar extension.
23
47
24
-
Note: The phar format does not specify any encoding for text fields (stub, alias name, and all file names), so these fields may contain arbitrary binary data. The actual text encoding used in a specific phar file usually depends on the application that created the phar, and on the standard encoding of the system on which the phar was created.
48
+
Note: The phar format does not specify any encoding for text fields
49
+
(stub, alias name, and all file names), so these fields may contain arbitrary
50
+
binary data. The actual text encoding used in a specific phar file usually
51
+
depends on the application that created the phar, and on the
52
+
standard encoding of the system on which the phar was created.
doc: The contents of each file in the archive (possibly compressed, as indicated by the file's flags in the manifest). The files are stored in the same order as they appear in the manifest.
68
+
doc: |
69
+
The contents of each file in the archive (possibly compressed,
70
+
as indicated by the file's flags in the manifest). The files are stored
71
+
in the same order as they appear in the manifest.
39
72
- id: signature
40
73
type: signature
41
74
size-eos: true
42
75
if: manifest.flags.has_signature
43
76
doc: |
44
-
The archive's signature - a digest of all archive data before the signature itself.
77
+
The archive's signature - a digest of all archive data before
78
+
the signature itself.
45
79
46
-
Note: Almost all of the available "signature" types are actually hashes, not signatures, and cannot be used to verify that the archive has not been tampered with. Only the OpenSSL signature type is a true cryptographic signature.
80
+
Note: Almost all of the available "signature" types are actually hashes,
81
+
not signatures, and cannot be used to verify that the archive has not
82
+
been tampered with. Only the OpenSSL signature type is a true
83
+
cryptographic signature.
47
84
enums:
48
85
signature_type:
49
86
0x1:
@@ -57,18 +94,27 @@ enums:
57
94
0x4:
58
95
id: sha256
59
96
-orig-id: PHAR_SIG_SHA256
60
-
doc: Indicates a SHA-256 hash. Available since API version 1.1.0, PHP_Archive 0.12.0 and phar extension 1.1.0.
97
+
doc: |
98
+
Indicates a SHA-256 hash. Available since API version 1.1.0,
99
+
PHP_Archive 0.12.0 and phar extension 1.1.0.
61
100
0x8:
62
101
id: sha512
63
102
-orig-id: PHAR_SIG_SHA512
64
-
doc: Indicates a SHA-512 hash. Available since API version 1.1.0, PHP_Archive 0.12.0 and phar extension 1.1.0.
103
+
doc: |
104
+
Indicates a SHA-512 hash. Available since API version 1.1.0,
105
+
PHP_Archive 0.12.0 and phar extension 1.1.0.
65
106
0x10:
66
107
id: openssl
67
108
-orig-id: PHAR_SIG_OPENSSL
68
109
doc: |
69
-
Indicates an OpenSSL signature. Available since API version 1.1.1, PHP_Archive 0.12.0 (even though it claims to only support API version 1.1.0) and phar extension 1.3.0. This type is not documented in the phar extension's documentation of the phar format.
110
+
Indicates an OpenSSL signature. Available since API version 1.1.1,
111
+
PHP_Archive 0.12.0 (even though it claims to only support
112
+
API version 1.1.0) and phar extension 1.3.0. This type is not
113
+
documented in the phar extension's documentation of the phar format.
70
114
71
-
Note: In older versions of the phar extension, this value was used for an undocumented and unimplemented "PGP" signature type (`PHAR_SIG_PGP`).
115
+
Note: In older versions of the phar extension, this value was used
116
+
for an undocumented and unimplemented "PGP" signature type
117
+
(`PHAR_SIG_PGP`).
72
118
types:
73
119
serialized_value:
74
120
seq:
@@ -105,13 +151,20 @@ types:
105
151
doc: The length of the file name, in bytes.
106
152
- id: filename
107
153
size: len_filename
108
-
doc: The name of this file. If the name ends with a slash, this entry represents a directory, otherwise a regular file. Directory entries are supported since phar API version 1.1.1. (Explicit directory entries are only needed for empty directories. Non-empty directories are implied by the files located inside them.)
154
+
doc: |
155
+
The name of this file. If the name ends with a slash, this entry
156
+
represents a directory, otherwise a regular file. Directory entries
157
+
are supported since phar API version 1.1.1.
158
+
(Explicit directory entries are only needed for empty directories.
159
+
Non-empty directories are implied by the files located inside them.)
109
160
- id: len_data_uncompressed
110
161
type: u4
111
162
doc: The length of the file's data when uncompressed, in bytes.
112
163
- id: timestamp
113
164
type: u4
114
-
doc: The time at which the file was added or last updated, as a Unix timestamp.
165
+
doc: |
166
+
The time at which the file was added or last updated, as a
167
+
Unix timestamp.
115
168
- id: len_data_compressed
116
169
type: u4
117
170
doc: The length of the file's data when compressed, in bytes.
@@ -128,7 +181,11 @@ types:
128
181
size: len_metadata
129
182
type: serialized_value
130
183
if: len_metadata != 0
131
-
doc: Metadata for this file, in the format used by PHP's `serialize` function. The meaning of the serialized data is not specified further, it may be used to store arbitrary custom data about the file.
184
+
doc: |
185
+
Metadata for this file, in the format used by PHP's
186
+
`serialize` function. The meaning of the serialized data is not
187
+
specified further, it may be used to store arbitrary custom data
188
+
about the file.
132
189
api_version:
133
190
meta:
134
191
endian: be
@@ -142,16 +199,38 @@ types:
142
199
- id: unused
143
200
type: b4
144
201
doc: |
145
-
A phar API version number. This version number is meant to indicate which features are used in a specific phar, so that tools reading the phar can easily check that they support all necessary features.
202
+
A phar API version number. This version number is meant to indicate
203
+
which features are used in a specific phar, so that tools reading
204
+
the phar can easily check that they support all necessary features.
146
205
147
206
The following API versions exist so far:
148
207
149
-
* 0.5, 0.6, 0.7, 0.7.1: The first official API versions. At this point, the phar format was only used by the PHP_Archive library, and the API version numbers were identical to the PHP_Archive versions that supported them. Development of the native phar extension started around API version 0.7. These API versions could only be queried using the `PHP_Archive::APIversion()` method, but were not stored physically in archives. These API versions are not supported by this spec.
150
-
* 0.8.0: Used by PHP_Archive 0.8.0 (released 2006-07-18) and later development versions of the phar extension. This is the first version number to be physically stored in archives. This API version is not supported by this spec.
151
-
* 0.9.0: Used by later development/early beta versions of the phar extension. Also temporarily used by PHP_Archive 0.9.0 (released 2006-12-15), but reverted back to API version 0.8.0 in PHP_Archive 0.9.1 (released 2007-01-05).
152
-
* 1.0.0: Supported since PHP_Archive 0.10.0 (released 2007-05-29) and phar extension 1.0.0 (released 2007-03-28). This is the first stable, forwards-compatible and documented version of the format.
153
-
* 1.1.0: Supported since PHP_Archive 0.12.0 (released 2015-07-06) and phar extension 1.1.0 (released 2007-04-12). Adds SHA-256 and SHA-512 signature types.
154
-
* 1.1.1: Supported since phar extension 2.0.0 (released 2009-07-29 and included with PHP 5.3 and later). (PHP_Archive 0.12.0 also supports all features from API verison 1.1.1, but it reports API version 1.1.0.) Adds the OpenSSL signature type and support for storing empty directories.
208
+
* 0.5, 0.6, 0.7, 0.7.1: The first official API versions. At this point,
209
+
the phar format was only used by the PHP_Archive library, and the
210
+
API version numbers were identical to the PHP_Archive versions that
211
+
supported them. Development of the native phar extension started around
212
+
API version 0.7. These API versions could only be queried using the
213
+
`PHP_Archive::APIversion()` method, but were not stored physically
214
+
in archives. These API versions are not supported by this spec.
215
+
* 0.8.0: Used by PHP_Archive 0.8.0 (released 2006-07-18) and
216
+
later development versions of the phar extension. This is the first
217
+
version number to be physically stored in archives. This API version
218
+
is not supported by this spec.
219
+
* 0.9.0: Used by later development/early beta versions of the
220
+
phar extension. Also temporarily used by PHP_Archive 0.9.0
221
+
(released 2006-12-15), but reverted back to API version 0.8.0 in
222
+
PHP_Archive 0.9.1 (released 2007-01-05).
223
+
* 1.0.0: Supported since PHP_Archive 0.10.0 (released 2007-05-29)
224
+
and phar extension 1.0.0 (released 2007-03-28). This is the first
225
+
stable, forwards-compatible and documented version of the format.
226
+
* 1.1.0: Supported since PHP_Archive 0.12.0 (released 2015-07-06)
227
+
and phar extension 1.1.0 (released 2007-04-12). Adds SHA-256 and
228
+
SHA-512 signature types.
229
+
* 1.1.1: Supported since phar extension 2.0.0 (released 2009-07-29 and
230
+
included with PHP 5.3 and later). (PHP_Archive 0.12.0 also supports
231
+
all features from API verison 1.1.1, but it reports API version 1.1.0.)
232
+
Adds the OpenSSL signature type and support for storing
233
+
empty directories.
155
234
global_flags:
156
235
seq:
157
236
- id: value
@@ -161,11 +240,15 @@ types:
161
240
any_zlib_compressed:
162
241
value: (value & 0x1000) != 0
163
242
-orig-id: PHAR_HDR_COMPRESSED_GZ
164
-
doc: Whether any of the files in this phar are stored using zlib compression.
243
+
doc: |
244
+
Whether any of the files in this phar are stored using
245
+
zlib compression.
165
246
any_bzip2_compressed:
166
247
value: (value & 0x2000) != 0
167
248
-orig-id: PHAR_HDR_COMPRESSED_BZ2
168
-
doc: Whether any of the files in this phar are stored using bzip2 compression.
249
+
doc: |
250
+
Whether any of the files in this phar are stored using
251
+
bzip2 compression.
169
252
has_signature:
170
253
value: (value & 0x10000) != 0
171
254
-orig-id: PHAR_HDR_SIGNATURE
@@ -177,7 +260,8 @@ types:
177
260
doc: |
178
261
The length of the manifest, in bytes.
179
262
180
-
Note: The phar extension does not allow reading manifests larger than 100 MiB.
263
+
Note: The phar extension does not allow reading manifests
264
+
larger than 100 MiB.
181
265
- id: num_files
182
266
type: u4
183
267
doc: The number of files in this phar.
@@ -192,15 +276,20 @@ types:
192
276
doc: The length of the alias, in bytes.
193
277
- id: alias
194
278
size: len_alias
195
-
doc: The phar's alias, i. e. the name under which it is loaded into PHP.
279
+
doc: |
280
+
The phar's alias, i. e. the name under which it is loaded into PHP.
196
281
- id: len_metadata
197
282
type: u4
198
283
doc: The size of the metadata, in bytes, or 0 if there is none.
199
284
- id: metadata
200
285
size: len_metadata
201
286
type: serialized_value
202
287
if: len_metadata != 0
203
-
doc: Metadata for this phar, in the format used by PHP's `serialize` function. The meaning of the serialized data is not specified further, it may be used to store arbitrary custom data about the archive.
288
+
doc: |
289
+
Metadata for this phar, in the format used by PHP's
290
+
`serialize` function. The meaning of the serialized data is not
291
+
specified further, it may be used to store arbitrary custom data
292
+
about the archive.
204
293
- id: file_entries
205
294
type: file_entry
206
295
repeat: expr
@@ -210,7 +299,9 @@ types:
210
299
seq:
211
300
- id: data
212
301
size: _io.size - _io.pos - 8
213
-
doc: The signature data. The size and contents depend on the signature type.
302
+
doc: |
303
+
The signature data. The size and contents depend on the
0 commit comments