Commit 96616833 authored by Cosimo Cecchi's avatar Cosimo Cecchi
Browse files

Fallback to basename when no family name (CVE-2019-19308)

Instead of possibly returning an empty string, which will cause
issues later on.

We store the GFile that was loaded to create the FT_Face into its
generic client data structure, and load the basename from it when
we don't have a family name.

#17
parent 4d548988
......@@ -67,6 +67,13 @@ font_load_job_free (FontLoadJob *job)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FontLoadJob, font_load_job_free)
static void
face_data_finalizer (void *object)
{
FT_Face face = object;
g_clear_object (&face->generic.data);
}
static FT_Face
create_face_from_contents (FontLoadJob *job,
gchar **contents,
......@@ -88,6 +95,9 @@ create_face_from_contents (FontLoadJob *job,
return NULL;
}
retval->generic.data = g_object_ref (job->file);
retval->generic.finalizer = face_data_finalizer;
*contents = g_steal_pointer (&job->face_contents);
return retval;
}
......@@ -181,8 +191,22 @@ gchar *
sushi_get_font_name (FT_Face face,
gboolean short_form)
{
if (short_form && g_strcmp0 (face->style_name, "Regular") == 0)
return g_strdup (face->family_name);
const char *style_name = face->style_name;
const char *family_name = face->family_name;
if (family_name == NULL) {
/* Try to get the basename of the file this was loaded from */
GFile *file = face->generic.data;
if (G_IS_FILE (file))
return g_file_get_basename (file);
/* Use an empty string as the last fallback */
return g_strdup ("");
}
if (style_name == NULL ||
(short_form && g_strcmp0 (style_name, "Regular") == 0))
return g_strdup (family_name);
return g_strconcat (face->family_name, ", ", face->style_name, NULL);
return g_strconcat (family_name, ", ", style_name, NULL);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment