diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2021-08-04 20:04:52 +0100 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2021-08-04 20:32:26 +0100 |
commit | 48267e62e3fecfc1e463a61e9e81cdee852361c6 (patch) | |
tree | 8ec5c0f11e52359b8690494c76ae292f885629f4 | |
parent | 66fff5d1b981aa54e489c3c706c54892a97f147d (diff) | |
download | ttf2f-48267e62e3fecfc1e463a61e9e81cdee852361c6.tar.gz ttf2f-48267e62e3fecfc1e463a61e9e81cdee852361c6.tar.bz2 |
Avoid overflow when fetching glyph names.
The glyph list only contains names for codepoints in the basic
multilingual plane (i.e. the first 2^16 codepoints). Ensure that
we don't erroneously match glyph names for codepoints in astral planes.
-rw-r--r-- | src/glyphs.c | 13 | ||||
-rw-r--r-- | src/glyphs.h | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/glyphs.c b/src/glyphs.c index b66675b..26c7308 100644 --- a/src/glyphs.c +++ b/src/glyphs.c @@ -76,13 +76,16 @@ ttf2f_result glyph_load_list(void) return TTF2F_RESULT_OK; } -const char *glyph_name(unsigned short code) +const char *glyph_name(unsigned int code) { - struct glyph_entry *g; + struct glyph_entry *g = NULL; - for (g = &glyphs[code / 256]; g; g = g->next) - if (g->code == code) - break; + /* The glyph list only covers the BMP */ + if (code < 65536) { + for (g = &glyphs[code / 256]; g; g = g->next) + if (g->code == code) + break; + } return g != NULL ? g->name : NULL; } diff --git a/src/glyphs.h b/src/glyphs.h index 5125f9e..a3cd435 100644 --- a/src/glyphs.h +++ b/src/glyphs.h @@ -5,6 +5,6 @@ ttf2f_result glyph_load_list(void); void glyph_destroy_list(void); -const char *glyph_name(unsigned short code); +const char *glyph_name(unsigned int code); #endif |