From: srowen Date: Sun, 21 Dec 2008 18:40:41 +0000 (+0000) Subject: Correct exception handling in certain situations so that routine decoding failures... X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=7a1eb945b6aa45fa359ca438302757b10a9457e9;hp=761bb857ad87c7010e4791591c4b08ed60515257;p=zxing.git Correct exception handling in certain situations so that routine decoding failures do not produce IllegalArgumentException git-svn-id: http://zxing.googlecode.com/svn/trunk@799 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/qrcode/decoder/DataBlock.java b/core/src/com/google/zxing/qrcode/decoder/DataBlock.java index a5176117..a08b5683 100755 --- a/core/src/com/google/zxing/qrcode/decoder/DataBlock.java +++ b/core/src/com/google/zxing/qrcode/decoder/DataBlock.java @@ -34,7 +34,7 @@ final class DataBlock { } /** - *

When QR Codes use multiple data blocks, they are actually interleave the bytes of each of them. + *

When QR Codes use multiple data blocks, they are actually interleaved. * That is, the first byte of data block 1 to n is written, then the second bytes, and so on. This * method will separate the data into original blocks.

* @@ -47,6 +47,11 @@ final class DataBlock { static DataBlock[] getDataBlocks(byte[] rawCodewords, Version version, ErrorCorrectionLevel ecLevel) { + + if (rawCodewords.length != version.getTotalCodewords()) { + throw new IllegalArgumentException(); + } + // Figure out the number and size of data blocks used by this version and // error correction level Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); @@ -79,9 +84,6 @@ final class DataBlock { if (numCodewords == shorterBlocksTotalCodewords) { break; } - if (numCodewords != shorterBlocksTotalCodewords + 1) { - throw new IllegalArgumentException("Data block sizes differ by more than 1"); - } longerBlocksStartAt--; } longerBlocksStartAt++; @@ -107,11 +109,6 @@ final class DataBlock { result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++]; } } - - if (rawCodewordsOffset != rawCodewords.length) { - throw new IllegalArgumentException(); - } - return result; } diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index 917a7ff1..16bfb62a 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -70,7 +70,11 @@ final class DecodedBitStreamParser { // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here mode = Mode.TERMINATOR; } else { - mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits + try { + mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits + } catch (IllegalArgumentException iae) { + throw ReaderException.getInstance(); + } } if (!mode.equals(Mode.TERMINATOR)) { if (mode.equals(Mode.FNC1_FIRST_POSITION) || mode.equals(Mode.FNC1_SECOND_POSITION)) { @@ -78,11 +82,11 @@ final class DecodedBitStreamParser { fc1InEffect = true; } else if (mode.equals(Mode.ECI)) { // Count doesn't apply to ECI - int value = parseECIValue(bits); try { + int value = parseECIValue(bits); currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value); } catch (IllegalArgumentException iae) { - // unsupported... just continue? + throw ReaderException.getInstance(); } } else { // How many characters will follow, encoded in this mode?