[FFmpeg-devel] [PATCH] rawdec: add check on sample_rate

Stefano Sabatini stefasab at gmail.com
Thu Oct 27 01:42:30 CEST 2011


Prevent error condition in case sample_rate is unset or set to a negative
value. In particular, fix divide-by-zero error occurring in ffmpeg due to
sample_rate set to 0 in output_packet(), in code:

                ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) /
                    ist->st->codec->sample_rate;

Fix trac ticket #324.
---
 libavformat/rawdec.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index 37e9b0c..f65266b 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -46,6 +46,8 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
         st->codec->codec_id = id;
 
         switch(st->codec->codec_type) {
+            int ret = 0;
+
         case AVMEDIA_TYPE_AUDIO: {
             RawAudioDemuxerContext *s1 = s->priv_data;
 
@@ -59,6 +61,13 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
             if (s1 && s1->channels)
                 st->codec->channels    = s1->channels;
 
+            if (st->codec->sample_rate <= 0) {
+                av_log(s, AV_LOG_ERROR, "Invalid sample rate %d specified\n",
+                       st->codec->sample_rate);
+                ret = AVERROR(EINVAL);
+                goto fail;
+            }
+
             st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
             assert(st->codec->bits_per_coded_sample > 0);
             st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
@@ -67,7 +76,7 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
             }
         case AVMEDIA_TYPE_VIDEO: {
             FFRawVideoDemuxerContext *s1 = s->priv_data;
-            int width = 0, height = 0, ret = 0;
+            int width = 0, height = 0;
             enum PixelFormat pix_fmt;
             AVRational framerate;
 
-- 
1.7.4.1



More information about the ffmpeg-devel mailing list