From 3b4a8bcd52ead1c3b21a802860ae5c32316b43e6 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Fri, 17 Feb 2012 21:05:44 +0000 Subject: [PATCH] port r2064 to C++ git-svn-id: https://zxing.googlecode.com/svn/trunk@2203 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/common/CharacterSetECI.cpp | 6 ++---- .../src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp/core/src/zxing/common/CharacterSetECI.cpp b/cpp/core/src/zxing/common/CharacterSetECI.cpp index 80603c6cb..8386208b5 100644 --- a/cpp/core/src/zxing/common/CharacterSetECI.cpp +++ b/cpp/core/src/zxing/common/CharacterSetECI.cpp @@ -16,8 +16,8 @@ */ #include -#include #include +#include using std::string; @@ -94,9 +94,7 @@ void CharacterSetECI::addCharacterSet(int const* values, char const* const* name CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) { if (value < 0 || value >= 900) { - std::ostringstream oss; - oss << "Bad ECI value: " << value; - throw IllegalArgumentException(oss.str().c_str()); + throw FormatException(); } return VALUE_TO_ECI[value]; } diff --git a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp index 1a208e61d..83ef51239 100644 --- a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp +++ b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp @@ -275,6 +275,9 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, ostringstream bytes; // Read two characters at a time while (count > 1) { + if (bits.available() < 11) { + throw FormatException(); + } int nextTwoCharsBits = bits.readBits(11); bytes << toAlphaNumericChar(nextTwoCharsBits / 45); bytes << toAlphaNumericChar(nextTwoCharsBits % 45); @@ -324,7 +327,7 @@ namespace { int secondThirdBytes = bits.readBits(16); return ((firstByte & 0x1F) << 16) | secondThirdBytes; } - throw IllegalArgumentException("Bad ECI bits starting with byte " + firstByte); + throw FormatException(); } }