diff mbox

[FFmpeg-devel,v2] avformat/flvdec: check FLVHeader PreviousTagSize0

Message ID 20170325131528.62595-1-lq@chinaffmpeg.org
State Accepted
Commit c0628919b8c5761d64b1169e8de7584544d15ebf
Headers show

Commit Message

Steven Liu March 25, 2017, 1:15 p.m. UTC
refer to SPEC:
Annex E. The FLV File Format said:
E.3 TheFLVFileBody have a table:
Field            Type    Comment
PreviousTagSize0 UI32    Always 0

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/flvdec.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Bodecs Bela March 26, 2017, 10:39 a.m. UTC | #1
2017.03.25. 14:15 keltezéssel, Steven Liu írta:
> refer to SPEC:
> Annex E. The FLV File Format said:
> E.3 TheFLVFileBody have a table:
> Field            Type    Comment
> PreviousTagSize0 UI32    Always 0
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>   libavformat/flvdec.c | 12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
> index cdcfb9c..94c9e28 100644
> --- a/libavformat/flvdec.c
> +++ b/libavformat/flvdec.c
> @@ -709,6 +709,7 @@ static int flv_read_header(AVFormatContext *s)
>       int flags;
>       FLVContext *flv = s->priv_data;
>       int offset;
> +    int pre_tag_size = 0;
>   
>       avio_skip(s->pb, 4);
>       flags = avio_r8(s->pb);
> @@ -719,7 +720,16 @@ static int flv_read_header(AVFormatContext *s)
>   
>       offset = avio_rb32(s->pb);
>       avio_seek(s->pb, offset, SEEK_SET);
> -    avio_skip(s->pb, 4);
> +
> +    /* Annex E. The FLV File Format
> +     * E.3 TheFLVFileBody
> +     *     Field               Type    Comment
> +     *     PreviousTagSize0    UI32    Always 0
> +     * */
> +    pre_tag_size = avio_rb32(s->pb);
> +    if (pre_tag_size) {
> +        av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
> +    }
>   
>       s->start_time = 0;
>       flv->sum_flv_tag_size = 0;
I think this forgiving behaviour is better, than the earlier rigorous 
one. I agree that showing warning is more useful than returning error 
and stopping execution because if

PreviousTagSize0 is not zero that causes no harm.

bb
Steven Liu March 28, 2017, 9 a.m. UTC | #2
2017-03-26 18:39 GMT+08:00 Bodecs Bela <bodecsb@vivanet.hu>:

>
>
> 2017.03.25. 14:15 keltezéssel, Steven Liu írta:
>
>> refer to SPEC:
>> Annex E. The FLV File Format said:
>> E.3 TheFLVFileBody have a table:
>> Field            Type    Comment
>> PreviousTagSize0 UI32    Always 0
>>
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>>   libavformat/flvdec.c | 12 +++++++++++-
>>   1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
>> index cdcfb9c..94c9e28 100644
>> --- a/libavformat/flvdec.c
>> +++ b/libavformat/flvdec.c
>> @@ -709,6 +709,7 @@ static int flv_read_header(AVFormatContext *s)
>>       int flags;
>>       FLVContext *flv = s->priv_data;
>>       int offset;
>> +    int pre_tag_size = 0;
>>         avio_skip(s->pb, 4);
>>       flags = avio_r8(s->pb);
>> @@ -719,7 +720,16 @@ static int flv_read_header(AVFormatContext *s)
>>         offset = avio_rb32(s->pb);
>>       avio_seek(s->pb, offset, SEEK_SET);
>> -    avio_skip(s->pb, 4);
>> +
>> +    /* Annex E. The FLV File Format
>> +     * E.3 TheFLVFileBody
>> +     *     Field               Type    Comment
>> +     *     PreviousTagSize0    UI32    Always 0
>> +     * */
>> +    pre_tag_size = avio_rb32(s->pb);
>> +    if (pre_tag_size) {
>> +        av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is
>> not a standard flv format, first PreviousTagSize0 always is 0\n");
>> +    }
>>         s->start_time = 0;
>>       flv->sum_flv_tag_size = 0;
>>
> I think this forgiving behaviour is better, than the earlier rigorous one.
> I agree that showing warning is more useful than returning error and
> stopping execution because if
>
> PreviousTagSize0 is not zero that causes no harm.
>
> bb
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Pushed



Thanks!
diff mbox

Patch

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index cdcfb9c..94c9e28 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -709,6 +709,7 @@  static int flv_read_header(AVFormatContext *s)
     int flags;
     FLVContext *flv = s->priv_data;
     int offset;
+    int pre_tag_size = 0;
 
     avio_skip(s->pb, 4);
     flags = avio_r8(s->pb);
@@ -719,7 +720,16 @@  static int flv_read_header(AVFormatContext *s)
 
     offset = avio_rb32(s->pb);
     avio_seek(s->pb, offset, SEEK_SET);
-    avio_skip(s->pb, 4);
+
+    /* Annex E. The FLV File Format
+     * E.3 TheFLVFileBody
+     *     Field               Type    Comment
+     *     PreviousTagSize0    UI32    Always 0
+     * */
+    pre_tag_size = avio_rb32(s->pb);
+    if (pre_tag_size) {
+        av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
+    }
 
     s->start_time = 0;
     flv->sum_flv_tag_size = 0;