diff mbox

[FFmpeg-devel] Fix handling of unknown length case for matroska files.

Message ID CAPUDrwe1QVaQjdMLPn9n1PpG5h=m9yHRCsnj-Xtnn5qoRxDyBg@mail.gmail.com
State New
Headers show

Commit Message

Dale Curtis Feb. 22, 2019, 11:41 p.m. UTC
Unknown length has a special encoding which is not uint64_t(-1).

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavformat/matroskadec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Steve Lhomme Feb. 23, 2019, 4:54 p.m. UTC | #1
On 23/02/2019 00:41, Dale Curtis wrote:
> Unknown length has a special encoding which is not uint64_t(-1).
>
> Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
> ---
>   libavformat/matroskadec.c | 13 ++++++++-----
>   1 file changed, 8 insertions(+), 5 deletions(-)
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Ah sorry, I didn't see you proposed the same thing.
diff mbox

Patch

From 2bf28a1edb54297f44021771b4c3d847c1f923f4 Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Fri, 22 Feb 2019 15:39:25 -0800
Subject: [PATCH] Fix handling of unknown length case for matroska files.

Unknown length has a special encoding which is not uint64_t(-1).

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavformat/matroskadec.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 5aa8a105dc..6d86342016 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -68,6 +68,9 @@ 
 
 #include "qtpalette.h"
 
+// 2^56 - 1.
+#define EBML_UNKNOWN_LEN 0xffffffffffffffULL
+
 typedef enum {
     EBML_NONE,
     EBML_UINT,
@@ -869,7 +872,7 @@  static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb,
 {
     int res = ebml_read_num(matroska, pb, 8, number);
     if (res > 0 && *number + 1 == 1ULL << (7 * res))
-        *number = 0xffffffffffffffULL;
+        *number = EBML_UNKNOWN_LEN;
     return res;
 }
 
@@ -1049,7 +1052,7 @@  static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
             break;
     if (!syntax[i].id && id == MATROSKA_ID_CLUSTER &&
         matroska->num_levels > 0                   &&
-        matroska->levels[matroska->num_levels - 1].length == 0xffffffffffffff)
+        matroska->levels[matroska->num_levels - 1].length == EBML_UNKNOWN_LEN)
         return 0;  // we reached the end of an unknown size cluster
     if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32) {
         av_log(matroska->ctx, AV_LOG_DEBUG, "Unknown entry 0x%"PRIX32"\n", id);
@@ -1201,7 +1204,7 @@  static int ebml_parse_elem(MatroskaDemuxContext *matroska,
             MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
             AVIOContext *pb = matroska->ctx->pb;
             int64_t pos = avio_tell(pb);
-            if (level->length != (uint64_t) -1 &&
+            if (level->length != EBML_UNKNOWN_LEN &&
                 (pos + length) > (level->start + level->length)) {
                 av_log(matroska->ctx, AV_LOG_ERROR,
                        "Invalid length 0x%"PRIx64" > 0x%"PRIx64" in parent\n",
@@ -1610,7 +1613,7 @@  static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
             ret = AVERROR_INVALIDDATA;
         } else {
             level.start  = 0;
-            level.length = (uint64_t) -1;
+            level.length = EBML_UNKNOWN_LEN;
             matroska->levels[matroska->num_levels] = level;
             matroska->num_levels++;
             matroska->current_id                   = 0;
@@ -1620,7 +1623,7 @@  static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska,
             /* remove dummy level */
             while (matroska->num_levels) {
                 uint64_t length = matroska->levels[--matroska->num_levels].length;
-                if (length == (uint64_t) -1)
+                if (length == EBML_UNKNOWN_LEN)
                     break;
             }
         }
-- 
2.21.0.rc0.258.g878e2cd30e-goog