mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
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.
This commit is contained in:
@@ -389,6 +389,18 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
|
||||
let try_get_range = |a: usize, b: usize| -> 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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user