[FFmpeg-devel] aiffdec: fix division by zero

Message ID a6d7c5e4-13c8-61d5-c945-3828acbd1a75@googlemail.com
State Accepted
Headers

Commit Message

Andreas Cadhalpun Oct. 19, 2016, 7:18 p.m. UTC
This is similar to commit c143a9c.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
---
 libavformat/aiffdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Michael Niedermayer Oct. 20, 2016, 12:56 a.m. UTC | #1
On Wed, Oct 19, 2016 at 09:18:51PM +0200, Andreas Cadhalpun wrote:
> This is similar to commit c143a9c.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  libavformat/aiffdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

can aiff work without block_align ?

either way, block_duration is from the header reading
if its still accurate then using it together with 1 instead of the
matching block align is quite likely not correct
OTOH if block_duration does not represent the actual content then
the duration would only be correct by pure chance

Its a bit unfortunate that theres no usecase with an undamaged sample
which would have clear correct values

one has to work on the assumptation of a use case where the user needs
to override the codec and then ask "what is correct to do" that makes
this a bit tricky ...

[...]
  

Patch

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index de82787..d96fc1d 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -391,7 +391,7 @@  static int aiff_read_packet(AVFormatContext *s,
         pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
     /* Only one stream in an AIFF file */
     pkt->stream_index = 0;
-    pkt->duration     = (res / st->codecpar->block_align) * aiff->block_duration;
+    pkt->duration     = (res / (st->codecpar->block_align ? st->codecpar->block_align : 1)) * aiff->block_duration ;
     return 0;
 }