Skip to content

Commit b14fb96

Browse files
committed
Make Path::Polyline::GetContourPointBounds safe for OOB (flutter#60)
1 parent 6da61e7 commit b14fb96

File tree

4 files changed

+14
-123
lines changed

4 files changed

+14
-123
lines changed

impeller/geometry/geometry_unittests.cc

+7
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,12 @@ TEST(GeometryTest, PolylineGetContourPointBoundsReturnsCorrectRanges) {
853853
ASSERT_EQ(b2, 6u);
854854
}
855855

856+
TEST(GeometryTest, PolylineGetContourOutOfBoundsAborts) {
857+
Path::Polyline polyline =
858+
PathBuilder{}.AddLine({100, 100}, {200, 100}).TakePath().CreatePolyline();
859+
ASSERT_EQ(polyline.GetContourPointBounds(0), std::make_tuple(2u, 2u));
860+
ASSERT_EQ(polyline.GetContourPointBounds(14), std::make_tuple(2u, 2u));
861+
}
862+
856863
} // namespace testing
857864
} // namespace impeller

impeller/geometry/path.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ Path::~Path() = default;
1818

1919
std::tuple<size_t, size_t> Path::Polyline::GetContourPointBounds(
2020
size_t contour_index) const {
21-
const size_t start_index = contours[contour_index].start_index;
21+
if (contour_index >= contours.size()) {
22+
return {points.size(), points.size()};
23+
}
24+
const size_t start_index = contours.at(contour_index).start_index;
2225
const size_t end_index = (contour_index >= contours.size() - 1)
2326
? points.size()
24-
: contours[contour_index + 1].start_index;
27+
: contours.at(contour_index + 1).start_index;
2528
return std::make_tuple(start_index, end_index);
2629
}
2730

impeller/geometry/path.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class Path {
6161

6262
/// Convenience method to compute the start (inclusive) and end (exclusive)
6363
/// point of the given contour index.
64+
///
65+
/// The contour_index parameter is clamped to contours.size().
6466
std::tuple<size_t, size_t> GetContourPointBounds(
6567
size_t contour_index) const;
6668
};

impeller/renderer/tessellator.cc

-121
This file was deleted.

0 commit comments

Comments
 (0)