diff mbox series

[FFmpeg-devel,06/20] avformat/matroskaenc: Check functions that can fail

Message ID 20200101005837.11356-7-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series Matroska muxer patches | expand

Checks

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

Commit Message

Andreas Rheinhardt Jan. 1, 2020, 12:58 a.m. UTC
Sometimes it has not been checked whether opening the dynamic buffer for
writing Tags fails; this might have led to segfaults.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskaenc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Andreas Rheinhardt Feb. 5, 2020, 12:59 p.m. UTC | #1
Andreas Rheinhardt:
> Sometimes it has not been checked whether opening the dynamic buffer for
> writing Tags fails; this might have led to segfaults.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/matroskaenc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 8cea829b31..7857656309 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -1557,7 +1557,9 @@ static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid,
>          ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_TAGS, avio_tell(s->pb));
>          if (ret < 0) return ret;
>  
> -        start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
> +        ret = start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
> +        if (ret < 0)
> +            return ret;
>      }
>      pb = mkv->tags_bc;
>  
> @@ -1653,7 +1655,10 @@ static int mkv_write_tags(AVFormatContext *s)
>              if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
>                  continue;
>  
> -            mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, &tag_target);
> +            ret = mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID,
> +                                        i + 1, &tag_target);
> +            if (ret < 0)
> +                return ret;
>              pb = mkv->tags_bc;
>  
>              tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 0);
> 
Ping.

- Andreas
Michael Niedermayer Feb. 5, 2020, 4:32 p.m. UTC | #2
On Wed, Jan 01, 2020 at 01:58:23AM +0100, Andreas Rheinhardt wrote:
> Sometimes it has not been checked whether opening the dynamic buffer for
> writing Tags fails; this might have led to segfaults.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/matroskaenc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 8cea829b31..7857656309 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1557,7 +1557,9 @@  static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid,
         ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_TAGS, avio_tell(s->pb));
         if (ret < 0) return ret;
 
-        start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
+        ret = start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
+        if (ret < 0)
+            return ret;
     }
     pb = mkv->tags_bc;
 
@@ -1653,7 +1655,10 @@  static int mkv_write_tags(AVFormatContext *s)
             if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
                 continue;
 
-            mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, &tag_target);
+            ret = mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID,
+                                        i + 1, &tag_target);
+            if (ret < 0)
+                return ret;
             pb = mkv->tags_bc;
 
             tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 0);