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();