From 32331c070819a9f686a2c0a3b25c8c112b336ed3 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Fri, 16 Jul 2021 11:47:49 -0500 Subject: [PATCH] Fix possible AIOOBE from fuzz test --- .../java/com/google/zxing/aztec/detector/Detector.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/zxing/aztec/detector/Detector.java b/core/src/main/java/com/google/zxing/aztec/detector/Detector.java index ef964ee09..16a623d82 100644 --- a/core/src/main/java/com/google/zxing/aztec/detector/Detector.java +++ b/core/src/main/java/com/google/zxing/aztec/detector/Detector.java @@ -425,10 +425,12 @@ public final class Detector { int corr = 3; - p1 = new Point(p1.getX() - corr, p1.getY() + corr); - p2 = new Point(p2.getX() - corr, p2.getY() - corr); - p3 = new Point(p3.getX() + corr, p3.getY() - corr); - p4 = new Point(p4.getX() + corr, p4.getY() + corr); + p1 = new Point(Math.max(0, p1.getX() - corr), Math.min(image.getHeight() - 1, p1.getY() + corr)); + p2 = new Point(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr)); + p3 = new Point(Math.min(image.getWidth() - 1, p3.getX() + corr), + Math.max(0, Math.min(image.getHeight() - 1, p3.getY() - corr))); + p4 = new Point(Math.min(image.getWidth() - 1, p4.getX() + corr), + Math.min(image.getHeight() - 1, p4.getY() + corr)); int cInit = getColor(p4, p1);