diff mbox series

[FFmpeg-devel,1/2] avformat/webmdashenc: Check codec types

Message ID 20200330073017.17693-1-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avformat/webmdashenc: Check codec types | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 30, 2020, 7:30 a.m. UTC
The WebM DASH Manifest muxer only supports VP8, VP9, Vorbis and Opus,
but there was no check for this. The codec type is used to get a pointer
to a string containing the codec name or NULL if it is not one of those
four codecs. Said pointer has then been used without further checks as
string for the %s conversion specifier in an avio_printf()) call which
is undefined behaviour.

This commit adds a check for the supported codec types.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/webmdashenc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Andreas Rheinhardt April 5, 2020, 5:50 p.m. UTC | #1
Andreas Rheinhardt:
> The WebM DASH Manifest muxer only supports VP8, VP9, Vorbis and Opus,
> but there was no check for this. The codec type is used to get a pointer
> to a string containing the codec name or NULL if it is not one of those
> four codecs. Said pointer has then been used without further checks as
> string for the %s conversion specifier in an avio_printf()) call which
> is undefined behaviour.
> 
> This commit adds a check for the supported codec types.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/webmdashenc.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
> index d05b265330..182a361eae 100644
> --- a/libavformat/webmdashenc.c
> +++ b/libavformat/webmdashenc.c
> @@ -516,6 +516,14 @@ static int webm_dash_manifest_write_header(AVFormatContext *s)
>      double start = 0.0;
>      int ret;
>      WebMDashMuxContext *w = s->priv_data;
> +
> +    for (unsigned i = 0; i < s->nb_streams; i++) {
> +        enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
> +        if ((codec_id != AV_CODEC_ID_VP8) && (codec_id != AV_CODEC_ID_VP9) &&
> +            (codec_id != AV_CODEC_ID_VORBIS) && (codec_id != AV_CODEC_ID_OPUS))
> +            return AVERROR(EINVAL);
> +    }
> +
>      ret = parse_adaptation_sets(s);
>      if (ret < 0) {
>          goto fail;
> 

If there are no objections, I intend to apply this patchset tomorrow.

- Andreas
Carl Eugen Hoyos April 5, 2020, 5:58 p.m. UTC | #2
Am Mo., 30. März 2020 um 09:30 Uhr schrieb Andreas Rheinhardt
<andreas.rheinhardt@gmail.com>:
>
> The WebM DASH Manifest muxer only supports VP8, VP9, Vorbis and Opus,
> but there was no check for this. The codec type is used to get a pointer
> to a string containing the codec name or NULL if it is not one of those
> four codecs. Said pointer has then been used without further checks as
> string for the %s conversion specifier in an avio_printf()) call which
> is undefined behaviour.
>
> This commit adds a check for the supported codec types.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/webmdashenc.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
> index d05b265330..182a361eae 100644
> --- a/libavformat/webmdashenc.c
> +++ b/libavformat/webmdashenc.c
> @@ -516,6 +516,14 @@ static int webm_dash_manifest_write_header(AVFormatContext *s)
>      double start = 0.0;
>      int ret;
>      WebMDashMuxContext *w = s->priv_data;
> +
> +    for (unsigned i = 0; i < s->nb_streams; i++) {
> +        enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
> +        if ((codec_id != AV_CODEC_ID_VP8) && (codec_id != AV_CODEC_ID_VP9) &&
> +            (codec_id != AV_CODEC_ID_VORBIS) && (codec_id != AV_CODEC_ID_OPUS))
> +            return AVERROR(EINVAL);

Too man parenthesis imo...

Carl Eugen
Andreas Rheinhardt April 5, 2020, 6:01 p.m. UTC | #3
Carl Eugen Hoyos:
> Am Mo., 30. März 2020 um 09:30 Uhr schrieb Andreas Rheinhardt
> <andreas.rheinhardt@gmail.com>:
>>
>> The WebM DASH Manifest muxer only supports VP8, VP9, Vorbis and Opus,
>> but there was no check for this. The codec type is used to get a pointer
>> to a string containing the codec name or NULL if it is not one of those
>> four codecs. Said pointer has then been used without further checks as
>> string for the %s conversion specifier in an avio_printf()) call which
>> is undefined behaviour.
>>
>> This commit adds a check for the supported codec types.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>>  libavformat/webmdashenc.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
>> index d05b265330..182a361eae 100644
>> --- a/libavformat/webmdashenc.c
>> +++ b/libavformat/webmdashenc.c
>> @@ -516,6 +516,14 @@ static int webm_dash_manifest_write_header(AVFormatContext *s)
>>      double start = 0.0;
>>      int ret;
>>      WebMDashMuxContext *w = s->priv_data;
>> +
>> +    for (unsigned i = 0; i < s->nb_streams; i++) {
>> +        enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
>> +        if ((codec_id != AV_CODEC_ID_VP8) && (codec_id != AV_CODEC_ID_VP9) &&
>> +            (codec_id != AV_CODEC_ID_VORBIS) && (codec_id != AV_CODEC_ID_OPUS))
>> +            return AVERROR(EINVAL);
> 
> Too man parenthesis imo...
> 
Fixed locally.

- Andreas
Andreas Rheinhardt April 7, 2020, 1:05 p.m. UTC | #4
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> The WebM DASH Manifest muxer only supports VP8, VP9, Vorbis and Opus,
>> but there was no check for this. The codec type is used to get a pointer
>> to a string containing the codec name or NULL if it is not one of those
>> four codecs. Said pointer has then been used without further checks as
>> string for the %s conversion specifier in an avio_printf()) call which
>> is undefined behaviour.
>>
>> This commit adds a check for the supported codec types.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>>  libavformat/webmdashenc.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
>> index d05b265330..182a361eae 100644
>> --- a/libavformat/webmdashenc.c
>> +++ b/libavformat/webmdashenc.c
>> @@ -516,6 +516,14 @@ static int webm_dash_manifest_write_header(AVFormatContext *s)
>>      double start = 0.0;
>>      int ret;
>>      WebMDashMuxContext *w = s->priv_data;
>> +
>> +    for (unsigned i = 0; i < s->nb_streams; i++) {
>> +        enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
>> +        if ((codec_id != AV_CODEC_ID_VP8) && (codec_id != AV_CODEC_ID_VP9) &&
>> +            (codec_id != AV_CODEC_ID_VORBIS) && (codec_id != AV_CODEC_ID_OPUS))
>> +            return AVERROR(EINVAL);
>> +    }
>> +
>>      ret = parse_adaptation_sets(s);
>>      if (ret < 0) {
>>          goto fail;
>>
> 
> If there are no objections, I intend to apply this patchset tomorrow.
> 
> - Andreas
> 
Applied.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index d05b265330..182a361eae 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -516,6 +516,14 @@  static int webm_dash_manifest_write_header(AVFormatContext *s)
     double start = 0.0;
     int ret;
     WebMDashMuxContext *w = s->priv_data;
+
+    for (unsigned i = 0; i < s->nb_streams; i++) {
+        enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
+        if ((codec_id != AV_CODEC_ID_VP8) && (codec_id != AV_CODEC_ID_VP9) &&
+            (codec_id != AV_CODEC_ID_VORBIS) && (codec_id != AV_CODEC_ID_OPUS))
+            return AVERROR(EINVAL);
+    }
+
     ret = parse_adaptation_sets(s);
     if (ret < 0) {
         goto fail;