From 84766334f64ed5ecc349799406696882cef7ee1d Mon Sep 17 00:00:00 2001 From: SahilMadan <36904562+SahilMadan@users.noreply.github.com> Date: Tue, 27 Sep 2022 12:21:10 -0700 Subject: [PATCH] [flatland] Reduce size of hit-region. (flutter/engine#36447) Currently, the hit-region is size FLT_MAX which is susceptible to numerical overflow when rotating or translating (or any other modification to the value). --- .../flutter/flatland_external_view_embedder.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc index ed0cb2384c..be43799f7a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc @@ -10,6 +10,14 @@ #include "third_party/skia/include/core/SkSurface.h" namespace flutter_runner { +namespace { + +// Since the flatland hit-region can be transformed (rotated, scaled or +// translated), we must ensure that the size of the hit-region will not cause +// overflows on operations (like FLT_MAX would). +constexpr float kMaxHitRegionSize = 1'000'000.f; + +} // namespace FlatlandExternalViewEmbedder::FlatlandExternalViewEmbedder( fuchsia::ui::views::ViewCreationToken view_creation_token, @@ -312,11 +320,12 @@ void FlatlandExternalViewEmbedder::SubmitFrame( child_transforms_.emplace_back( flatland_layers_[flatland_layer_index].transform_id); - // Attach full-screen hit testing shield. + // Attach full-screen hit testing shield. Note that since the hit-region + // may be transformed (translated, rotated), we do not want to set + // width/height to FLT_MAX. This will cause a numeric overflow. flatland_->flatland()->SetHitRegions( flatland_layers_[flatland_layer_index].transform_id, - {{{0, 0, std::numeric_limits::max(), - std::numeric_limits::max()}, + {{{0, 0, kMaxHitRegionSize, kMaxHitRegionSize}, fuchsia::ui::composition::HitTestInteraction:: SEMANTICALLY_INVISIBLE}}); }