From 2acc89d321bf0d1ea4bc08bc4620f165cb7e65f3 Mon Sep 17 00:00:00 2001
From: Frank Galligan <fgalligan@google.com>
Date: Fri, 10 May 2019 17:42:46 -0700
Subject: [PATCH] Check there is only one settings per ContentCompression

This fixes a memory leak with invalid files.

BUG: 127702368

Merged-In: Id7de1f8c35ef2f6458c6fb6c7751a84fe43ed1cc
Change-Id: I73bd34e212d74ffcf8d428e01b5269037147bf8c
(cherry picked from commit 0fbbf3c3e05647aa10174a1876e02ba6a2ec631d)
---
 libwebm/mkvparser.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libwebm/mkvparser.cpp b/libwebm/mkvparser.cpp
index f0cd97f..e65e9c7 100644
--- a/libwebm/mkvparser.cpp
+++ b/libwebm/mkvparser.cpp
@@ -4284,6 +4284,12 @@ long ContentEncoding::ParseCompressionEntry(long long start, long long size,
         return status;
       }
 
+      // There should be only one settings element per content compression.
+      if (compression->settings != NULL) {
+        delete[] buf;
+        return E_FILE_FORMAT_INVALID;
+      }
+
       compression->settings = buf;
       compression->settings_len = buflen;
     }
