From fd69d1c349c5d03fcbd27cfc859f99f70db623fd Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 4 Mar 2010 21:15:39 +0000 Subject: [PATCH] Prevent an array out of bounds exception I noticed in the web logs git-svn-id: http://zxing.googlecode.com/svn/trunk@1238 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../google/zxing/pdf417/decoder/BitMatrixParser.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java b/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java index 03c12ac6..7821483a 100644 --- a/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java @@ -16,6 +16,7 @@ package com.google.zxing.pdf417.decoder; +import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; @@ -58,7 +59,7 @@ final class BitMatrixParser { * * @return an array of codewords. */ - int[] readCodewords() { + int[] readCodewords() throws FormatException { int width = bitMatrix.getDimension(); // TODO should be a rectangular matrix int height = width; @@ -183,11 +184,16 @@ final class BitMatrixParser { * @return the next available index into the codeword array after processing * this row. */ - int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) { + int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) + throws FormatException { int width = bitMatrix.getDimension(); int columnNumber = 0; long symbol = 0; for (int i = 0; i < width; i += MODULES_IN_SYMBOL) { + // This happens in real life and is almost surely a rare misdecode + if (i + MODULES_IN_SYMBOL > rowCounters.length) { + throw FormatException.getFormatInstance(); + } for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) { if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) { symbol |= 1L << mask; -- 2.20.1