Issue #147 : handle corner case as normal failed read rather than AIOOBE

This commit is contained in:
Sean Owen 2014-05-15 13:26:04 +01:00
parent 2a8cd871bc
commit 77aabfc457

View file

@ -326,27 +326,31 @@ public final class PDF417ScanningDecoder {
throw ChecksumException.getChecksumInstance(); throw ChecksumException.getChecksumInstance();
} }
private static BarcodeValue[][] createBarcodeMatrix(DetectionResult detectionResult) { private static BarcodeValue[][] createBarcodeMatrix(DetectionResult detectionResult) throws FormatException {
BarcodeValue[][] barcodeMatrix = new BarcodeValue[detectionResult.getBarcodeRowCount()][detectionResult BarcodeValue[][] barcodeMatrix =
.getBarcodeColumnCount() + 2]; new BarcodeValue[detectionResult.getBarcodeRowCount()][detectionResult.getBarcodeColumnCount() + 2];
for (int row = 0; row < barcodeMatrix.length; row++) { for (int row = 0; row < barcodeMatrix.length; row++) {
for (int column = 0; column < barcodeMatrix[row].length; column++) { for (int column = 0; column < barcodeMatrix[row].length; column++) {
barcodeMatrix[row][column] = new BarcodeValue(); barcodeMatrix[row][column] = new BarcodeValue();
} }
} }
int column = -1; int column = 0;
for (DetectionResultColumn detectionResultColumn : detectionResult.getDetectionResultColumns()) { for (DetectionResultColumn detectionResultColumn : detectionResult.getDetectionResultColumns()) {
column++; if (detectionResultColumn != null) {
if (detectionResultColumn == null) { for (Codeword codeword : detectionResultColumn.getCodewords()) {
continue; if (codeword != null) {
} int rowNumber = codeword.getRowNumber();
for (Codeword codeword : detectionResultColumn.getCodewords()) { if (rowNumber >= 0) {
if (codeword == null || codeword.getRowNumber() == -1) { if (rowNumber >= barcodeMatrix.length) {
continue; throw FormatException.getFormatInstance();
}
barcodeMatrix[rowNumber][column].setValue(codeword.getValue());
}
}
} }
barcodeMatrix[codeword.getRowNumber()][column].setValue(codeword.getValue());
} }
column++;
} }
return barcodeMatrix; return barcodeMatrix;
} }