From 4f1fd2687d280bc71ce1b4768dd3e16350cfa52d Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Wed, 30 Apr 2014 16:14:50 +0100 Subject: [PATCH] libav: avoid dividing by zero on insane fps/par While there, fix mixup in num/den with par (copied from fps, apparently, and fps inverts fps to time base). Coverity 1139696 --- ext/libav/gstavcodecmap.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/ext/libav/gstavcodecmap.c b/ext/libav/gstavcodecmap.c index d0e7a04..11fb40a 100644 --- a/ext/libav/gstavcodecmap.c +++ b/ext/libav/gstavcodecmap.c @@ -2379,26 +2379,43 @@ gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps, fps = gst_structure_get_value (structure, "framerate"); if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) { - /* somehow these seem mixed up.. */ - context->time_base.den = gst_value_get_fraction_numerator (fps); - context->time_base.num = gst_value_get_fraction_denominator (fps); - context->ticks_per_frame = 1; - - GST_DEBUG ("setting framerate %d/%d = %lf", - context->time_base.den, context->time_base.num, - 1. * context->time_base.den / context->time_base.num); + int num = gst_value_get_fraction_numerator (fps); + int den = gst_value_get_fraction_denominator (fps); + + if (num > 0 && den > 0) { + /* somehow these seem mixed up.. */ + /* they're fine, this is because it does period=1/frequency */ + context->time_base.den = gst_value_get_fraction_numerator (fps); + context->time_base.num = gst_value_get_fraction_denominator (fps); + context->ticks_per_frame = 1; + + GST_DEBUG ("setting framerate %d/%d = %lf", + context->time_base.den, context->time_base.num, + 1. * context->time_base.den / context->time_base.num); + } else { + GST_WARNING ("ignoring insane framerate %d/%d", + context->time_base.den, context->time_base.num); + } } par = gst_structure_get_value (structure, "pixel-aspect-ratio"); if (par && GST_VALUE_HOLDS_FRACTION (par)) { - context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par); - context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par); + int num = gst_value_get_fraction_numerator (par); + int den = gst_value_get_fraction_denominator (par); + + if (num > 0 && den > 0) { + context->sample_aspect_ratio.num = num; + context->sample_aspect_ratio.den = den; - GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf", - context->sample_aspect_ratio.den, context->sample_aspect_ratio.num, - 1. * context->sample_aspect_ratio.den / - context->sample_aspect_ratio.num); + GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf", + context->sample_aspect_ratio.num, context->sample_aspect_ratio.den, + 1. * context->sample_aspect_ratio.num / + context->sample_aspect_ratio.den); + } else { + GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d", + context->sample_aspect_ratio.num, context->sample_aspect_ratio.den); + } } if (!raw) -- 2.7.4