Skip to content

Commit b15d0a9

Browse files
committed
Remove redundant bounds check for lookup in BIG5 conversion table
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.
1 parent 74319de commit b15d0a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/mbstring/libmbfl/filters/mbfilter_big5.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,9 @@ static size_t mb_big5_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf
400400
unsigned char c2 = *p++;
401401

402402
if ((c2 >= 0x40 && c2 <= 0x7E) || (c2 >= 0xA1 && c2 <= 0xFE)) {
403-
unsigned int w = ((c - 0xA1)*157) + c2 - ((c2 <= 0x7E) ? 0x40 : 0xA1 - 0x3F);
404-
w = (w < big5_ucs_table_size) ? big5_ucs_table[w] : 0;
403+
unsigned int w = (c - 0xA1)*157 + c2 - ((c2 <= 0x7E) ? 0x40 : 0xA1 - 0x3F);
404+
ZEND_ASSERT(w < big5_ucs_table_size);
405+
w = big5_ucs_table[w];
405406
if (!w)
406407
w = MBFL_BAD_INPUT;
407408
*out++ = w;

0 commit comments

Comments
 (0)