Issue 1434 more sanity checks for RSS expanded

git-svn-id: https://zxing.googlecode.com/svn/trunk@2512 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-11-12 18:50:25 +00:00
parent b22642a0b0
commit f3065f1210

View file

@ -545,6 +545,12 @@ public final class RSSExpandedReader extends AbstractRSSReader {
int numModules = 17; //left and right data characters have all the same length int numModules = 17; //left and right data characters have all the same length
float elementWidth = (float) count(counters) / (float) numModules; 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[] oddCounts = this.getOddCounts();
int[] evenCounts = this.getEvenCounts(); int[] evenCounts = this.getEvenCounts();
float[] oddRoundingErrors = this.getOddRoundingErrors(); float[] oddRoundingErrors = this.getOddRoundingErrors();
@ -554,8 +560,14 @@ public final class RSSExpandedReader extends AbstractRSSReader {
float value = 1.0f * counters[i] / elementWidth; float value = 1.0f * counters[i] / elementWidth;
int count = (int) (value + 0.5f); // Round int count = (int) (value + 0.5f); // Round
if (count < 1) { if (count < 1) {
if (value < 0.3f) {
throw NotFoundException.getNotFoundInstance();
}
count = 1; count = 1;
} else if (count > 8) { } else if (count > 8) {
if (value > 8.7f) {
throw NotFoundException.getNotFoundInstance();
}
count = 8; count = 8;
} }
int offset = i >> 1; int offset = i >> 1;