Skip to content

[Embedder API] Lock the FlutterRect struct to guarantee ABI stability  #121347

@loic-sharma

Description

@loic-sharma

Solution

  • Add a comment to FlutterRect that new members cannot be added
  • Add a unit test to verify new members aren't added to FlutterRect.

Background

The engine uses FlutterFrameBufferWithDamageCallback to notify the embedder of a damage region using an array of FlutterRect. Adding members to FlutterRect would break the ABI of this callback.

For example:

FlutterDamage damageRegion = ...;
FlutterRect first = damageRegion.damage[0];
FlutterRect second = damageRegion.damage[1]; // BAD! This could crash

The array indexing might crash if the external embedder wasn't recompiled after an engine update. Instead, external embedders must determine the size of FlutterRect using their struct_size member. Something like:

FlutterDamage damageRegion = ...;
FlutterRect first = damageRegion.damage[0];
FlutterRect second = static_cast<FlutterRect*>(
    static_cast<char*>(damageRegion.damage) + 1 * first.struct_size);

This problem would've been avoided if FlutterDamage.damage was an array of pointers to FlutterRect instead of arrays of FlutterRect.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktope: embedderUsers of the Embedder API

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions