diff mbox

[FFmpeg-devel] lavf/flacdec: Return maximum score if a valid streaminfo header was found

Message ID 201703010938.58604.cehoyos@ag.or.at
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos March 1, 2017, 8:38 a.m. UTC
Hi!

I implemented this patch to fix ticket #6208 but it turned out the flac probe 
function wasn't the issue. Still looks like a good idea to me.

Please comment, Carl Eugen
From acc7558a3585d99776523ed670747597c4de99fb Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Wed, 1 Mar 2017 09:34:37 +0100
Subject: [PATCH 1/2] lavf/flacdec: Return maximum score if the streaminfo
 header is valid.

---
 libavformat/flacdec.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer March 2, 2017, 2:09 a.m. UTC | #1
On Wed, Mar 01, 2017 at 09:38:58AM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> I implemented this patch to fix ticket #6208 but it turned out the flac probe 
> function wasn't the issue. Still looks like a good idea to me.
> 
> Please comment, Carl Eugen

>  flacdec.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 64259ee8c398e244db4174257a3f1bbad6160ca7  0001-lavf-flacdec-Return-maximum-score-if-the-streaminfo-.patch
> From acc7558a3585d99776523ed670747597c4de99fb Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Wed, 1 Mar 2017 09:34:37 +0100
> Subject: [PATCH 1/2] lavf/flacdec: Return maximum score if the streaminfo
>  header is valid.
> 
> ---
>  libavformat/flacdec.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

if this works with all flac files you have then its probably ok
but i wouldnt be surprised if some of this will need to be tuned
based on future tickets

thx

[...]
Carl Eugen Hoyos March 2, 2017, 8:34 a.m. UTC | #2
2017-03-02 3:09 GMT+01:00 Michael Niedermayer <michael@niedermayer.cc>:
> On Wed, Mar 01, 2017 at 09:38:58AM +0100, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> I implemented this patch to fix ticket #6208 but it turned out the flac probe
>> function wasn't the issue. Still looks like a good idea to me.
>>
>> Please comment, Carl Eugen
>
>>  flacdec.c |    9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>> 64259ee8c398e244db4174257a3f1bbad6160ca7  0001-lavf-flacdec-Return-maximum-score-if-the-streaminfo-.patch
>> From acc7558a3585d99776523ed670747597c4de99fb Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
>> Date: Wed, 1 Mar 2017 09:34:37 +0100
>> Subject: [PATCH 1/2] lavf/flacdec: Return maximum score if the streaminfo
>>  header is valid.
>>
>> ---
>>  libavformat/flacdec.c |    9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> if this works with all flac files you have then its probably ok
> but i wouldnt be surprised if some of this will need to be tuned
> based on future tickets

Committed a variant that does not change behaviour for files
with an invalid streaminfo header (and better matches the commit
message).

Thank you, Carl Eugen
diff mbox

Patch

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 66baba5..c75eba8 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -233,7 +233,14 @@  static int flac_probe(AVProbeData *p)
         return raw_flac_probe(p);
     if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
         return 0;
-    return AVPROBE_SCORE_EXTENSION;
+    if (   p->buf[4] & 0x7f != FLAC_METADATA_TYPE_STREAMINFO
+        || AV_RB24(p->buf + 5) != FLAC_STREAMINFO_SIZE
+        || AV_RB16(p->buf + 8) < 16
+        || AV_RB16(p->buf + 8) > AV_RB16(p->buf + 10)
+        || !(AV_RB24(p->buf + 18) >> 4)
+        || AV_RB24(p->buf + 18) >> 4 > 655350)
+        return AVPROBE_SCORE_EXTENSION / 8;
+    return AVPROBE_SCORE_MAX;
 }
 
 static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,