mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Possible fix for https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=37905
This commit is contained in:
parent
f6087eea12
commit
490769e75f
|
@ -42,12 +42,14 @@ final class State {
|
|||
private final int binaryShiftByteCount;
|
||||
// The total number of bits generated (including Binary Shift).
|
||||
private final int bitCount;
|
||||
private final int binaryShiftCost;
|
||||
|
||||
private State(Token token, int mode, int binaryBytes, int bitCount) {
|
||||
this.token = token;
|
||||
this.mode = mode;
|
||||
this.binaryShiftByteCount = binaryBytes;
|
||||
this.bitCount = bitCount;
|
||||
this.binaryShiftCost = calculateBinaryShiftCost(binaryBytes);
|
||||
}
|
||||
|
||||
int getMode() {
|
||||
|
@ -155,7 +157,7 @@ final class State {
|
|||
int newModeBitCount = this.bitCount + (HighLevelEncoder.LATCH_TABLE[this.mode][other.mode] >> 16);
|
||||
if (this.binaryShiftByteCount < other.binaryShiftByteCount) {
|
||||
// add additional B/S encoding cost of other, if any
|
||||
newModeBitCount += calculateBinaryShiftCost(other) - calculateBinaryShiftCost(this);
|
||||
newModeBitCount += other.binaryShiftCost - this.binaryShiftCost;
|
||||
} else if (this.binaryShiftByteCount > other.binaryShiftByteCount && other.binaryShiftByteCount > 0) {
|
||||
// maximum possible additional cost (we end up exceeding the 31 byte boundary and other state can stay beneath it)
|
||||
newModeBitCount += 10;
|
||||
|
@ -184,14 +186,14 @@ final class State {
|
|||
return String.format("%s bits=%d bytes=%d", HighLevelEncoder.MODE_NAMES[mode], bitCount, binaryShiftByteCount);
|
||||
}
|
||||
|
||||
private static int calculateBinaryShiftCost(State state) {
|
||||
if (state.binaryShiftByteCount > 62) {
|
||||
private static int calculateBinaryShiftCost(int binaryShiftByteCount) {
|
||||
if (binaryShiftByteCount > 62) {
|
||||
return 21; // B/S with extended length
|
||||
}
|
||||
if (state.binaryShiftByteCount > 31) {
|
||||
if (binaryShiftByteCount > 31) {
|
||||
return 20; // two B/S
|
||||
}
|
||||
if (state.binaryShiftByteCount > 0) {
|
||||
if (binaryShiftByteCount > 0) {
|
||||
return 10; // one B/S
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue