|
| 1 | +From 1767f99e2e2196c3fcae27db6d8b60098d3f6d26 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Behdad Esfahbod < [email protected]> |
| 3 | +Date: Sun, 10 Nov 2024 22:43:28 -0700 |
| 4 | +Subject: [PATCH] [cairo] Guard hb_cairo_glyphs_from_buffer() against bad UTF-8 |
| 5 | + |
| 6 | +Previously it was assuming valid UTF-8. |
| 7 | +--- |
| 8 | + src/3rdparty/harfbuzz-ng/src/hb-cairo.cc | 2 ++ |
| 9 | + src/3rdparty/harfbuzz-ng/src/hb-utf.hh | 6 ++++-- |
| 10 | + 2 files changed, 6 insertions(+), 2 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/3rdparty/harfbuzz-ng/src/hb-cairo.cc b/src/3rdparty/harfbuzz-ng/src/hb-cairo.cc |
| 13 | +index d8b582c4908..4d22ae059ff 100644 |
| 14 | +--- a/src/3rdparty/harfbuzz-ng/src/hb-cairo.cc |
| 15 | ++++ b/src/3rdparty/harfbuzz-ng/src/hb-cairo.cc |
| 16 | +@@ -1000,6 +1000,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, |
| 17 | + end = start + hb_glyph[i].cluster - hb_glyph[i+1].cluster; |
| 18 | + else |
| 19 | + end = (const char *) hb_utf_offset_to_pointer<hb_utf8_t> ((const uint8_t *) start, |
| 20 | ++ (const uint8_t *) utf8, utf8_len, |
| 21 | + (signed) (hb_glyph[i].cluster - hb_glyph[i+1].cluster)); |
| 22 | + (*clusters)[cluster].num_bytes = end - start; |
| 23 | + start = end; |
| 24 | +@@ -1020,6 +1021,7 @@ hb_cairo_glyphs_from_buffer (hb_buffer_t *buffer, |
| 25 | + end = start + hb_glyph[i].cluster - hb_glyph[i-1].cluster; |
| 26 | + else |
| 27 | + end = (const char *) hb_utf_offset_to_pointer<hb_utf8_t> ((const uint8_t *) start, |
| 28 | ++ (const uint8_t *) utf8, utf8_len, |
| 29 | + (signed) (hb_glyph[i].cluster - hb_glyph[i-1].cluster)); |
| 30 | + (*clusters)[cluster].num_bytes = end - start; |
| 31 | + start = end; |
| 32 | +diff --git a/src/3rdparty/harfbuzz-ng/src/hb-utf.hh b/src/3rdparty/harfbuzz-ng/src/hb-utf.hh |
| 33 | +index 1120bd1cccf..6db9bf2fd79 100644 |
| 34 | +--- a/src/3rdparty/harfbuzz-ng/src/hb-utf.hh |
| 35 | ++++ b/src/3rdparty/harfbuzz-ng/src/hb-utf.hh |
| 36 | +@@ -458,19 +458,21 @@ struct hb_ascii_t |
| 37 | + template <typename utf_t> |
| 38 | + static inline const typename utf_t::codepoint_t * |
| 39 | + hb_utf_offset_to_pointer (const typename utf_t::codepoint_t *start, |
| 40 | ++ const typename utf_t::codepoint_t *text, |
| 41 | ++ unsigned text_len, |
| 42 | + signed offset) |
| 43 | + { |
| 44 | + hb_codepoint_t unicode; |
| 45 | + |
| 46 | + while (offset-- > 0) |
| 47 | + start = utf_t::next (start, |
| 48 | +- start + utf_t::max_len, |
| 49 | ++ text + text_len, |
| 50 | + &unicode, |
| 51 | + HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT); |
| 52 | + |
| 53 | + while (offset++ < 0) |
| 54 | + start = utf_t::prev (start, |
| 55 | +- start - utf_t::max_len, |
| 56 | ++ text, |
| 57 | + &unicode, |
| 58 | + HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT); |
0 commit comments