mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Avoid some rare IllegalArgumentException and ArrayIndexOutOfBoundsException on bad input
git-svn-id: https://zxing.googlecode.com/svn/trunk@2184 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
de25d10e9d
commit
0cf9ec342f
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -97,9 +99,9 @@ public enum CharacterSetECI {
|
|||
* unsupported
|
||||
* @throws IllegalArgumentException if ECI value is invalid
|
||||
*/
|
||||
public static CharacterSetECI getCharacterSetECIByValue(int value) {
|
||||
public static CharacterSetECI getCharacterSetECIByValue(int value) throws FormatException {
|
||||
if (value < 0 || value >= 900) {
|
||||
throw new IllegalArgumentException("Bad ECI value: " + value);
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
return VALUE_TO_ECI.get(value);
|
||||
}
|
||||
|
|
|
@ -248,6 +248,9 @@ final class DecodedBitStreamParser {
|
|||
// Read two characters at a time
|
||||
int start = result.length();
|
||||
while (count > 1) {
|
||||
if (bits.available() < 11) {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
int nextTwoCharsBits = bits.readBits(11);
|
||||
result.append(toAlphaNumericChar(nextTwoCharsBits / 45));
|
||||
result.append(toAlphaNumericChar(nextTwoCharsBits % 45));
|
||||
|
@ -316,7 +319,7 @@ final class DecodedBitStreamParser {
|
|||
}
|
||||
}
|
||||
|
||||
private static int parseECIValue(BitSource bits) {
|
||||
private static int parseECIValue(BitSource bits) throws FormatException {
|
||||
int firstByte = bits.readBits(8);
|
||||
if ((firstByte & 0x80) == 0) {
|
||||
// just one byte
|
||||
|
@ -332,7 +335,7 @@ final class DecodedBitStreamParser {
|
|||
int secondThirdBytes = bits.readBits(16);
|
||||
return ((firstByte & 0x1F) << 16) | secondThirdBytes;
|
||||
}
|
||||
throw new IllegalArgumentException("Bad ECI bits starting with byte " + firstByte);
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue