diff options
author | Anton Khirnov <anton@khirnov.net> | 2016-07-30 15:14:26 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2016-07-31 08:19:45 +0200 |
commit | ed1cd81076434b76f37576d4d806973476a8e96c (patch) | |
tree | 9b5e28bcb91ebb1b5a4dca6494f3264cce0e8556 /libavformat/flacdec.c | |
parent | 5ebef79abecc3ffcc4ab0d46e203d13b068107c9 (diff) | |
download | ffmpeg-ed1cd81076434b76f37576d4d806973476a8e96c.tar.gz |
flac demuxer: improve probing
Extend the probe function to validate the STREAMINFO block that must
follow the fLaC ID tag.
Diffstat (limited to 'libavformat/flacdec.c')
-rw-r--r-- | libavformat/flacdec.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 7a75527333..2f4ac56040 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -177,9 +177,24 @@ static int flac_read_header(AVFormatContext *s) static int flac_probe(AVProbeData *p) { - if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4)) - return 0; - return AVPROBE_SCORE_EXTENSION; + /* file header + metadata header + checked bytes of streaminfo */ + if (p->buf_size >= 4 + 4 + 13) { + int type = p->buf[4] & 0x7f; + int size = AV_RB24(p->buf + 5); + int min_block_size = AV_RB16(p->buf + 8); + int max_block_size = AV_RB16(p->buf + 10); + int sample_rate = AV_RB24(p->buf + 18) >> 4; + + if (!memcmp(p->buf, "fLaC", 4) && + type == FLAC_METADATA_TYPE_STREAMINFO && + size == FLAC_STREAMINFO_SIZE && + min_block_size >= 16 && + max_block_size >= min_block_size && + sample_rate && sample_rate <= 655350) + return AVPROBE_SCORE_MAX; + } + + return 0; } AVInputFormat ff_flac_demuxer = { |