Ignore additional PDF417 barcode rows

Some barcode generators (e.g. Okapi) seem to generate additional barcode
rows at the end of the barcode, which can be decoded as valid barcode
rows, but actually contain garbage. The barcode metadata states that
these additional rows are not part of the barcode. So we ignore those
addional rows when parsing the barcode. This could potentially also
happen (though quite unlikely) if data after the barcode looks like a
barcode row.
This commit is contained in:
Guenther Grau 2015-09-01 13:54:03 +02:00
parent 585667bc31
commit 825a31e4b5
5 changed files with 7 additions and 4 deletions

View file

@ -122,7 +122,8 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
if (codeword != null) {
int rowNumber = codeword.getRowNumber();
if (rowNumber >= result.length) {
throw FormatException.getFormatInstance();
// We have more rows than the barcode metadata allows for, ignore them.
continue;
}
result[rowNumber]++;
} // else throw exception?

View file

@ -343,7 +343,8 @@ public final class PDF417ScanningDecoder {
int rowNumber = codeword.getRowNumber();
if (rowNumber >= 0) {
if (rowNumber >= barcodeMatrix.length) {
throw FormatException.getFormatInstance();
// We have more rows than the barcode metadata allows for, ignore them.
continue;
}
barcodeMatrix[rowNumber][column].setValue(codeword.getValue());
}

View file

@ -29,8 +29,8 @@ public final class PDF417BlackBox1TestCase extends AbstractBlackBoxTestCase {
public PDF417BlackBox1TestCase() {
super("src/test/resources/blackbox/pdf417-1", new MultiFormatReader(), BarcodeFormat.PDF_417);
addTest(9, 9, 0.0f);
addTest(9, 9, 180.0f);
addTest(10, 10, 0.0f);
addTest(10, 10, 180.0f);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1 @@
This is just a test.