From 83d78fb9701c46a1286717490630bb4f43308d42 Mon Sep 17 00:00:00 2001 From: Olssdani Date: Tue, 21 Mar 2023 13:55:24 +0100 Subject: [PATCH 1/2] Fixed crash --- src/maxicode/detector.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index 18b3244..f22c00f 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -281,7 +281,9 @@ impl Circle<'_> { // count left while { let point = get_point(self.center, (x, y), rotation); - !self.image.get(point.x as u32, point.y as u32) && x > 0 + !self.image.check_in_bounds(point.x as u32, point.y as u32) + && !self.image.get(point.x as u32, point.y as u32) + && x > 0 } { x -= 1; length += 1; @@ -293,7 +295,8 @@ impl Circle<'_> { // count right while { let point = get_point(self.center, (x, y), rotation); - !self.image.get(point.x as u32, point.y as u32) + !self.image.check_in_bounds(point.x as u32, point.y as u32) + && !self.image.get(point.x as u32, point.y as u32) } { x += 1; length += 1; From 8eaabb1c90750774bb338512cb8df2d734d362cd Mon Sep 17 00:00:00 2001 From: Olssdani Date: Tue, 21 Mar 2023 14:29:07 +0100 Subject: [PATCH 2/2] Change condition since we went out of bound --- src/common/bit_matrix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index 5232b2a..7bd401e 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -255,7 +255,7 @@ impl BitMatrix { /// Confusingly returns true if the requested element is out of bounds pub fn check_in_bounds(&self, x: u32, y: u32) -> bool { - (self.get_offset(y, x)) > self.bits.len() + (self.get_offset(y, x)) >= self.bits.len() } /**