From 0e8772a3bdca491230c90d3c9c7ab2ac5c18c2e7 Mon Sep 17 00:00:00 2001 From: Rodger Combs Date: Fri, 7 Nov 2014 14:49:18 -0400 Subject: Check more allocations Part of #146 --- libass/ass_bitmap.c | 16 ++++++++++++++++ libass/ass_render.c | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libass/ass_bitmap.c b/libass/ass_bitmap.c index 9a98f5a..6de70f0 100644 --- a/libass/ass_bitmap.c +++ b/libass/ass_bitmap.c @@ -133,7 +133,13 @@ static Bitmap *alloc_bitmap_raw(int w, int h) unsigned align = (w >= 32) ? 32 : ((w >= 16) ? 16 : 1); unsigned s = ass_align(align, w); bm = malloc(sizeof(Bitmap)); + if (!bm) + return NULL; bm->buffer = ass_aligned_alloc(align, s * h + 32); + if (!bm->buffer) { + free(bm); + return NULL; + } bm->w = w; bm->h = h; bm->stride = s; @@ -160,6 +166,8 @@ void ass_free_bitmap(Bitmap *bm) Bitmap *copy_bitmap(const Bitmap *src) { Bitmap *dst = alloc_bitmap_raw(src->w, src->h); + if (!dst) + return NULL; dst->left = src->left; dst->top = src->top; memcpy(dst->buffer, src->buffer, src->stride * src->h); @@ -179,6 +187,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv, if (rst->x_min >= rst->x_max || rst->y_min >= rst->y_max) { Bitmap *bm = alloc_bitmap(2 * bord, 2 * bord); + if (!bm) + return NULL; bm->left = bm->top = -bord; return bm; } @@ -200,6 +210,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv, int tile_w = (w + 2 * bord + mask) & ~mask; int tile_h = (h + 2 * bord + mask) & ~mask; Bitmap *bm = alloc_bitmap(tile_w, tile_h); + if (!bm) + return NULL; bm->left = x_min - bord; bm->top = -y_max - bord; @@ -234,6 +246,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv, FT_Outline_Get_CBox(outline, &bbox); if (bbox.xMin >= bbox.xMax || bbox.yMin >= bbox.yMax) { bm = alloc_bitmap(2 * bord, 2 * bord); + if (!bm) + return NULL; bm->left = bm->top = -bord; return bm; } @@ -259,6 +273,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv, // allocate and set up bitmap bm = alloc_bitmap(w + 2 * bord, h + 2 * bord); + if (!bm) + return NULL; bm->left = bbox.xMin - bord; bm->top = -bbox.yMax - bord; bitmap.width = w; diff --git a/libass/ass_render.c b/libass/ass_render.c index d1a47ee..c1cf548 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -1883,7 +1883,8 @@ static void make_shadow_bitmap(CombinedBitmapInfo *info, ASS_Renderer *render_pr } else info->bm_s = copy_bitmap(info->bm); - assert(info->bm_s); + if (!info->bm_s) + return; // Works right even for negative offsets // '>>' rounds toward negative infinity, '&' returns correct remainder @@ -2557,11 +2558,15 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event, int offset_y = (info->pos.y >> 6) - current_info->pos.y; if(info->bm){ current_info->bm = copy_bitmap(info->bm); + if (!current_info->bm) + goto cleanup; current_info->bm->left += offset_x; current_info->bm->top += offset_y; } if(info->bm_o){ current_info->bm_o = copy_bitmap(info->bm_o); + if (!current_info->bm_o) + goto cleanup; current_info->bm_o->left += offset_x; current_info->bm_o->top += offset_y; } @@ -2593,6 +2598,7 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event, } } } + cleanup: info = info->next; } } -- cgit v1.2.3