Blender Git Commit Log

Git Commits -> Revision 8b55cda

Revision 8b55cda by Campbell Barton (master)
August 24, 2021, 04:25 (GMT)
Fix BLI_str_utf8_as_unicode_step reading past intended bounds

Add a string length argument to BLI_str_utf8_as_unicode_step to prevent
reading past the buffer bounds or the intended range since some callers
of this function take a string length to operate on part of the string.

Font drawing for example didn't respect the length argument,
potentially causing a buffer over-read with multi-byte characters
that could read past the end of the string.

The following command would read 5 bytes past the end of the input.

`BLF_draw(font_id, (char[]){252}, 1);`

In practice strings are typically null terminated so this didn't crash
reading past buffer bounds.

Nevertheless, this wasn't correct and could cause bugs in the future.

Clamping by the length now has the same behavior as a null byte.

Add test to ensure this is working as intended.

Commit Details:

Full Hash: 8b55cda04812255922f488ad6bacd228d5d290a6
Parent Commit: 8371df8
Lines Changed: +179, -46

6 Modified Paths:

/source/blender/blenfont/intern/blf_font.c (+12, -12) (Diff)
/source/blender/blenkernel/intern/text.c (+2, -2) (Diff)
/source/blender/blenlib/BLI_string_utf8.h (+4, -2) (Diff)
/source/blender/blenlib/intern/string_utf8.c (+47, -26) (Diff)
/source/blender/blenlib/tests/BLI_string_utf8_test.cc (+110, -1) (Diff)
/source/blender/editors/space_text/text_ops.c (+4, -3) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021