From 10065f8c1c8e989c2f041852adaf7d3c7dcabd95 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 28 Jun 2011 06:50:37 +0000 Subject: [PATCH] Avoid AIOOBE for corrupt codes git-svn-id: https://zxing.googlecode.com/svn/trunk@1837 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/qrcode/decoder/DecodedBitStreamParser.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index ff374ac50..b5df4831a 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -275,6 +275,9 @@ final class DecodedBitStreamParser { // Read three digits at a time while (count >= 3) { // Each 10 bits encodes three digits + if (bits.available() < 10) { + throw FormatException.getFormatInstance(); + } int threeDigitsBits = bits.readBits(10); if (threeDigitsBits >= 1000) { throw FormatException.getFormatInstance(); @@ -286,6 +289,9 @@ final class DecodedBitStreamParser { } if (count == 2) { // Two digits left over to read, encoded in 7 bits + if (bits.available() < 7) { + throw FormatException.getFormatInstance(); + } int twoDigitsBits = bits.readBits(7); if (twoDigitsBits >= 100) { throw FormatException.getFormatInstance(); @@ -294,6 +300,9 @@ final class DecodedBitStreamParser { result.append(toAlphaNumericChar(twoDigitsBits % 10)); } else if (count == 1) { // One digit left over to read + if (bits.available() < 4) { + throw FormatException.getFormatInstance(); + } int digitBits = bits.readBits(4); if (digitBits >= 10) { throw FormatException.getFormatInstance();