Box::parse( Avifinfo\stream $handle, int $num_parsed_boxes, int $num_remaining_bytes = MAX_SIZE ): Avifinfo\Status
- Source
wp-includes/class-avif-info.php:231
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$handleAvifinfo\stream- The resource the header will be parsed from.
$num_parsed_boxesint- The total number of parsed boxes. Prevents timeouts.
$num_remaining_bytesintoptional- The number of bytes that should be available from the resource.Default:
MAX_SIZE
Return value
Avifinfo\Status- FOUND on success or an error on failure.
Performance profile
How much work a call to Box::parse() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 44–135
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 186.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Box::parse() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$num_remaining_bytes && !$header_size | 44–72 | read(), read_big_endian() |
!$num_remaining_bytes && !$header_size && !$num_parsed_boxes && !$data | 63–76 | read(), read_big_endian(), read() |
!$num_remaining_bytes && !$header_size && !$num_parsed_boxes && $data | 85–135 | read(), read_big_endian(), read(), read_big_endian(), read_big_endian() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 186 | 44–135 | 34 | |
| 8.5 | 186 | 44–135 | 34 | |
| 8.4 | 186 | 44–135 | 34 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 195 | 47–141 | 34 | |
| 8.2 | 195 | 47–141 | 34 | |
| 8.1 | 195 | 47–141 | 34 | |
| 7.4 | 195 | 47–141 | 34 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- read()Reads bytes and advances the stream position by the same count.
- read_big_endian()Reads an unsigned integer with most significant bits first.
Source code
public function parse( $handle, &$num_parsed_boxes, $num_remaining_bytes = MAX_SIZE ) { // See ISO/IEC 14496-12:2012(E) 4.2 $header_size = 8; // box 32b size + 32b type (at least) if ( $header_size > $num_remaining_bytes ) { return INVALID; } if ( !( $data = read( $handle, 8 ) ) ) { return TRUNCATED; } $this->size = read_big_endian( $data, 4 ); $this->type = substr( $data, 4, 4 ); // 'box->size==1' means 64-bit size should be read after the box type. // 'box->size==0' means this box extends to all remaining bytes. if ( $this->size == 1 ) { $header_size += 8; if ( $header_size > $num_remaining_bytes ) { return INVALID; } if ( !( $data = read( $handle, 8 ) ) ) { return TRUNCATED; } // Stop the parsing if any box has a size greater than 4GB. if ( read_big_endian( $data, 4 ) != 0 ) { return ABORTED; } // Read the 32 least-significant bits. $this->size = read_big_endian( substr( $data, 4, 4 ), 4 ); } else if ( $this->size == 0 ) { // ISO/IEC 14496-12 4.2.2: // if size is 0, then this box shall be in a top-level box // (i.e. not contained in another box) // Unfortunately the presence of a parent box is unknown here. $this->size = $num_remaining_bytes; } if ( $this->size < $header_size ) { return INVALID; } if ( $this->size > $num_remaining_bytes ) { return INVALID; } // 16 bytes of usertype should be read here if the box type is 'uuid'. // 'uuid' boxes are skipped so usertype is part of the skipped body. $has_fullbox_header = $this->type == 'meta' || $this->type == 'pitm' || $this->type == 'ipma' || $this->type == 'ispe' || $this->type == 'pixi' || $this->type == 'iref' || $this->type == 'auxC'; if ( $has_fullbox_header ) { $header_size += 4; } if ( $this->size < $header_size ) { return INVALID; } $this->content_size = $this->size - $header_size; // Avoid timeouts. The maximum number of parsed boxes is arbitrary. ++$num_parsed_boxes; if ( $num_parsed_boxes >= MAX_NUM_BOXES ) { return ABORTED; } $this->version = 0; $this->flags = 0; if ( $has_fullbox_header ) { if ( !( $data = read( $handle, 4 ) ) ) { return TRUNCATED; } $this->version = read_big_endian( $data, 1 ); $this->flags = read_big_endian( substr( $data, 1, 3 ), 3 ); // See AV1 Image File Format (AVIF) 8.1 // at https://aomediacodec.github.io/av1-avif/#avif-boxes (available when // https://github.com/AOMediaCodec/av1-avif/pull/170 is merged). $is_parsable = ( $this->type == 'meta' && $this->version <= 0 ) || ( $this->type == 'pitm' && $this->version <= 1 ) || ( $this->type == 'ipma' && $this->version <= 1 ) || ( $this->type == 'ispe' && $this->version <= 0 ) || ( $this->type == 'pixi' && $this->version <= 0 ) || ( $this->type == 'iref' && $this->version <= 1 ) || ( $this->type == 'auxC' && $this->version <= 0 ); // Instead of considering this file as invalid, skip unparsable boxes.Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-avif-info.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.