mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-22 23:18:01 +03:00
Fix use-after-free in font_freetype.c
Pointers to `struct font_size` objects are cached in `struct text_style` objects, so the `sizes` array can't be reallocated. This fixes a crash in Rance 02 when entering battle.
This commit is contained in:
+5
-2
@@ -28,12 +28,14 @@
|
||||
#include "gfx/font.h"
|
||||
#include "xsystem4.h"
|
||||
|
||||
#define MAX_FONT_SIZES 64
|
||||
|
||||
struct font_ft {
|
||||
struct font super;
|
||||
FT_Face font;
|
||||
unsigned current_size;
|
||||
unsigned nr_sizes;
|
||||
struct font_size *sizes;
|
||||
struct font_size sizes[MAX_FONT_SIZES];
|
||||
};
|
||||
|
||||
static FT_Library ft_lib;
|
||||
@@ -69,7 +71,8 @@ static struct font_size *ft_font_get_size(struct font *_font, float size)
|
||||
}
|
||||
}
|
||||
|
||||
font->sizes = xrealloc_array(font->sizes, font->nr_sizes, font->nr_sizes+1, sizeof(struct font_size));
|
||||
if (font->nr_sizes + 1 >= MAX_FONT_SIZES)
|
||||
ERROR("Exceeded maximum number of font sizes");
|
||||
struct font_size *fs = &font->sizes[font->nr_sizes++];
|
||||
fs->size = size;
|
||||
fs->y_offset = -roundf(size * 0.15f);
|
||||
|
||||
+1
-1
Submodule subprojects/libsys4 updated: 5468eed9ba...958e1b6762
Reference in New Issue
Block a user