]> git.ipfire.org Git - thirdparty/grub.git/commit
font: Fix integer overflow in BMP index
authorZhang Boyang <zhangboyang.id@gmail.com>
Sun, 14 Aug 2022 18:04:58 +0000 (02:04 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 14 Nov 2022 19:24:39 +0000 (20:24 +0100)
commitb9396daf1c2e3cdc0a1e69b056852e0769fb24de
treec34e73a0b62496b94e17203425f9d3c4156493c0
parent23843fe8947e4da955a05ad3d1858725bfcb56c8
font: Fix integer overflow in BMP index

The BMP index (font->bmp_idx) is designed as a reverse lookup table of
char entries (font->char_index), in order to speed up lookups for BMP
chars (i.e. code < 0x10000). The values in BMP index are the subscripts
of the corresponding char entries, stored in grub_uint16_t, while 0xffff
means not found.

This patch fixes the problem of large subscript truncated to grub_uint16_t,
leading BMP index to return wrong char entry or report false miss. The
code now checks for bounds and uses BMP index as a hint, and fallbacks
to binary-search if necessary.

On the occasion add a comment about BMP index is initialized to 0xffff.

Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/font/font.c