mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Fixed a few crashes and added a FIXME for another which needs some refactoring.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1814 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
e04e3ef2c1
commit
127839b2b7
|
@ -38,6 +38,7 @@ final class DecodeHandler extends Handler {
|
||||||
|
|
||||||
private final CaptureActivity activity;
|
private final CaptureActivity activity;
|
||||||
private final MultiFormatReader multiFormatReader;
|
private final MultiFormatReader multiFormatReader;
|
||||||
|
private boolean running = true;
|
||||||
|
|
||||||
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
|
DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
|
||||||
multiFormatReader = new MultiFormatReader();
|
multiFormatReader = new MultiFormatReader();
|
||||||
|
@ -47,11 +48,15 @@ final class DecodeHandler extends Handler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
|
if (!running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case R.id.decode:
|
case R.id.decode:
|
||||||
decode((byte[]) message.obj, message.arg1, message.arg2);
|
decode((byte[]) message.obj, message.arg1, message.arg2);
|
||||||
break;
|
break;
|
||||||
case R.id.quit:
|
case R.id.quit:
|
||||||
|
running = false;
|
||||||
Looper.myLooper().quit();
|
Looper.myLooper().quit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,6 +446,12 @@ final class DecodedBitStreamParser {
|
||||||
} else {
|
} else {
|
||||||
count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
|
count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We're seeing NegativeArraySizeException errors from users.
|
||||||
|
if (count < 0) {
|
||||||
|
throw FormatException.getFormatInstance();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] bytes = new byte[count];
|
byte[] bytes = new byte[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
// Have seen this particular error in the wild, such as at
|
// Have seen this particular error in the wild, such as at
|
||||||
|
|
|
@ -126,6 +126,11 @@ final class DecodedBitStreamParser {
|
||||||
private static void decodeHanziSegment(BitSource bits,
|
private static void decodeHanziSegment(BitSource bits,
|
||||||
StringBuffer result,
|
StringBuffer result,
|
||||||
int count) throws FormatException {
|
int count) throws FormatException {
|
||||||
|
// Don't crash trying to read more bits than we have available.
|
||||||
|
if (count * 13 > bits.available()) {
|
||||||
|
throw FormatException.getFormatInstance();
|
||||||
|
}
|
||||||
|
|
||||||
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
||||||
// and decode as GB2312 afterwards
|
// and decode as GB2312 afterwards
|
||||||
byte[] buffer = new byte[2 * count];
|
byte[] buffer = new byte[2 * count];
|
||||||
|
@ -157,6 +162,11 @@ final class DecodedBitStreamParser {
|
||||||
private static void decodeKanjiSegment(BitSource bits,
|
private static void decodeKanjiSegment(BitSource bits,
|
||||||
StringBuffer result,
|
StringBuffer result,
|
||||||
int count) throws FormatException {
|
int count) throws FormatException {
|
||||||
|
// Don't crash trying to read more bits than we have available.
|
||||||
|
if (count * 13 > bits.available()) {
|
||||||
|
throw FormatException.getFormatInstance();
|
||||||
|
}
|
||||||
|
|
||||||
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
||||||
// and decode as Shift_JIS afterwards
|
// and decode as Shift_JIS afterwards
|
||||||
byte[] buffer = new byte[2 * count];
|
byte[] buffer = new byte[2 * count];
|
||||||
|
@ -191,10 +201,12 @@ final class DecodedBitStreamParser {
|
||||||
CharacterSetECI currentCharacterSetECI,
|
CharacterSetECI currentCharacterSetECI,
|
||||||
Vector byteSegments,
|
Vector byteSegments,
|
||||||
Hashtable hints) throws FormatException {
|
Hashtable hints) throws FormatException {
|
||||||
byte[] readBytes = new byte[count];
|
// Don't crash trying to read more bits than we have available.
|
||||||
if (count << 3 > bits.available()) {
|
if (count << 3 > bits.available()) {
|
||||||
throw FormatException.getFormatInstance();
|
throw FormatException.getFormatInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] readBytes = new byte[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
readBytes[i] = (byte) bits.readBits(8);
|
readBytes[i] = (byte) bits.readBits(8);
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,14 +308,19 @@ public class Detector {
|
||||||
int dx = Math.abs(toX - fromX);
|
int dx = Math.abs(toX - fromX);
|
||||||
int dy = Math.abs(toY - fromY);
|
int dy = Math.abs(toY - fromY);
|
||||||
int error = -dx >> 1;
|
int error = -dx >> 1;
|
||||||
int ystep = fromY < toY ? 1 : -1;
|
|
||||||
int xstep = fromX < toX ? 1 : -1;
|
int xstep = fromX < toX ? 1 : -1;
|
||||||
int state = 0; // In black pixels, looking for white, first or second time
|
int ystep = fromY < toY ? 1 : -1;
|
||||||
for (int x = fromX, y = fromY; x != toX; x += xstep) {
|
|
||||||
|
|
||||||
|
// In black pixels, looking for white, first or second time.
|
||||||
|
int state = 0;
|
||||||
|
for (int x = fromX, y = fromY; x != toX; x += xstep) {
|
||||||
int realX = steep ? y : x;
|
int realX = steep ? y : x;
|
||||||
int realY = steep ? x : y;
|
int realY = steep ? x : y;
|
||||||
if (state == 1) { // In white pixels, looking for black
|
|
||||||
|
// In white pixels, looking for black.
|
||||||
|
// FIXME(dswitkin): This method seems to assume square images, which can cause these calls to
|
||||||
|
// BitMatrix.get() to throw ArrayIndexOutOfBoundsException.
|
||||||
|
if (state == 1) {
|
||||||
if (image.get(realX, realY)) {
|
if (image.get(realX, realY)) {
|
||||||
state++;
|
state++;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +330,8 @@ public class Detector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == 3) { // Found black, white, black, and stumbled back onto white; done
|
// Found black, white, black, and stumbled back onto white, so we're done.
|
||||||
|
if (state == 3) {
|
||||||
int diffX = x - fromX;
|
int diffX = x - fromX;
|
||||||
int diffY = y - fromY;
|
int diffY = y - fromY;
|
||||||
if (xstep < 0) {
|
if (xstep < 0) {
|
||||||
|
|
Loading…
Reference in a new issue