diff mbox

[FFmpeg-devel] avformat/matroskadec: fix DiscardPadding element parsing

Message ID 20161105205024.5536-1-jamrial@gmail.com
State Accepted
Headers show

Commit Message

James Almer Nov. 5, 2016, 8:50 p.m. UTC
If the value is negative then it means padding at the start of the packet
instead of at the end.

Based on a patch by Hendrik Leppkes.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

James Zern Nov. 8, 2016, midnight UTC | #1
On Sat, Nov 5, 2016 at 1:50 PM, James Almer <jamrial@gmail.com> wrote:
> If the value is negative then it means padding at the start of the packet
> instead of at the end.
>
> Based on a patch by Hendrik Leppkes.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/matroskadec.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>

lgtm

> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 32f5e49..5a22193 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -3082,10 +3082,16 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
>              av_free(pkt);
>              return AVERROR(ENOMEM);
>          }
> -        AV_WL32(side_data, 0);
> -        AV_WL32(side_data + 4, av_rescale_q(discard_padding,
> +        discard_padding = av_rescale_q(discard_padding,
>                                              (AVRational){1, 1000000000},
> -                                            (AVRational){1, st->codecpar->sample_rate}));
> +                                            (AVRational){1, st->codecpar->sample_rate});
> +        if (discard_padding > 0) {
>

I might have said '>= 0' as I was reading the else as doing '-0' which
sounded weird.
James Almer Nov. 8, 2016, 4:47 p.m. UTC | #2
On 11/7/2016 9:00 PM, James Zern wrote:
> On Sat, Nov 5, 2016 at 1:50 PM, James Almer <jamrial@gmail.com> wrote:
>> If the value is negative then it means padding at the start of the packet
>> instead of at the end.
>>
>> Based on a patch by Hendrik Leppkes.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/matroskadec.c | 12 +++++++++---
>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>
> 
> lgtm

Pushed, thanks.

> 
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 32f5e49..5a22193 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -3082,10 +3082,16 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
>>              av_free(pkt);
>>              return AVERROR(ENOMEM);
>>          }
>> -        AV_WL32(side_data, 0);
>> -        AV_WL32(side_data + 4, av_rescale_q(discard_padding,
>> +        discard_padding = av_rescale_q(discard_padding,
>>                                              (AVRational){1, 1000000000},
>> -                                            (AVRational){1, st->codecpar->sample_rate}));
>> +                                            (AVRational){1, st->codecpar->sample_rate});
>> +        if (discard_padding > 0) {
>>
> 
> I might have said '>= 0' as I was reading the else as doing '-0' which
> sounded weird.

This code is only ever run if discard_padding is not zero.

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 32f5e49..5a22193 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3082,10 +3082,16 @@  static int matroska_parse_frame(MatroskaDemuxContext *matroska,
             av_free(pkt);
             return AVERROR(ENOMEM);
         }
-        AV_WL32(side_data, 0);
-        AV_WL32(side_data + 4, av_rescale_q(discard_padding,
+        discard_padding = av_rescale_q(discard_padding,
                                             (AVRational){1, 1000000000},
-                                            (AVRational){1, st->codecpar->sample_rate}));
+                                            (AVRational){1, st->codecpar->sample_rate});
+        if (discard_padding > 0) {
+            AV_WL32(side_data, 0);
+            AV_WL32(side_data + 4, discard_padding);
+        } else {
+            AV_WL32(side_data, -discard_padding);
+            AV_WL32(side_data + 4, 0);
+        }
     }
 
     if (track->ms_compat)