From b6240cdaef1b51a9add42a4bdfa72064297dbc7d Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Fri, 24 Sep 2021 22:51:16 +0300 Subject: ass_face_open: don't return garbage if PostScript name not found Fixes https://github.com/libass/libass/issues/554. --- libass/ass_font.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libass/ass_font.c b/libass/ass_font.c index 46b7975..6f55840 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -133,6 +133,9 @@ static void set_font_metrics(FT_Face face) FT_Face ass_face_open(ASS_Library *lib, FT_Library ftlib, const char *path, const char *postscript_name, int index) { + if (index < 0 && !postscript_name) + return NULL; + FT_Face face; int error = FT_New_Face(ftlib, path, index, &face); if (error) { @@ -140,7 +143,9 @@ FT_Face ass_face_open(ASS_Library *lib, FT_Library ftlib, const char *path, return NULL; } - if (postscript_name && index < 0 && face->num_faces > 0) { + if (index >= 0) { + return face; + } else { // The font provider gave us a postscript name and is not sure // about the face index.. so use the postscript name to find the // correct face_index in the collection! @@ -155,11 +160,14 @@ FT_Face ass_face_open(ASS_Library *lib, FT_Library ftlib, const char *path, const char *face_psname = FT_Get_Postscript_Name(face); if (face_psname != NULL && strcmp(face_psname, postscript_name) == 0) - break; + return face; } - } - return face; + FT_Done_Face(face); + ass_msg(lib, MSGL_WARN, "Failed to find font '%s' in file: '%s'", + postscript_name, path); + return NULL; + } } static unsigned long -- cgit v1.2.3