Skip to content

Prevent crash in tessellator with extreme radii - #196648

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Hixie:tesselator_crash
Nov 20, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
Hixie:tesselator_crash

Conversation

@Hixie

@Hixie Hixie commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ComputeQuadrantDivisions did not handle values above INT_MAX (or NaN/Inf), because it converted to integer before checking the range. The code now checks the range as a double first, and also verifies the input isn't infinite or NaN.

Also, fix a bug in FilledEllipse that passed the diameter to ComputeQuadrantDivisions instead of the radius, and thus overestimated the required number of divisions.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Nov 15, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Nov 15, 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 improves the robustness of the tessellator by handling NaN, infinite, and extremely large radii in ComputeQuadrantDivisions to prevent undefined behavior and crashes. It also corrects FilledEllipse to use the radius instead of the diameter for division calculations and adds comprehensive unit tests. The feedback suggests using std::ceil instead of the global ceil function to comply with the Google C++ Style Guide and avoid unnecessary type promotions.

// Range-check as a float *before* converting to an integer: converting a
// float above INT_MAX to int is undefined behaviour (it comes out as
// INT_MIN on x86-64, which then crashes as it reads outside the table).
impeller::Scalar pixel_radius_ceil = ceil(pixel_radius);

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

Use std::ceil instead of ceil. Since pixel_radius is of type impeller::Scalar (which is float), using std::ceil from <cmath> avoids promoting the argument to double and then demoting the result back to float.

Suggested change
impeller::Scalar pixel_radius_ceil = ceil(pixel_radius);
impeller::Scalar pixel_radius_ceil = std::ceil(pixel_radius);
References
  1. C++ code should follow the Google C++ Style Guide, which prefers standard library functions from <cmath> (like std::ceil) over global ones from <math.h>. (link)

// afford to be more accurate using the acos formula here for larger radii.
double k = impeller::Tessellator::kCircleTolerance / pixel_radius;
return ceil(impeller::kPiOver4 / std::acos(1 - k));
double divisions = ceil(impeller::kPiOver4 / std::acos(1 - k));

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

Use std::ceil instead of ceil to adhere to the Google C++ Style Guide and ensure standard library functions are properly namespaced.

Suggested change
double divisions = ceil(impeller::kPiOver4 / std::acos(1 - k));
double divisions = std::ceil(impeller::kPiOver4 / std::acos(1 - k));
References
  1. C++ code should follow the Google C++ Style Guide, which prefers standard library functions from <cmath> (like std::ceil) over global ones from <math.h>. (link)

@Hixie

Hixie commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

ok well with this fix a very large drawOval end up hanging instead of crashing, i'll add a fix for that too, one sec.

ComputeQuadrantDivisions did not handle values above INT_MAX (or
NaN/Inf), because it converted to integer before checking the range.
The code now checks the range as a double first, and also verifies the
input isn't infinite or NaN.

Also, fix a bug in FilledEllipse that passed the diameter to
ComputeQuadrantDivisions instead of the radius, and thus overestimated
the required number of divisions.
Wang's formula (and its conic analogue) had no upper bound. For curves
with very large coordinates, such as an oval drawn in "world" units and
positioned with a transform, squared lengths overflow float and the
subdivision count becomes infinite (or NaN, via inf * 0 for conics with
weight 1). The fill, stroke, and shadow tessellators then loop forever.
Even without overflow, coordinates around 1e12 asked for over a million
segments per curve.

This was seen as a raster thread hang when drawing a blurred oval with
bounds around 1e21: the blur takes the shadow mesh fast path, which
tessellates the oval as four conics.

Clamp all three Compute*Subdivisions functions to kMaxCurveSubdivisions,
mapping non-finite counts to the maximum. The limit is shared with
Tessellator::kMaxQuadrantDivisions through a new
kMaxSegmentsPerQuarterTurn constant, since ovals and round rect corners
reach Wang's formula as one conic per quarter turn.

Claude-Session: https://claude.ai/code/session_019qUZgGHwJP6eP9ewDoAT4X
…nges

clang-tidy's clang-analyzer-security.FloatLoopCounter check rejects
floating point loop counters. Iterate over integers and derive the same
radii from them.

Claude-Session: https://claude.ai/code/session_019qUZgGHwJP6eP9ewDoAT4X
@gaaclarke
gaaclarke requested a review from flar November 17, 2026 21:35
@gaaclarke

Copy link
Copy Markdown
Member

@flar can you give this a look please?

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #196648 at sha 71bb6d2

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Nov 19, 2026
@Hixie

Hixie commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

golden changes look like what i'd expect

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

All LGTM

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 20, 2026
@flar

flar commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

It's waiting for golden approval. I skimmed them and they looked fine, but I think @Hixie did a more thorough examination?

@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 20, 2026
Merged via the queue into flutter:master with commit df5fbe0 Nov 20, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 20, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 21, 2026
flutter/flutter@b34b017...5423f94

2026-11-21 [email protected] Make an Impeller render target from a Vulkan backing store (flutter/flutter#193003)
2026-11-21 [email protected] Persist the vulkan shader cache on teardown (flutter/flutter#197017)
2026-11-21 [email protected] [flutter_tools] Preserve rolling log buffer for Chromium crash diagnostics (flutter/flutter#196037)
2026-11-21 [email protected] Roll Skia from 8845aecd8c53 to 39e0ad394168 (2 revisions) (flutter/flutter#197094)
2026-11-21 [email protected] Adds redirect for listen package in api.flutter.dev (flutter/flutter#197068)
2026-11-21 [email protected] Roll Dart SDK from c6857d58f0ec to fc86f5a42779 (1 revision) (flutter/flutter#197086)
2026-11-20 [email protected] iOS: Discard pending platform view disposals on reset (flutter/flutter#197026)
2026-11-20 [email protected] Tolerate a missing flutter/service_worker handler in the web first-frame notification (flutter/flutter#196329)
2026-11-20 [email protected] Roll Skia from 9aafbb357743 to 8845aecd8c53 (2 revisions) (flutter/flutter#197080)
2026-11-20 [email protected] Prevent crash in tessellator with extreme radii (flutter/flutter#196648)
2026-11-20 [email protected] Windows: in the flutter tool, always close the file handle in _download even when an HTTP request fails so that it is not left open and becomes undeletable (flutter/flutter#197061)
2026-11-20 [email protected] Roll Skia from b61640825c5b to 9aafbb357743 (7 revisions) (flutter/flutter#197066)
2026-11-20 [email protected] Swap dependabot reviewers (flutter/flutter#196995)
2026-11-20 [email protected] [iOS] Hide UIScrollEdgeEffect on FlutterSemanticsScrollView and scroll-to-top UIScrollView on iOS 26+ (flutter/flutter#195356)
2026-11-20 [email protected] [devicelab] Enable Vulkan GPU tracing by default on Android Impeller PerfTests (flutter/flutter#196822)
2026-11-20 [email protected] Roll Dart SDK from 3b5f45d812f8 to c6857d58f0ec (1 revision) (flutter/flutter#197063)
2026-11-20 [email protected] [flutter_tools] Delete flutter.version.json when switching channels (flutter/flutter#196943)
2026-11-20 [email protected] Update desktop TESTOWNERS (flutter/flutter#196930)
2026-11-20 [email protected] [web] Release CanvasKit WebGL contexts and surfaces when a view is removed (flutter/flutter#196816)
2026-11-20 [email protected] [Linux] Hide libunwind symbols in libflutter_linux_gtk.so (flutter/flutter#196451)
2026-11-20 [email protected] Roll Skia from a1edf5c2ea5c to b61640825c5b (1 revision) (flutter/flutter#197058)
2026-11-20 [email protected] [flutter_tools] Update --web-content-hash serving tip to cover assets and canvaskit (flutter/flutter#196908)
2026-11-20 [email protected] Send a semantics update when only the identifier changes (flutter/flutter#196460)
2026-11-20 [email protected] Roll Packages from 81b7c44 to 898818d (11 revisions) (flutter/flutter#197056)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@Hixie

Hixie commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

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

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants