diff --git a/core/src/com/google/zxing/qrcode/decoder/DataBlock.java b/core/src/com/google/zxing/qrcode/decoder/DataBlock.java index a51761179..a08b5683e 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 917a7ff17..16bfb62a9 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?