diff mbox series

[FFmpeg-devel] avformat/matroskadec: parse all BlockAdditionMapping elements and export the correct value as BlockAdditional side data

Message ID 20230405152610.5872-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avformat/matroskadec: parse all BlockAdditionMapping elements and export the correct value as BlockAdditional side data | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer April 5, 2023, 3:26 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c | 47 +++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 7 deletions(-)

Comments

James Almer April 7, 2023, 1:58 p.m. UTC | #1
On 4/5/2023 12:26 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavformat/matroskadec.c | 47 +++++++++++++++++++++++++++++++++------
>   1 file changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 3c7c2b7c70..175fad6144 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2392,17 +2392,23 @@ static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
>           MatroskaBlockAdditionMapping *mapping = &mappings[i];
>   
>           switch (mapping->type) {
> +        case MATROSKA_BLOCK_ADD_ID_TYPE_DEFAULT:
> +            av_log(s, AV_LOG_DEBUG,
> +                   "Explicit block Addition Mapping type \"Use BlockAddIDValue\", value %"PRIu64","
> +                   " name \"%s\" found.\n", mapping->value, mapping->name ? mapping->name : "");
> +            break;
> +        case MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE:
>           case MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35:
> -            if (mapping->value != MATROSKA_BLOCK_ADD_ID_ITU_T_T35) {
> +            if (mapping->value != mapping->type) {
>                   int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
>                   av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
>                          "Invalid Block Addition Value 0x%"PRIx64" for Block Addition Mapping Type "
> -                       "\"ITU T.35 metadata\"\n", mapping->value);
> -                if (!strict)
> -                    break;
> -                return AVERROR_INVALIDDATA;
> +                       "0x%"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
> +                       mapping->name ? mapping->name : "");
> +                if (strict)
> +                    return AVERROR_INVALIDDATA;
>               }
> -            track->blockaddid_itu_t_t35 = 1;
> +            track->blockaddid_itu_t_t35 |= mapping->type == MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35;
>               break;
>           case MATROSKA_BLOCK_ADD_ID_TYPE_DVCC:
>           case MATROSKA_BLOCK_ADD_ID_TYPE_DVVC:
> @@ -2412,8 +2418,18 @@ static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
>               break;
>           default:
>               av_log(s, AV_LOG_DEBUG,
> -                   "Unknown block additional mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
> +                   "Unknown Block Addition Mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
>                      mapping->type, mapping->value, mapping->name ? mapping->name : "");
> +            if (mapping->value < 2) {
> +                int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
> +                av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
> +                       "Invalid Block Addition value 0x%"PRIu64" for unknown Block Addition Mapping "
> +                       "type %"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
> +                       mapping->name ? mapping->name : "");
> +                if (strict)
> +                    return AVERROR_INVALIDDATA;
> +            }
> +            break;
>           }
>       }
>   
> @@ -3638,6 +3654,8 @@ static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
>                                              MatroskaTrack *track, AVPacket *pkt,
>                                              const uint8_t *data, int size, uint64_t id)
>   {
> +    const EbmlList *mappings_list = &track->block_addition_mappings;
> +    MatroskaBlockAdditionMapping *mappings = mappings_list->elem, *mapping = NULL;
>       uint8_t *side_data;
>       int res;
>   
> @@ -3685,6 +3703,21 @@ static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
>           break;
>       }
>   
> +    for (int i = 0; i < mappings_list->nb_elem; i++) {
> +        if (id != mappings[i].value)
> +            continue;
> +        mapping = &mappings[i];
> +        break;
> +    }
> +
> +    if (id != 1 && !matroska->is_webm && !mapping) {
> +        av_log(matroska->ctx, AV_LOG_WARNING, "BlockAddID %"PRIu64" has no mapping. Skipping\n", id);
> +        return 0;
> +    }
> +
> +    if (mapping && mapping->type)
> +        id = mapping->type;
> +
>       side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
>                                           size + (size_t)8);
>       if (!side_data)

Will apply.
diff mbox series

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 3c7c2b7c70..175fad6144 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2392,17 +2392,23 @@  static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
         MatroskaBlockAdditionMapping *mapping = &mappings[i];
 
         switch (mapping->type) {
+        case MATROSKA_BLOCK_ADD_ID_TYPE_DEFAULT:
+            av_log(s, AV_LOG_DEBUG,
+                   "Explicit block Addition Mapping type \"Use BlockAddIDValue\", value %"PRIu64","
+                   " name \"%s\" found.\n", mapping->value, mapping->name ? mapping->name : "");
+            break;
+        case MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE:
         case MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35:
-            if (mapping->value != MATROSKA_BLOCK_ADD_ID_ITU_T_T35) {
+            if (mapping->value != mapping->type) {
                 int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
                 av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
                        "Invalid Block Addition Value 0x%"PRIx64" for Block Addition Mapping Type "
-                       "\"ITU T.35 metadata\"\n", mapping->value);
-                if (!strict)
-                    break;
-                return AVERROR_INVALIDDATA;
+                       "0x%"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
+                       mapping->name ? mapping->name : "");
+                if (strict)
+                    return AVERROR_INVALIDDATA;
             }
-            track->blockaddid_itu_t_t35 = 1;
+            track->blockaddid_itu_t_t35 |= mapping->type == MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35;
             break;
         case MATROSKA_BLOCK_ADD_ID_TYPE_DVCC:
         case MATROSKA_BLOCK_ADD_ID_TYPE_DVVC:
@@ -2412,8 +2418,18 @@  static int mkv_parse_block_addition_mappings(AVFormatContext *s, AVStream *st, M
             break;
         default:
             av_log(s, AV_LOG_DEBUG,
-                   "Unknown block additional mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
+                   "Unknown Block Addition Mapping type 0x%"PRIx64", value %"PRIu64", name \"%s\"\n",
                    mapping->type, mapping->value, mapping->name ? mapping->name : "");
+            if (mapping->value < 2) {
+                int strict = s->strict_std_compliance >= FF_COMPLIANCE_STRICT;
+                av_log(s, strict ? AV_LOG_ERROR : AV_LOG_WARNING,
+                       "Invalid Block Addition value 0x%"PRIu64" for unknown Block Addition Mapping "
+                       "type %"PRIx64", name \"%s\"\n", mapping->value, mapping->type,
+                       mapping->name ? mapping->name : "");
+                if (strict)
+                    return AVERROR_INVALIDDATA;
+            }
+            break;
         }
     }
 
@@ -3638,6 +3654,8 @@  static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
                                            MatroskaTrack *track, AVPacket *pkt,
                                            const uint8_t *data, int size, uint64_t id)
 {
+    const EbmlList *mappings_list = &track->block_addition_mappings;
+    MatroskaBlockAdditionMapping *mappings = mappings_list->elem, *mapping = NULL;
     uint8_t *side_data;
     int res;
 
@@ -3685,6 +3703,21 @@  static int matroska_parse_block_additional(MatroskaDemuxContext *matroska,
         break;
     }
 
+    for (int i = 0; i < mappings_list->nb_elem; i++) {
+        if (id != mappings[i].value)
+            continue;
+        mapping = &mappings[i];
+        break;
+    }
+
+    if (id != 1 && !matroska->is_webm && !mapping) {
+        av_log(matroska->ctx, AV_LOG_WARNING, "BlockAddID %"PRIu64" has no mapping. Skipping\n", id);
+        return 0;
+    }
+
+    if (mapping && mapping->type)
+        id = mapping->type;
+
     side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
                                         size + (size_t)8);
     if (!side_data)