Skip to content

WIP: fix: remove Pango font caching

The Pango plugin was caching font descriptions upon lookup. Unfortunately the cached description could outlive some of the pointers to the font's details that were stored with it, leading to use-after-free accesses to these pointers in subsequent calls to pango_textlayout. To address this, we simply remove the caching altogether and destruct and then reconstruct the font description each time. Fixes #1767 (closed).

@Caryon1, if you're in a position to build this from source, can you confirm it solves your problem?


This has a potential performance impact, as it's removing a caching mechanism. I think it's the right direction, as the caching mechanism was unsafe, but I wanted to outline an alternative so we go into this more informed. We could alternatively retain the cache and do a pointer comparison between fontname and span->font->name, and only discard the cached desc in this circumstance. This would avoid dereferencing the (stale) fontname pointer, but using a pointer comparison for this is a bit hacky. Thoughts?

We should probably also regression test this. However, I don't think the test suite currently has a convenient mechanism for compiling and running a C test case. Opinions on this (both whether this needs a test case and how it should be constructed)? I could just roll a pytest test case that compiles some C to a temporary directory and execs that?

Edited by Matthew Fernandez

Merge request reports