diff mbox series

[FFmpeg-devel] avcodec/utils: don't return negative values in av_get_audio_frame_duration()

Message ID 20210721040812.8429-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/utils: don't return negative values in av_get_audio_frame_duration()
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer July 21, 2021, 4:08 a.m. UTC
In some extrme cases, like with adpcm_ms samples with an extremely high channel
count, get_audio_frame_duration() may return a negative frame duration value.
Don't propagate it, and instead return 0, signaling that a duration could not
be determined.

Fixes ticket #9312

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

James Almer July 23, 2021, 1:04 p.m. UTC | #1
On 7/21/2021 1:08 AM, James Almer wrote:
> In some extrme cases, like with adpcm_ms samples with an extremely high channel
> count, get_audio_frame_duration() may return a negative frame duration value.
> Don't propagate it, and instead return 0, signaling that a duration could not
> be determined.
> 
> Fixes ticket #9312
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/utils.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 88e88bc958..e0d5b2f536 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -810,20 +810,22 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
>   
>   int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
>   {
> -    return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
> +    int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
>                                       avctx->channels, avctx->block_align,
>                                       avctx->codec_tag, avctx->bits_per_coded_sample,
>                                       avctx->bit_rate, avctx->extradata, avctx->frame_size,
>                                       frame_bytes);
> +    return FFMAX(0, duration);
>   }
>   
>   int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
>   {
> -    return get_audio_frame_duration(par->codec_id, par->sample_rate,
> +    int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
>                                       par->channels, par->block_align,
>                                       par->codec_tag, par->bits_per_coded_sample,
>                                       par->bit_rate, par->extradata, par->frame_size,
>                                       frame_bytes);
> +    return FFMAX(0, duration);
>   }
>   
>   #if !HAVE_THREADS

Will apply.
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 88e88bc958..e0d5b2f536 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -810,20 +810,22 @@  static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
 
 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
 {
-    return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
+    int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
                                     avctx->channels, avctx->block_align,
                                     avctx->codec_tag, avctx->bits_per_coded_sample,
                                     avctx->bit_rate, avctx->extradata, avctx->frame_size,
                                     frame_bytes);
+    return FFMAX(0, duration);
 }
 
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
-    return get_audio_frame_duration(par->codec_id, par->sample_rate,
+    int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
                                     par->channels, par->block_align,
                                     par->codec_tag, par->bits_per_coded_sample,
                                     par->bit_rate, par->extradata, par->frame_size,
                                     frame_bytes);
+    return FFMAX(0, duration);
 }
 
 #if !HAVE_THREADS