Skip to content

Verify shader bundle FlatBuffer before access in flutter_gpu ShaderLibrary#188252

Open
adilburaksen wants to merge 1 commit into
flutter:masterfrom
adilburaksen:fix-shaderbundle-verifier
Open

Verify shader bundle FlatBuffer before access in flutter_gpu ShaderLibrary#188252
adilburaksen wants to merge 1 commit into
flutter:masterfrom
adilburaksen:fix-shaderbundle-verifier

Conversation

@adilburaksen

Copy link
Copy Markdown
Contributor

Description

ParseShaderBundle in engine/src/flutter/lib/gpu/shader_library.cc checks the
"IPSB" file identifier and then immediately calls GetShaderBundle() and reads
fields (format_version(), the shaders vector, names, mappings) without first
running a flatbuffers::Verifier
. A buffer with a valid identifier but corrupt
internal offsets is therefore read out of bounds.

This is the same structural-verification gap that was recently fixed for the two
sibling loaders in #187878:

  • impeller/runtime_stage/runtime_stage.cc (VerifyRuntimeStagesBuffer)
  • impeller/shader_archive/shader_archive.cc (VerifyShaderArchiveBuffer)

The flutter_gpu shader-bundle loader (IPSB), reachable via
ShaderLibrary.fromAsset / MakeFromFlatbuffer, was not covered by that change.

Change

Add a VerifyShaderBundleBuffer() check after the identifier check and before
GetShaderBundle(), mirroring the sibling loaders. The generated
shader_bundle_flatbuffers.h (already included) provides the verifier; no new
include is required. On verification failure the loader returns an empty shader
map, consistent with the function's existing early-return behavior.

I'm happy to add a unit test mirroring RejectsCorruptBufferWithValidIdentifier
from #187878 if a maintainer prefers it wired in.

…brary

ParseShaderBundle in lib/gpu/shader_library.cc checks the "IPSB" file
identifier and then calls GetShaderBundle() and reads fields from the buffer
without first running a flatbuffers::Verifier. A buffer with a valid identifier
but corrupt internal offsets is therefore read out of bounds.

Add a VerifyShaderBundleBuffer() check after the identifier check and before
GetShaderBundle(), mirroring the verification recently added for the runtime
stage and shader archive loaders.
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team labels Jun 19, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU Jun 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces structural verification of the FlatBuffer in ParseShaderBundle before accessing its fields to prevent potential out-of-bounds reads. The review feedback recommends removing a redundant reinterpret_cast on payload->GetMapping() to simplify the verifier initialization.

Comment on lines +189 to +191
flatbuffers::Verifier verifier(
reinterpret_cast<const uint8_t*>(payload->GetMapping()),
payload->GetSize());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since fml::Mapping::GetMapping() already returns const uint8_t*, the reinterpret_cast is redundant. Removing it simplifies the code and improves readability.

  flatbuffers::Verifier verifier(payload->GetMapping(), payload->GetSize());
References
  1. Avoid redundant casts to keep the code clean and readable, adhering to general C++ best practices and the Google C++ Style Guide. (link)

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

Labels

engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team

Projects

Status: 🤔 Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant