From 23fc6b558bad94d06213bfdb360ff08d08de543b Mon Sep 17 00:00:00 2001 From: dswitkin Date: Tue, 14 Oct 2008 18:24:23 +0000 Subject: [PATCH] Added a bit of defensive programming in the AlignmentPattern code. There were real world examples where the width passed to AlignmentPatternFinder was zero, which causes BitArray to throw when built with a size of zero. I'm going a little bit farther and not searching extremely small areas either. Sean, please review. git-svn-id: http://zxing.googlecode.com/svn/trunk@617 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- core/src/com/google/zxing/qrcode/detector/Detector.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 8f06e8d7..574d2d1c 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -334,6 +334,10 @@ public final class Detector { int allowance = (int) (allowanceFactor * overallEstModuleSize); int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance); int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance); + if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) { + throw new ReaderException("Alignment pattern is too small to search"); + } + int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance); int alignmentAreaBottomY = Math.min(image.getHeight() - 1, estAlignmentY + allowance); -- 2.20.1