\r
package com.google.zxing.pdf417.decoder;\r
\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.NotFoundException;\r
import com.google.zxing.common.BitMatrix;\r
\r
*\r
* @return an array of codewords.\r
*/\r
- int[] readCodewords() {\r
+ int[] readCodewords() throws FormatException {\r
int width = bitMatrix.getDimension();\r
// TODO should be a rectangular matrix\r
int height = width;\r
* @return the next available index into the codeword array after processing\r
* this row.\r
*/\r
- int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) {\r
+ int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next)\r
+ throws FormatException {\r
int width = bitMatrix.getDimension();\r
int columnNumber = 0;\r
long symbol = 0;\r
for (int i = 0; i < width; i += MODULES_IN_SYMBOL) {\r
+ // This happens in real life and is almost surely a rare misdecode\r
+ if (i + MODULES_IN_SYMBOL > rowCounters.length) {\r
+ throw FormatException.getFormatInstance();\r
+ }\r
for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) {\r
if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) {\r
symbol |= 1L << mask;\r