Issue 509
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 12 Aug 2010 20:54:54 +0000 (20:54 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 12 Aug 2010 20:54:54 +0000 (20:54 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1525 59b500cc-1b3d-0410-9834-0bbf25fbcc57

cpp/core/src/zxing/qrcode/decoder/BitMatrixParser.cpp
cpp/core/src/zxing/qrcode/detector/Detector.cpp

index 04cd06b..3e3a5ff 100644 (file)
@@ -84,7 +84,7 @@ Version *BitMatrixParser::readVersion() {
     return parsedVersion_;
   }
 
     return parsedVersion_;
   }
 
-  size_t dimension = bitMatrix_->getDimension();
+  int dimension = bitMatrix_->getDimension();
 
   int provisionalVersion = (dimension - 17) >> 2;
   if (provisionalVersion <= 6) {
 
   int provisionalVersion = (dimension - 17) >> 2;
   if (provisionalVersion <= 6) {
@@ -101,7 +101,7 @@ Version *BitMatrixParser::readVersion() {
   }
 
   parsedVersion_ = Version::decodeVersionInformation(versionBits);
   }
 
   parsedVersion_ = Version::decodeVersionInformation(versionBits);
-  if (parsedVersion_ != 0) {
+  if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) {
     return parsedVersion_;
   }
 
     return parsedVersion_;
   }
 
@@ -115,7 +115,7 @@ Version *BitMatrixParser::readVersion() {
   }
 
   parsedVersion_ = Version::decodeVersionInformation(versionBits);
   }
 
   parsedVersion_ = Version::decodeVersionInformation(versionBits);
-  if (parsedVersion_ != 0) {
+  if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) {
     return parsedVersion_;
   }
   throw ReaderException("Could not decode version");
     return parsedVersion_;
   }
   throw ReaderException("Could not decode version");
index bba077f..4e40b72 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
   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
   int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);\r
   Version *provisionalVersion = Version::getProvisionalVersionForDimension(dimension);\r
   int modulesBetweenFPCenters = provisionalVersion->getDimensionForVersion() - 7;\r