diff mbox

[FFmpeg-devel] lavf/movenc: Fail when codec tag is invalid for format

Message ID 20180825160444.11263-1-jstebbins@jetheaddev.com
State Superseded
Headers show

Commit Message

John Stebbins Aug. 25, 2018, 4:04 p.m. UTC
Fixes ticket #6897
---
 libavformat/movenc.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer Aug. 27, 2018, 5:59 p.m. UTC | #1
On Sat, Aug 25, 2018 at 09:04:44AM -0700, John Stebbins wrote:
> Fixes ticket #6897
> ---
>  libavformat/movenc.c | 40 +++++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 11 deletions(-)

breaks make -j12 fate-mov-gpmf-remux
[mp4 @ 0x26a5b40] Could not find tag for codec none in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
    Last message repeated 1 times
make: *** [fate-mov-gpmf-remux] Error 1

[...]
John Stebbins Aug. 27, 2018, 6:58 p.m. UTC | #2
On 08/27/2018 10:59 AM, Michael Niedermayer wrote:
> On Sat, Aug 25, 2018 at 09:04:44AM -0700, John Stebbins wrote:
>> Fixes ticket #6897
>> ---
>>  libavformat/movenc.c | 40 +++++++++++++++++++++++++++++-----------
>>  1 file changed, 29 insertions(+), 11 deletions(-)
> breaks make -j12 fate-mov-gpmf-remux
> [mp4 @ 0x26a5b40] Could not find tag for codec none in stream #1, codec not currently supported in container
> Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
> Stream mapping:
>   Stream #0:0 -> #0:0 (copy)
>   Stream #0:1 -> #0:1 (copy)
>     Last message repeated 1 times
> make: *** [fate-mov-gpmf-remux] Error 1
>
>

Yeah, I ran a fate test this morning and saw the same thing.  Sorry I didn't run it first, I should know better...

Preparing a fix as we speak.
diff mbox

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 72a6e12d52..93bb50ce86 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1589,6 +1589,26 @@  static const AVCodecTag codec_cover_image_tags[] = {
     { AV_CODEC_ID_NONE, 0 },
 };
 
+static int validate_codec_tag(const AVCodecTag *const *tags,
+                              unsigned int tag, int codec_id)
+{
+    int i;
+
+    /**
+     * Check that tag + id is in the table
+     */
+    for (i = 0; tags && tags[i]; i++) {
+        const AVCodecTag *codec_tags = tags[i];
+        while (codec_tags->id != AV_CODEC_ID_NONE) {
+            if (codec_tags->tag == tag && codec_tags->id == codec_id) {
+                return 1;
+            }
+            codec_tags++;
+        }
+    }
+    return 0;
+}
+
 static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
     int tag;
@@ -1596,23 +1616,21 @@  static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
     if (is_cover_image(track->st))
         return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id);
 
-    if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
-        tag = track->par->codec_tag;
-    else if (track->mode == MODE_ISM)
-        tag = track->par->codec_tag;
-    else if (track->mode == MODE_IPOD) {
+    if (track->mode == MODE_IPOD)
         if (!av_match_ext(s->url, "m4a") &&
             !av_match_ext(s->url, "m4v") &&
             !av_match_ext(s->url, "m4b"))
             av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v "
                    "Quicktime/Ipod might not play the file\n");
-        tag = track->par->codec_tag;
-    } else if (track->mode & MODE_3GP)
-        tag = track->par->codec_tag;
-    else if (track->mode == MODE_F4V)
-        tag = track->par->codec_tag;
-    else
+
+    if (track->mode == MODE_MOV)
         tag = mov_get_codec_tag(s, track);
+    else
+        if (!validate_codec_tag(s->oformat->codec_tag, track->par->codec_tag,
+                                track->par->codec_id))
+            tag = 0;
+        else
+            tag = track->par->codec_tag;
 
     return tag;
 }