[FFmpeg-devel] [PATCH] PCM: fail gracefully if the audio parameters are wrong.

Nicolas George nicolas.george
Thu Apr 10 17:02:59 CEST 2008


The attached patch checks that the sample rate and channels count is correct
for raw PCM files.

If the channels count is not set in the AVFormatParameters,
av_find_stream_info crashes on a division by zero, which is not cool. The
problem does not occur with ffmpeg itself, since it always sets the sample
rate and the channels count.


  Nicolas George
-------------- next part --------------
diff --git a/libavformat/raw.c b/libavformat/raw.c
index d4b1389..81215b4 100644
--- a/libavformat/raw.c
+++ b/libavformat/raw.c
@@ -80,6 +80,12 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
         switch(st->codec->codec_type) {
         case CODEC_TYPE_AUDIO:
+	    if(ap->sample_rate == 0 || ap->channels == 0) {
+		av_log(s, AV_LOG_ERROR,
+		    "Bad sample rate (%d) or channels count (%d)\n",
+		    ap->sample_rate, ap->channels);
+		return -1;
+	    }
             st->codec->sample_rate = ap->sample_rate;
             st->codec->channels = ap->channels;
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080410/5e1e0890/attachment.pgp>

More information about the ffmpeg-devel mailing list