diff options
author | John Stebbins <[email protected]> | 2015-10-21 09:36:16 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2015-10-26 08:32:38 -0700 |
commit | 37dfc5b294c084503dab6102be0542f0eb64f881 (patch) | |
tree | 5880fb6694f05e1176a50217ce40aa442c0b0c12 /libhb | |
parent | 90f9b9a077bf59a596486fecf063d7c4828df432 (diff) |
libhb: prevent crashes in hb_get_preview2
Try to avoid failures to initialize sws context by setting minimum
dimensions. And if initialization does fail, exit gracefully instead of
crashing in sws_scale.
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/hb.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index c5c3c8cf1..0665f1b51 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -758,7 +758,8 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, hb_geometry_settings_t *geo, int deinterlace) { char filename[1024]; - hb_buffer_t * in_buf, * deint_buf = NULL, * preview_buf; + hb_buffer_t * in_buf = NULL, * deint_buf = NULL; + hb_buffer_t * preview_buf = NULL; uint32_t swsflags; AVPicture pic_in, pic_preview, pic_deint, pic_crop; struct SwsContext * context; @@ -767,6 +768,17 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, geo->geometry.par.num / geo->geometry.par.den; int height = geo->geometry.height; + // Set minimum dimensions to prevent failure to initialize + // sws context + if (width < 32) + { + width = 32; + } + if (height < 32) + { + height = 32; + } + swsflags = SWS_LANCZOS | SWS_ACCURATE_RND; preview_buf = hb_frame_buffer_init(AV_PIX_FMT_RGB32, width, height); @@ -816,6 +828,12 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, title->geometry.height - (geo->crop[0] + geo->crop[1]), AV_PIX_FMT_YUV420P, width, height, AV_PIX_FMT_RGB32, swsflags); + if (context == NULL) + { + // if by chance hb_sws_get_context fails, don't crash in sws_scale + goto fail; + } + // Scale sws_scale(context, (const uint8_t* const *)pic_crop.data, pic_crop.linesize, @@ -836,6 +854,10 @@ hb_image_t* hb_get_preview2(hb_handle_t * h, int title_idx, int picture, fail: + hb_buffer_close( &in_buf ); + hb_buffer_close( &deint_buf ); + hb_buffer_close( &preview_buf ); + image = hb_image_init(AV_PIX_FMT_RGB32, width, height); return image; } |