Make WordPress Core

Changeset 62029


Ignore:
Timestamp:
03/14/2026 11:54:43 PM (8 weeks ago)
Author:
SergeyBiryukov
Message:

Media: Correct parsing AVIF files with empty iref box on older PHP versions.

An empty iref box is pointless but is allowed by the specification. This commit imports an upstream fix from libavifinfo.

Follow-up to [57524], [58049].

Props yguyon.
Fixes #64669.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-avif-info.php

    r58049 r62029  
    1010 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
    1111 *
    12  * Note: this class is from libavifinfo - https://aomedia.googlesource.com/libavifinfo/+/refs/heads/main/avifinfo.php at f509487.
     12 * Note: this class is from libavifinfo - https://aomedia.googlesource.com/libavifinfo/+/refs/heads/main/avifinfo.php at 2b924de.
    1313 * It is used as a fallback to parse AVIF files when the server doesn't support AVIF,
    1414 * primarily to identify the width and height of the image.
     
    110110  public $primary_item_features = array( // Deduced from the data below.
    111111    'width'        => UNDEFINED, // In number of pixels.
    112     'height'       => UNDEFINED, // Ignores mirror and rotation.
     112    'height'       => UNDEFINED, // Ignores crop and rotation.
    113113    'bit_depth'    => UNDEFINED, // Likely 8, 10 or 12 bits per channel per pixel.
    114114    'num_channels' => UNDEFINED  // Likely 1, 2, 3 or 4 channels:
     
    257257      $this->size = read_big_endian( substr( $data, 4, 4 ), 4 );
    258258    } else if ( $this->size == 0 ) {
     259      // ISO/IEC 14496-12 4.2.2:
     260      //   if size is 0, then this box shall be in a top-level box
     261      //   (i.e. not contained in another box)
     262      // Unfortunately the presence of a parent box is unknown here.
    259263      $this->size = $num_remaining_bytes;
    260264    }
     
    265269      return INVALID;
    266270    }
     271
     272    // 16 bytes of usertype should be read here if the box type is 'uuid'.
     273    // 'uuid' boxes are skipped so usertype is part of the skipped body.
    267274
    268275    $has_fullbox_header = $this->type == 'meta' || $this->type == 'pitm' ||
     
    303310      // Instead of considering this file as invalid, skip unparsable boxes.
    304311      if ( !$is_parsable ) {
    305         $this->type = 'unknownversion';
     312        $this->type = 'skip'; // FreeSpaceBox. To be ignored by readers.
    306313      }
    307314    }
     
    484491   * Parses an "iprp" box.
    485492   *
    486    * The "ipco" box contain the properties which are linked to items by the "ipma" box.
     493   * The "ipco" box contains the properties which are linked to items by the "ipma" box.
    487494   *
    488495   * @param stream  $handle              The resource the box will be parsed from.
     
    597604   */
    598605  private function parse_iref( $num_remaining_bytes ) {
    599     do {
     606    while ( $num_remaining_bytes > 0 ) {
    600607      $box    = new Box();
    601608      $status = $box->parse( $this->handle, $this->num_parsed_boxes, $num_remaining_bytes );
     
    657664      }
    658665      $num_remaining_bytes -= $box->size;
    659     } while ( $num_remaining_bytes > 0 );
     666    }
    660667    return NOT_FOUND;
    661668  }
Note: See TracChangeset for help on using the changeset viewer.