mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Correct exception handling in certain situations so that routine decoding failures do not produce IllegalArgumentException
git-svn-id: https://zxing.googlecode.com/svn/trunk@799 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
031ceb7e69
commit
fa59c4e093
|
@ -34,7 +34,7 @@ final class DataBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>When QR Codes use multiple data blocks, they are actually interleave the bytes of each of them.
|
* <p>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
|
* 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.</p>
|
* method will separate the data into original blocks.</p>
|
||||||
*
|
*
|
||||||
|
@ -47,6 +47,11 @@ final class DataBlock {
|
||||||
static DataBlock[] getDataBlocks(byte[] rawCodewords,
|
static DataBlock[] getDataBlocks(byte[] rawCodewords,
|
||||||
Version version,
|
Version version,
|
||||||
ErrorCorrectionLevel ecLevel) {
|
ErrorCorrectionLevel ecLevel) {
|
||||||
|
|
||||||
|
if (rawCodewords.length != version.getTotalCodewords()) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out the number and size of data blocks used by this version and
|
// Figure out the number and size of data blocks used by this version and
|
||||||
// error correction level
|
// error correction level
|
||||||
Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
|
Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
|
||||||
|
@ -79,9 +84,6 @@ final class DataBlock {
|
||||||
if (numCodewords == shorterBlocksTotalCodewords) {
|
if (numCodewords == shorterBlocksTotalCodewords) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (numCodewords != shorterBlocksTotalCodewords + 1) {
|
|
||||||
throw new IllegalArgumentException("Data block sizes differ by more than 1");
|
|
||||||
}
|
|
||||||
longerBlocksStartAt--;
|
longerBlocksStartAt--;
|
||||||
}
|
}
|
||||||
longerBlocksStartAt++;
|
longerBlocksStartAt++;
|
||||||
|
@ -107,11 +109,6 @@ final class DataBlock {
|
||||||
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
|
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawCodewordsOffset != rawCodewords.length) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,11 @@ final class DecodedBitStreamParser {
|
||||||
// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
|
// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
|
||||||
mode = Mode.TERMINATOR;
|
mode = Mode.TERMINATOR;
|
||||||
} else {
|
} 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.TERMINATOR)) {
|
||||||
if (mode.equals(Mode.FNC1_FIRST_POSITION) || mode.equals(Mode.FNC1_SECOND_POSITION)) {
|
if (mode.equals(Mode.FNC1_FIRST_POSITION) || mode.equals(Mode.FNC1_SECOND_POSITION)) {
|
||||||
|
@ -78,11 +82,11 @@ final class DecodedBitStreamParser {
|
||||||
fc1InEffect = true;
|
fc1InEffect = true;
|
||||||
} else if (mode.equals(Mode.ECI)) {
|
} else if (mode.equals(Mode.ECI)) {
|
||||||
// Count doesn't apply to ECI
|
// Count doesn't apply to ECI
|
||||||
int value = parseECIValue(bits);
|
|
||||||
try {
|
try {
|
||||||
|
int value = parseECIValue(bits);
|
||||||
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
|
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
// unsupported... just continue?
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// How many characters will follow, encoded in this mode?
|
// How many characters will follow, encoded in this mode?
|
||||||
|
|
Loading…
Reference in a new issue