bug fix. huge memory usages for matroska file with errors 23/262023/9 accepted/tizen_6.5_unified tizen_6.5 accepted/tizen/6.5/unified/20211029.012654 accepted/tizen/unified/20210804.122502 submit/tizen/20210803.020242 submit/tizen/20210804.005008 submit/tizen_6.5/20211028.163401 tizen_6.5.m2_release
authorJiyong Min <jiyong.min@samsung.com>
Mon, 2 Aug 2021 00:41:03 +0000 (09:41 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Mon, 2 Aug 2021 07:18:38 +0000 (16:18 +0900)
[Cause]
  According to the current specifications for matroska,
  it needs to be parsed to the end of the file when tag has no length.
  If a normal tag does not appear immediately, unnecessary memory
  for embl list is used to read the the end of the file.
[Solution]
  To avoid huge memory usages, return error for unknown-length tags.

Change-Id: I756419ddb3b42af423dbf0aace2e9df5e9f21f1d

libavformat/matroskadec.c

index 201fb85..9de1adc 100644 (file)
@@ -1277,7 +1277,11 @@ static int ebml_parse(MatroskaDemuxContext *matroska,
             return res;
 
 #ifdef FIX_CRASH_ISSUE_FOR_INVALID_FILE
-        if((length == 0xffffffffffffffULL) && (matroska->is_parse_header_finish == 0)) {
+        if ((length == 0xffffffffffffffULL || length == EBML_UNKNOWN_LENGTH) &&
+            (matroska->is_parse_header_finish == 0)) {
+            av_log(matroska->ctx, AV_LOG_WARNING,
+                   "Found invalid length 0x%"PRIx64" element 0x%"PRIX32" at 0x%"PRIx64"."
+                   "Return error for invalid length\n", length, id, pos);
             av_log(matroska->ctx, AV_LOG_ERROR, "WE DETECTED THIS CONTENT IS A TORRENT FILE!!!\n");
             return AVERROR_INVALIDDATA;
         }