From a582958cc30ac60af8eb894aa1d0c12798a29b2e Mon Sep 17 00:00:00 2001 From: "srowen@gmail.com" Date: Mon, 19 Aug 2013 10:24:59 +0000 Subject: [PATCH] Issue 1736 reject UPC/EAN less than 8 chars git-svn-id: https://zxing.googlecode.com/svn/trunk@2871 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- core/src/com/google/zxing/oned/UPCEANReader.java | 4 ++++ cpp/core/src/zxing/oned/UPCEANReader.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/core/src/com/google/zxing/oned/UPCEANReader.java b/core/src/com/google/zxing/oned/UPCEANReader.java index cb486c258..91afbe36d 100644 --- a/core/src/com/google/zxing/oned/UPCEANReader.java +++ b/core/src/com/google/zxing/oned/UPCEANReader.java @@ -176,6 +176,10 @@ public abstract class UPCEANReader extends OneDReader { } String resultString = result.toString(); + // UPC/EAN should never be less than 8 chars anyway + if (resultString.length() < 8) { + throw FormatException.getFormatInstance(); + } if (!checkChecksum(resultString)) { throw ChecksumException.getChecksumInstance(); } diff --git a/cpp/core/src/zxing/oned/UPCEANReader.cpp b/cpp/core/src/zxing/oned/UPCEANReader.cpp index e76aa755e..1643531c1 100644 --- a/cpp/core/src/zxing/oned/UPCEANReader.cpp +++ b/cpp/core/src/zxing/oned/UPCEANReader.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include using std::vector; @@ -31,6 +32,7 @@ using std::string; using zxing::Ref; using zxing::Result; using zxing::NotFoundException; +using zxing::FormatException; using zxing::ChecksumException; using zxing::oned::UPCEANReader; @@ -138,6 +140,11 @@ Ref UPCEANReader::decodeRow(int rowNumber, throw NotFoundException(); } + // UPC/EAN should never be less than 8 chars anyway + if (result.length() < 8) { + throw FormatException(); + } + Ref resultString (new String(result)); if (!checkChecksum(resultString)) { throw ChecksumException();