From 2664094767b5bbfb26f3fa77ef712175f6bca3c5 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Mon, 6 Nov 2023 09:52:39 -0600 Subject: [PATCH] Modify the concentric finder to guard array bounds A potential resolution to Issue #36. In some cases the array positions suggested by the corner_positions array may be out of bounds for the points array. To resolve this, guard against out of bounds checks. In other cases, where the positions are matched, guard against having the start position of a slice go beyond the end position of the slice. --- src/common/cpp_essentials/concentric_finder.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/common/cpp_essentials/concentric_finder.rs b/src/common/cpp_essentials/concentric_finder.rs index 0263a6d1..cc42a8b4 100644 --- a/src/common/cpp_essentials/concentric_finder.rs +++ b/src/common/cpp_essentials/concentric_finder.rs @@ -389,6 +389,18 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option Option<&[Point]> { if a > b { None + } + // Added for Issue #36 where array is sometimes out of bounds + else if a + 1 >= points.len() || b >= points.len() { + if a + 1 >= points.len() { + None + } else { + Some(&points[a..]) + } + } + // Added for Issue #36 where a sometimes equals b + else if a == b { + Some(&points[a..b]) } else { Some(&points[a + 1..b]) }