Skip to content

Commit

Permalink
Fix raqm_set_text_utf8/utf16 reading beyond len for multibyte
Browse files Browse the repository at this point in the history
_raqm_u8_to_u32 and _raqm_u16_to_u32 were only incrementing in_len instead of
increasing it by the amount of bytes/shorts read. Fix so raqm_set_text_utf8 and
raqm_set_text_utf16 correctly interpret the len parameters as UTF-8
bytes/UTF-16 shorts
  • Loading branch information
CallumDev authored Oct 9, 2024
1 parent 8876579 commit 53167e1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/raqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,10 @@ _raqm_u8_to_u32 (const char *text, size_t len, uint32_t *unicode)

while ((*in_utf8 != '\0') && (in_len < len))
{
in_utf8 = _raqm_get_utf8_codepoint (in_utf8, out_utf32);
const char *out_utf8 = _raqm_get_utf8_codepoint (in_utf8, out_utf32);
in_len += out_utf8 - in_utf8;
in_utf8 = out_utf8;
++out_utf32;
++in_len;
}

return (out_utf32 - unicode);
Expand Down Expand Up @@ -628,9 +629,10 @@ _raqm_u16_to_u32 (const uint16_t *text, size_t len, uint32_t *unicode)

while ((*in_utf16 != '\0') && (in_len < len))
{
in_utf16 = _raqm_get_utf16_codepoint (in_utf16, out_utf32);
const uint16_t *out_utf16 = _raqm_get_utf16_codepoint (in_utf16, out_utf32);
in_len += (out_utf16 - in_utf16);
in_utf16 = out_utf16;
++out_utf32;
++in_len;
}

return (out_utf32 - unicode);
Expand Down

0 comments on commit 53167e1

Please sign in to comment.