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,28 +326,32 @@ 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) {
continue;
}
for (Codeword codeword : detectionResultColumn.getCodewords()) { for (Codeword codeword : detectionResultColumn.getCodewords()) {
if (codeword == null || codeword.getRowNumber() == -1) { if (codeword != null) {
continue; int rowNumber = codeword.getRowNumber();
if (rowNumber >= 0) {
if (rowNumber >= barcodeMatrix.length) {
throw FormatException.getFormatInstance();
} }
barcodeMatrix[codeword.getRowNumber()][column].setValue(codeword.getValue()); barcodeMatrix[rowNumber][column].setValue(codeword.getValue());
} }
} }
}
}
column++;
}
return barcodeMatrix; return barcodeMatrix;
} }