Skip to content

Commit

Permalink
qrdectxt: Fix Big5 pre-validation
Browse files Browse the repository at this point in the history
Correct the range checking to evaluate both bytes together.

The ranges are from the table at https://en.wikipedia.org/wiki/Big5

References mchehab#281

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Aug 23, 2024
1 parent a549566 commit 256df63
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions zbar/qrcode/qrdectxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ static int text_is_big5(const unsigned char *_text, int _len)
for (i = 0; i < _len; i++) {
if (_text[i] == 0xFF)
return 0;
else if (_text[i] >= 0x80) { // first byte is big5
i++;
if (i >= _len) // second byte not exists
else if (_text[i] >= 0x81) { // possible Big5 start byte
int w = _text[i] << 8;
if (++i == _len) // second byte does not exist
return 0;
if (_text[i] < 0x40 || (_text[i] > 0x7E && _text[i] < 0xA1) ||
_text[i] > 0xFE) { // second byte not in range
return 0;
}
w |= _text[i];
/* non user-defined ranges */
if ((w >= 0xA140 && w <= 0xA3BF) ||
(w >= 0xA3C0 && w <= 0xA3FE) ||
(w >= 0xA440 && w <= 0xC67E) ||
(w >= 0xC940 && w <= 0xF9D5))
continue;
/* user-defined ranges */
if ((w >= 0x8140 && w <= 0xA0FE) ||
(w >= 0xC6A1 && w <= 0xC8FE) ||
(w >= 0xF9D6 && w <= 0xFEFE))
continue;
return 0;
} else { // normal ascii encoding, it's okay
}
}
Expand Down

0 comments on commit 256df63

Please sign in to comment.