Skip to content

fix(shorebird): let the createForSnapshots tests supply region lengths - #170

Open
nickshorebird wants to merge 1 commit into
shorebird/devfrom
fix/shorebird-unittests-createforsnapshots
Open

nickshorebird wants to merge 1 commit into
shorebird/devfrom
fix/shorebird-unittests-createforsnapshots

Conversation

@nickshorebird

Copy link
Copy Markdown

Summary

The three CreateForSnapshots tests have crashed since they were added, so the blob ordering they guard has never been checked. They hand createForSnapshots 4 byte strings, and it asks the VM to parse a snapshot header out of them. Production cannot use the mapping's own size instead, because AOT regions arrive as fml::SymbolMapping, whose GetSize() is 0 for a dlsym'd address that carries no extent. So the length lookup became a parameter, defaulted to the Dart API, rather than production getting weaker to suit a test.

Testing

  • shorebird_unittests 41 of 41, the three crashing cases passing by name. This suite has no CI lane, so I built and ran it by hand against arm64 debug unopt.
  • The one production caller still uses the default overload, so the Dart size calls are untouched.

The three CreateForSnapshots tests have crashed since they were added.
createForSnapshots asks the VM for each region's length, and the tests hand
it 4 byte strings, so the parser reads a header out of arbitrary bytes and
dereferences it.

Production cannot use the mapping's own size instead, because an AOT
snapshot's regions arrive as fml::SymbolMapping, whose GetSize() is 0 for a
dlsym'd symbol address that carries no extent. Only the snapshot header
knows. So the lookup becomes a parameter, defaulted to the Dart API, and the
tests pass their own.

Production keeps calling Dart_SnapshotDataSize and Dart_SnapshotInstrSize
through the default overload, which is what the single caller uses.
@nickshorebird nickshorebird added the bug Something isn't working label Sep 21, 2026
@nickshorebird nickshorebird self-assigned this Sep 21, 2026

@easymac easymac left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

// Production has to ask the Dart VM. An AOT snapshot's regions arrive as
// fml::SymbolMapping, whose GetSize() is 0 because a dlsym'd symbol address
// carries no extent. Only the snapshot header knows where the region ends.
using RegionSizer = std::function<size_t(const uint8_t* region)>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider passing the size directly here; I think it may be simpler for callers to use something like createForSnapshots(*snapshot, data.size(), instructions.size())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants