On 26.06.2015 01:27, Michael Niedermayer wrote:
> On Fri, Jun 26, 2015 at 12:05:09AM +0200, Andreas Cadhalpun wrote:
>> If 'buf_size * 8' is smaller than 'avctx->channels *
>> (avctx->bits_per_raw_sample + 4)' it resulted in a division by zero.
>>
>> Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
>> ---
>>  libavcodec/s302m.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
>> index 5cf9eb5..36c8e7c 100644
>> --- a/libavcodec/s302m.c
>> +++ b/libavcodec/s302m.c
>> @@ -86,9 +86,9 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, 
>> const uint8_t *buf,
>>              avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | 
>> AV_CH_LAYOUT_STEREO_DOWNMIX;
>>      }
>>      avctx->bit_rate    = 48000 * avctx->channels * 
>> (avctx->bits_per_raw_sample + 4) +
>> -                         32 * (48000 / (buf_size * 8 /
>> -                                        (avctx->channels *
>> -                                         (avctx->bits_per_raw_sample + 
>> 4))));
>> +                         32 * (48000 * avctx->channels
>> +                                * (avctx->bits_per_raw_sample + 4))
>> +                            / (buf_size * 8);
> 
> i dont think the new code matches the nb_samples vs. buf_size vs.
> samplerate of s302m_decode_frame()

I don't think the old code did either.

> maybe the nb_samples calculation could be factored out and used for
> bitrate computation too

It can just be reused, which also nicely avoids the division by zero.
New patch attached.

Best regards,
Andreas

>From 20bca467900d0b0d4ec6fe64140f4d4d251d0bbe Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
Date: Fri, 26 Jun 2015 19:31:03 +0200
Subject: [PATCH] s302m: fix arithmetic exception

If nb_samples is zero, the bit_rate calculation results in a division by
zero.

Since ff_get_buffer fails if frame->nb_samples is zero, this can be
fixed by moving the bit_rate calculation after that function call.

That also makes it possible to reuse the already calculated
frame->nb_samples value.

Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
---
 libavcodec/s302m.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index 5cf9eb5..24130d8 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -85,10 +85,6 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
         case 8:
             avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX;
     }
-    avctx->bit_rate    = 48000 * avctx->channels * (avctx->bits_per_raw_sample + 4) +
-                         32 * (48000 / (buf_size * 8 /
-                                        (avctx->channels *
-                                         (avctx->bits_per_raw_sample + 4))));
 
     return frame_size;
 }
@@ -117,6 +113,8 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
+    avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_raw_sample + 4) +
+                      32 * 48000 / frame->nb_samples;
     buf_size = (frame->nb_samples * avctx->channels / 2) * block_size;
 
     if (avctx->bits_per_raw_sample == 24) {
-- 
2.1.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to