mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Handle case where GB2312 isn't supported; don't support Hanzi mode QR codes in this case
This commit is contained in:
parent
6fb399bc91
commit
a6273e3bc7
|
@ -18,6 +18,7 @@ package com.google.zxing.common;
|
|||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.zxing.DecodeHintType;
|
||||
|
@ -32,7 +33,17 @@ public final class StringUtils {
|
|||
|
||||
private static final Charset PLATFORM_DEFAULT_ENCODING = Charset.defaultCharset();
|
||||
public static final Charset SHIFT_JIS_CHARSET = Charset.forName("SJIS");
|
||||
public static final Charset GB2312_CHARSET = Charset.forName("GB2312");
|
||||
public static final Charset GB2312_CHARSET;
|
||||
static {
|
||||
Charset gb2312Charset;
|
||||
try {
|
||||
gb2312Charset = Charset.forName("GB2312");
|
||||
} catch (UnsupportedCharsetException ucee) {
|
||||
// Can happen on some embedded JREs?
|
||||
gb2312Charset = null;
|
||||
}
|
||||
GB2312_CHARSET = gb2312Charset;
|
||||
}
|
||||
private static final Charset EUC_JP = Charset.forName("EUC_JP");
|
||||
private static final boolean ASSUME_SHIFT_JIS =
|
||||
SHIFT_JIS_CHARSET.equals(PLATFORM_DEFAULT_ENCODING) ||
|
||||
|
|
|
@ -175,6 +175,10 @@ final class DecodedBitStreamParser {
|
|||
private static void decodeHanziSegment(BitSource bits,
|
||||
StringBuilder result,
|
||||
int count) throws FormatException {
|
||||
if (StringUtils.GB2312_CHARSET == null) {
|
||||
// Not supported without charset support
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
// Don't crash trying to read more bits than we have available.
|
||||
if (count * 13 > bits.available()) {
|
||||
throw FormatException.getFormatInstance();
|
||||
|
|
Loading…
Reference in a new issue