WINGs/wfont_wl: remove stale text comparison in wl_text_width
The optimization that skipped pango_layout_set_text when the text matched the previous layout content used pango_layout_get_text() which returns an internal pointer. This pointer comparison with arbitrary input text could read freed memory or trigger heap corruption in Pango internals when the layout state was stale. Always call pango_layout_set_text unconditionally. The cost is negligible (Pango internally short-circuits if text is identical).
This commit is contained in:
parent
3acf2f6b2b
commit
5558a1edf0
|
|
@ -110,9 +110,7 @@ static int
|
|||
wl_text_width(void *handle, const char *text, int len)
|
||||
{
|
||||
FontHandleWL *h = handle;
|
||||
const char *prev = pango_layout_get_text(h->layout);
|
||||
if (!prev || strncmp(text, prev, (size_t)len) != 0 || prev[len] != '\0')
|
||||
pango_layout_set_text(h->layout, text, len);
|
||||
pango_layout_set_text(h->layout, text, len);
|
||||
int w = 0;
|
||||
pango_layout_get_pixel_size(h->layout, &w, NULL);
|
||||
return w;
|
||||
|
|
|
|||
Loading…
Reference in New Issue