diff options
author | Oneric <oneric@oneric.stub> | 2020-10-13 03:19:59 +0200 |
---|---|---|
committer | Oleg Oshmyan <chortos@inbox.lv> | 2020-10-27 01:03:04 +0200 |
commit | 86da6159c9f9b6b278dd5cba7fe289ddd0203a3f (patch) | |
tree | 9eed218a221459233ffe0c3f044377a20d4caabc /libass | |
parent | 324c75fb6972d42b707aa17edc38b9943ae966bd (diff) | |
download | libass-86da6159c9f9b6b278dd5cba7fe289ddd0203a3f.tar.bz2 libass-86da6159c9f9b6b278dd5cba7fe289ddd0203a3f.tar.xz |
Handle strdup-fails regardinging FontFamily
We already ensure at creation that all styles have a non-null FontName.
However font family strings are strduped at various places and NULLs
cannot be fully avoided, since already the very first font strdup may
fail, so additional checks are required.
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass_parse.c | 16 | ||||
-rw-r--r-- | libass/ass_render.c | 12 |
2 files changed, 19 insertions, 9 deletions
diff --git a/libass/ass_parse.c b/libass/ass_parse.c index bb6fcff..3d7afe2 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -24,6 +24,7 @@ #include <string.h> #include <math.h> +#include "ass_library.h" #include "ass_render.h" #include "ass_parse.h" @@ -101,6 +102,8 @@ void update_font(ASS_Renderer *render_priv) unsigned val; ASS_FontDesc desc; + if (!render_priv->state.family) + return; if (render_priv->state.family[0] == '@') { desc.vertical = 1; desc.family = strdup(render_priv->state.family + 1); @@ -108,6 +111,8 @@ void update_font(ASS_Renderer *render_priv) desc.vertical = 0; desc.family = strdup(render_priv->state.family); } + if (!desc.family) + return; val = render_priv->state.bold; // 0 = normal, 1 = bold, >1 = exact weight @@ -520,11 +525,14 @@ char *parse_tags(ASS_Renderer *render_priv, char *p, char *end, double pwr, if (nargs && strncmp(start, "0", args->end - start)) { skip_spaces(&start); family = strndup(start, args->end - start); - } else + } else { family = strdup(render_priv->state.style->FontName); - free(render_priv->state.family); - render_priv->state.family = family; - update_font(render_priv); + } + if (family) { + free(render_priv->state.family); + render_priv->state.family = family; + update_font(render_priv); + } } else if (tag("alpha")) { int i; if (nargs) { diff --git a/libass/ass_render.c b/libass/ass_render.c index c0bbb9f..f529ffe 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -997,11 +997,13 @@ void reset_render_context(ASS_Renderer *render_priv, ASS_Style *style) (style->StrikeOut ? DECO_STRIKETHROUGH : 0); render_priv->state.font_size = style->FontSize; - free(render_priv->state.family); - render_priv->state.family = NULL; - render_priv->state.family = strdup(style->FontName); - render_priv->state.treat_family_as_pattern = - style->treat_fontname_as_pattern; + char* new_family = strdup(style->FontName); + if (new_family) { + free(render_priv->state.family); + render_priv->state.family = new_family; + render_priv->state.treat_family_as_pattern = + style->treat_fontname_as_pattern; + } render_priv->state.bold = style->Bold; render_priv->state.italic = style->Italic; update_font(render_priv); |