Skip to content

Commit 914e9a0

Browse files
committed
don't limit how many windows fonts we scan to 1024 (fixes #5526)
1 parent a7d1939 commit 914e9a0

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

ext/mupdf_load_system_font.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ typedef uint32_t u32;
3030

3131
#define MAX_FACENAME 256
3232

33-
#define MAX_FONT_FILES 1024
34-
#define MAX_FONTS 4096
33+
#define GROW_BY 128
3534

3635
typedef struct {
3736
const char* file_path;
@@ -46,13 +45,13 @@ typedef struct {
4645
} win_font_info;
4746

4847
typedef struct {
49-
win_font_info fontmap[MAX_FONTS];
48+
win_font_info* fontmap;
5049
int len;
5150
int cap;
5251
} win_fonts;
5352

5453
typedef struct {
55-
font_file files[MAX_FONT_FILES];
54+
font_file* files;
5655
int len;
5756
int cap;
5857
} font_files;
@@ -346,7 +345,14 @@ static int get_or_append_font_file(const char* file_path) {
346345
return i;
347346
}
348347
if (g_font_files.len >= g_font_files.cap) {
349-
return -1;
348+
int newCap = g_font_files.cap + GROW_BY;
349+
font_file* newFiles = (font_file*)realloc(g_font_files.files, newCap * sizeof(font_file));
350+
if (!newFiles) {
351+
return -1;
352+
}
353+
memset(newFiles + g_font_files.cap, 0, GROW_BY * sizeof(font_file));
354+
g_font_files.files = newFiles;
355+
g_font_files.cap = newCap;
350356
}
351357
i = g_font_files.len;
352358
ff = &g_font_files.files[i];
@@ -365,8 +371,14 @@ static void append_mapping(fz_context* ctx, const char* facename, const char* pa
365371
return;
366372
}
367373
if (fl->len >= fl->cap) {
368-
// fz_throw(ctx, FZ_ERROR_GENERIC, "fonterror : fontlist overflow");
369-
return;
374+
int newCap = fl->cap + GROW_BY;
375+
win_font_info* newMap = (win_font_info*)realloc(fl->fontmap, newCap * sizeof(win_font_info));
376+
if (!newMap) {
377+
return;
378+
}
379+
memset(newMap + fl->cap, 0, GROW_BY * sizeof(win_font_info));
380+
fl->fontmap = newMap;
381+
fl->cap = newCap;
370382
}
371383

372384
win_font_info* i = &fl->fontmap[fl->len];
@@ -1069,10 +1081,12 @@ void init_system_font_list(void) {
10691081
return;
10701082
}
10711083
InitializeCriticalSection(&cs_fonts);
1084+
g_win_fonts.fontmap = NULL;
10721085
g_win_fonts.len = 0;
1073-
g_win_fonts.cap = MAX_FONTS;
1086+
g_win_fonts.cap = 0;
1087+
g_font_files.files = NULL;
10741088
g_font_files.len = 0;
1075-
g_font_files.cap = MAX_FONT_FILES;
1089+
g_font_files.cap = 0;
10761090
did_init = 1;
10771091
}
10781092

@@ -1081,12 +1095,18 @@ void destroy_system_font_list(void) {
10811095
for (i = 0; i < g_win_fonts.len; i++) {
10821096
free((void*)g_win_fonts.fontmap[i].fontface);
10831097
}
1098+
free(g_win_fonts.fontmap);
1099+
g_win_fonts.fontmap = NULL;
10841100
g_win_fonts.len = 0;
1101+
g_win_fonts.cap = 0;
10851102
for (i = 0; i < g_font_files.len; i++) {
10861103
free((void*)g_font_files.files[i].file_path);
10871104
free(g_font_files.files[i].data);
10881105
}
1106+
free(g_font_files.files);
1107+
g_font_files.files = NULL;
10891108
g_font_files.len = 0;
1109+
g_font_files.cap = 0;
10901110
DeleteCriticalSection(&cs_fonts);
10911111
}
10921112

0 commit comments

Comments
 (0)