fix: fix Font Preview crash if opened manually
This commit is contained in:
1 parent
7c8b7a5cf7
commit
796ed46d12
3 files changed
+17
-3
No files matched your search
@@ -345,8 +345,13 @@ extern "C" void _start() {
|
||||
g_preview_data = (uint8_t*)montauk::malloc(size);
|
||||
if (g_preview_data) {
|
||||
montauk::read(fd, g_preview_data, 0, size);
|
||||
if (stbtt_InitFont(&g_preview_info, g_preview_data,
|
||||
stbtt_GetFontOffsetForIndex(g_preview_data, 0))) {
|
||||
// stbtt_GetFontOffsetForIndex returns -1 for anything that
|
||||
// isn't a valid font (e.g. a directory or arbitrary file).
|
||||
// Passing that -1 into stbtt_InitFont makes it read at
|
||||
// data + (uint32)-1, faulting. Guard against it.
|
||||
int off = stbtt_GetFontOffsetForIndex(g_preview_data, 0);
|
||||
if (off >= 0 &&
|
||||
stbtt_InitFont(&g_preview_info, g_preview_data, off)) {
|
||||
g_load_ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user