]> git.ipfire.org Git - thirdparty/grub.git/commit
font: Fix size overflow in grub_font_get_glyph_internal()
authorZhang Boyang <zhangboyang.id@gmail.com>
Thu, 4 Aug 2022 16:51:20 +0000 (00:51 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 14 Nov 2022 19:24:39 +0000 (20:24 +0100)
commit9c76ec09ae08155df27cd237eaea150b4f02f532
tree00b4a6510aad592822ef3619808c7e0d5ea6b5c3
parentf6b6236077f059e64ee315f2d7acb8fa4eda87c5
font: Fix size overflow in grub_font_get_glyph_internal()

The length of memory allocation and file read may overflow. This patch
fixes the problem by using safemath macros.

There is a lot of code repetition like "(x * y + 7) / 8". It is unsafe
if overflow happens. This patch introduces grub_video_bitmap_calc_1bpp_bufsz().
It is safe replacement for such code. It has safemath-like prototype.

This patch also introduces grub_cast(value, pointer), it casts value to
typeof(*pointer) then store the value to *pointer. It returns true when
overflow occurs or false if there is no overflow. The semantics of arguments
and return value are designed to be consistent with other safemath macros.

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