Issue #67 : Avoid rare AIOOBE on PDF417 misread

This commit is contained in:
Sean Owen 2014-02-21 08:10:42 +00:00
parent bd4536f077
commit 1b898320ac
2 changed files with 10 additions and 5 deletions

View file

@ -16,6 +16,7 @@
package com.google.zxing.pdf417.decoder; package com.google.zxing.pdf417.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
import com.google.zxing.pdf417.PDF417Common; import com.google.zxing.pdf417.PDF417Common;
@ -110,7 +111,7 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
return (int) (averageRowHeight + 0.5); return (int) (averageRowHeight + 0.5);
} }
int[] getRowHeights() { int[] getRowHeights() throws FormatException {
BarcodeMetadata barcodeMetadata = getBarcodeMetadata(); BarcodeMetadata barcodeMetadata = getBarcodeMetadata();
if (barcodeMetadata == null) { if (barcodeMetadata == null) {
return null; return null;
@ -119,8 +120,12 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
int[] result = new int[barcodeMetadata.getRowCount()]; int[] result = new int[barcodeMetadata.getRowCount()];
for (Codeword codeword : getCodewords()) { for (Codeword codeword : getCodewords()) {
if (codeword != null) { if (codeword != null) {
result[codeword.getRowNumber()]++; int rowNumber = codeword.getRowNumber();
} if (rowNumber >= result.length) {
throw FormatException.getFormatInstance();
}
result[rowNumber]++;
} // else throw exception?
} }
return result; return result;
} }

View file

@ -125,7 +125,7 @@ public final class PDF417ScanningDecoder {
private static DetectionResult merge(DetectionResultRowIndicatorColumn leftRowIndicatorColumn, private static DetectionResult merge(DetectionResultRowIndicatorColumn leftRowIndicatorColumn,
DetectionResultRowIndicatorColumn rightRowIndicatorColumn) DetectionResultRowIndicatorColumn rightRowIndicatorColumn)
throws NotFoundException { throws NotFoundException, FormatException {
if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) { if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) {
return null; return null;
} }
@ -139,7 +139,7 @@ public final class PDF417ScanningDecoder {
} }
private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn rowIndicatorColumn) private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn rowIndicatorColumn)
throws NotFoundException { throws NotFoundException, FormatException {
if (rowIndicatorColumn == null) { if (rowIndicatorColumn == null) {
return null; return null;
} }