1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavd/alsa: add stream validation

Don't trust provided streams.
Return with error when stream count is not 1 or
provided stream is not an audio stream.

Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
This commit is contained in:
Lukasz Marek 2013-10-26 01:32:55 +02:00 committed by Nicolas George
parent 6ac9afd16e
commit e56d1a1203

View File

@ -47,12 +47,17 @@
static av_cold int audio_write_header(AVFormatContext *s1) static av_cold int audio_write_header(AVFormatContext *s1)
{ {
AlsaData *s = s1->priv_data; AlsaData *s = s1->priv_data;
AVStream *st; AVStream *st = NULL;
unsigned int sample_rate; unsigned int sample_rate;
enum AVCodecID codec_id; enum AVCodecID codec_id;
int res; int res;
if (s1->nb_streams != 1 || s1->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
av_log(s1, AV_LOG_ERROR, "Only a single audio stream is supported.\n");
return AVERROR(EINVAL);
}
st = s1->streams[0]; st = s1->streams[0];
sample_rate = st->codec->sample_rate; sample_rate = st->codec->sample_rate;
codec_id = st->codec->codec_id; codec_id = st->codec->codec_id;
res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate, res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,