[Ffmpeg-devel] Divide by zero in av_reduce - Possible Bug
Ian McIntosh
ianm
Thu May 25 11:31:05 CEST 2006
Hi
I had an mpeg2 (Elementary Video Stream) source that had quite a few
errors in the stream. While decoding using the ffmpeg library, my
program would crash with a divide by zero error. Looking at the
backtrace I noticed that in mpeg12.c the frame_rate_index was 0 just
before calling av_reduce. The result of this is that the 'nom' and 'den'
parameters in av_reduce are 0 which ends up making the 'gcd' variable
inside av_reduce (rational.c) 0, which is later used as a divisor in
another calculation which equals core dump.
Anyway it turns out that in the mpeg2 source stream there was an error
with the 'frame rate code' bits in one of the sequence headers (they
were 0 for some reason). A quick hack to fix this was to check the
frame_rate_index just before the av_reduce function call and set it to
some valid value if it was 0. This resolved the problem, but I was
thinking that there is probably a better way to handle this condition.
Anyone have any thoughts on the matter or suggestions for a fix ?
Unfortunately I no longer have the source as I mistakenly deleted it
thinking it was something else (sometimes I do some pretty dumb things).
However regenerating such a source using a hex-editor and a valid mpeg2
source would be quite easy.
Thanks
Ian
More information about the ffmpeg-devel
mailing list