Skip to content

Commit

Permalink
Remove redundant bounds check for lookup in BIG5 conversion table
Browse files Browse the repository at this point in the history
For CP950 conversion, the bounds check is needed before doing a lookup
in big5_ucs_table, since the first byte of a CP950 multibyte
character can be up to 0xFE. For BIG5, we only accept 1st bytes up
to 0xF9, and it is not possible for the lookup to go out of bounds.
  • Loading branch information
alexdowad committed Jan 4, 2023
1 parent 74319de commit b15d0a9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/mbstring/libmbfl/filters/mbfilter_big5.c
Expand Up @@ -400,8 +400,9 @@ static size_t mb_big5_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf
unsigned char c2 = *p++;

if ((c2 >= 0x40 && c2 <= 0x7E) || (c2 >= 0xA1 && c2 <= 0xFE)) {
unsigned int w = ((c - 0xA1)*157) + c2 - ((c2 <= 0x7E) ? 0x40 : 0xA1 - 0x3F);
w = (w < big5_ucs_table_size) ? big5_ucs_table[w] : 0;
unsigned int w = (c - 0xA1)*157 + c2 - ((c2 <= 0x7E) ? 0x40 : 0xA1 - 0x3F);
ZEND_ASSERT(w < big5_ucs_table_size);
w = big5_ucs_table[w];
if (!w)
w = MBFL_BAD_INPUT;
*out++ = w;
Expand Down

0 comments on commit b15d0a9

Please sign in to comment.