Skip to content

[Impeller] Fix crash trying to check for duplicate vertices in shadow_path code#180920

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
flar:shadow-path-dup-vertex-check-crash
Jan 13, 2026
Merged

[Impeller] Fix crash trying to check for duplicate vertices in shadow_path code#180920
auto-submit[bot] merged 1 commit into
flutter:masterfrom
flar:shadow-path-dup-vertex-check-crash

Conversation

@flar

@flar flar commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #180827

The new general convex path shadow code was checking for duplicate vertices without actually checking if the vectors contained any vertices. Thus, .back() was being called on empty vectors, which is bad. This led to a crash in G3 as their code is being run with a vector implementation that protects against this, but apparently we do not have such a vector implementation in our local building and testing.

No tests because this covered by existing test cases and a new FML_DCHECK, however I'm not sure if we have DCHECKs enabled in CI...?

@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.

@flar flar requested a review from gaaclarke January 13, 2026 18:57
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jan 13, 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 fixes a crash that occurs when checking for duplicate vertices on an empty vector. The fix correctly adds a check to ensure the vectors are not empty before accessing their last elements. My review includes a suggestion to simplify the implementation of this check for better readability and conciseness.

Comment on lines +1362 to 1367
if (index > 0u) {
FML_DCHECK(!gaussians_.empty() && !vertices_.empty());
if (gaussian == gaussians_.back() && vertex == vertices_.back()) {
return index - 1;
}
}

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

The if (index > 0u) check on line 1362 already guarantees that vertices_ and gaussians_ are not empty. This is because index is initialized to vertices_.size(), and the FML_DCHECK on line 1359 ensures gaussians_ has the same size.

Therefore, the FML_DCHECK on line 1363 is redundant.

You can simplify this logic by combining the conditions into a single if statement. C++'s short-circuit evaluation for && will prevent .back() from being called on empty vectors.

  if (index > 0u && gaussian == gaussians_.back() && vertex == vertices_.back()) {
    return index - 1;
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I realize this. It's a check so that tests run with debug_unopt builds will catch any future issues.

Belt-and-suspenders kind of thing and I'm not worried about performance on debug_unopt...

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wish there was a way we could make this crash in our tests too. Is there a linter flag for this? Can we also enable the flags that g3 is using?

FML_DCHECK(index <= std::numeric_limits<uint16_t>::max());
if (gaussian == gaussians_.back() && vertex == vertices_.back()) {
return index - 1;
if (index > 0u) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think if (!gaussians_.empty() && !vertices_.empty()) is more clear instead of branching on the derivative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The thing is that index is sufficient without making 2 method calls. We've already asserted with DCHECK that the 2 vectors are the same length and index contains the size of the vectors. I only added the DCHECK so tests would fail. I tested the unit tests without the index check and the DCHECK crashed and then I added the index check and they passed just fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like at least one of our CI runs is on a debug_unopt build and Jason and John confirmed that it does run the impeller tests. I confirmed before I fixed it that the DCHECK fails without the fix and passes with it, so I think this is OK. Though, as a general rule, I'd rather that all CI tasks that run unit tests run them on a debug_unopt build.

@gaaclarke

Copy link
Copy Markdown
Member

Maybe it's ASAN?

@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 13, 2026
@flar

flar commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

Maybe it's ASAN?

It is believed that the G3 test runs have it enabled, but we don't.

@stuartmorgan-g

Copy link
Copy Markdown
Contributor

test-exempt: new DCHECK changes behavior of existing tests

@auto-submit auto-submit Bot added this pull request to the merge queue Jan 13, 2026
Merged via the queue into flutter:master with commit aec9901 Jan 13, 2026
181 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2026
jtmcdole pushed a commit that referenced this pull request Jan 14, 2026
…_path code (#180920)

The new general convex path shadow code was checking for duplicate
vertices without actually checking if the vectors contained any
vertices. Thus, <vector>.back() was being called on empty vectors, which
is bad. This led to a crash in G3 as their code is being run with a
vector implementation that protects against this, but apparently we do
not have such a vector implementation in our local building and testing.

No tests because this covered by existing test cases and a new
FML_DCHECK, however I'm not sure if we have DCHECKs enabled in CI...?
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 15, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 16, 2026
@flar flar added the cp: stable cherry pick this pull request to stable release candidate branch label Jan 17, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

flar added a commit to flar/flutter that referenced this pull request Jan 17, 2026
…_path code (flutter#180920)

The new general convex path shadow code was checking for duplicate
vertices without actually checking if the vectors contained any
vertices. Thus, <vector>.back() was being called on empty vectors, which
is bad. This led to a crash in G3 as their code is being run with a
vector implementation that protects against this, but apparently we do
not have such a vector implementation in our local building and testing.

No tests because this covered by existing test cases and a new
FML_DCHECK, however I'm not sure if we have DCHECKs enabled in CI...?
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
@jtmcdole jtmcdole added the cp: beta cherry pick this pull request to beta release candidate branch label Jan 20, 2026
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Jan 20, 2026
…_path code (flutter#180920)

The new general convex path shadow code was checking for duplicate
vertices without actually checking if the vectors contained any
vertices. Thus, <vector>.back() was being called on empty vectors, which
is bad. This led to a crash in G3 as their code is being run with a
vector implementation that protects against this, but apparently we do
not have such a vector implementation in our local building and testing.

No tests because this covered by existing test cases and a new
FML_DCHECK, however I'm not sure if we have DCHECKs enabled in CI...?
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
auto-submit Bot pushed a commit that referenced this pull request Jan 27, 2026
… shadow_path code (#180920) (#181095)

The new general convex path shadow code was checking for duplicate vertices without actually checking if the vectors contained any vertices. Thus, <vector>.back() was being called on empty vectors, which is bad. This led to a crash in G3 as their code is being run with a vector implementation that protects against this, but apparently we do not have such a vector implementation in our local building and testing.

No tests because this covered by existing test cases and a new FML_DCHECK.

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Fixes #180827

Impacted users: Any user who uses shadows (pretty much every Flutter app) on a platform that has address sanitization built into its `std::vector` implementation, if they use Impeller (always used on iOS and the default on Android)

Impact Description: Every shadow render operation in Impeller backend will access `back()` on an empty `std::vector` which will crash immediately if the vector is using sanitization on that platform.

Workaround: Potentially look into disabling address sanitization? On platforms that still support Skia, it can be used as a workaround, but that is not an option on iOS

Risk: The fix was obvious and non-controversial.

Test Coverage: Existing tests cover this case really well and there is now an FML_DCHECK (engine assert) to check if we trigger the condition under testing.

Validation: The original issue indicates an app that will trigger the sanitization crash, but only in G3. None of the platforms we support directly through flutter perform this sanitization.

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cp: beta cherry pick this pull request to beta release candidate branch cp: stable cherry pick this pull request to stable release candidate branch e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Google3 Bug]: [Crash Report] `anonymous namespace'::PolygonInfo::AppendVertex-dead1d17

5 participants