From f3065f1210066b76fab763877a6e26e82efcb070 Mon Sep 17 00:00:00 2001 From: srowen Date: Mon, 12 Nov 2012 18:50:25 +0000 Subject: [PATCH] Issue 1434 more sanity checks for RSS expanded git-svn-id: https://zxing.googlecode.com/svn/trunk@2512 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/oned/rss/expanded/RSSExpandedReader.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java b/core/src/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java index c9caab009..6937871b0 100644 --- a/core/src/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java +++ b/core/src/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java @@ -545,6 +545,12 @@ public final class RSSExpandedReader extends AbstractRSSReader { int numModules = 17; //left and right data characters have all the same length float elementWidth = (float) count(counters) / (float) numModules; + // Sanity check: element width for pattern and the character should match + float expectedElementWidth = (pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) / 15.0f; + if (Math.abs(elementWidth - expectedElementWidth) / expectedElementWidth > 0.3f) { + throw NotFoundException.getNotFoundInstance(); + } + int[] oddCounts = this.getOddCounts(); int[] evenCounts = this.getEvenCounts(); float[] oddRoundingErrors = this.getOddRoundingErrors(); @@ -554,8 +560,14 @@ public final class RSSExpandedReader extends AbstractRSSReader { float value = 1.0f * counters[i] / elementWidth; int count = (int) (value + 0.5f); // Round if (count < 1) { + if (value < 0.3f) { + throw NotFoundException.getNotFoundInstance(); + } count = 1; } else if (count > 8) { + if (value > 8.7f) { + throw NotFoundException.getNotFoundInstance(); + } count = 8; } int offset = i >> 1;