Issue 524
[zxing.git] / cpp / core / src / zxing / qrcode / detector / Detector.cpp
index bba077f..fdab429 100644 (file)
@@ -53,6 +53,9 @@ Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
   Ref<FinderPattern> bottomLeft(info->getBottomLeft());\r
 \r
   float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);\r
+  if (moduleSize < 1.0f) {\r
+    throw zxing::ReaderException("bad module size");\r
+  }\r
   int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);\r
   Version *provisionalVersion = Version::getProvisionalVersionForDimension(dimension);\r
   int modulesBetweenFPCenters = provisionalVersion->getDimensionForVersion() - 7;\r
@@ -270,6 +273,9 @@ Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize
   }\r
   int alignmentAreaTopY = max(0, estAlignmentY - allowance);\r
   int alignmentAreaBottomY = min((int)(image_->getHeight() - 1), estAlignmentY + allowance);\r
+  if (alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize * 3) {\r
+      throw zxing::ReaderException("region too small to hold alignment pattern");\r
+  }\r
 \r
   AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX\r
                                          - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);\r