Blame SOURCES/0003-CVE-2019-9371-update-libwebm.patch

44b363
From ca1647dda267762c03c8641d2c605a9853a8ac59 Mon Sep 17 00:00:00 2001
44b363
From: Johann <johannkoenig@google.com>
44b363
Date: Tue, 24 Apr 2018 15:22:28 -0700
44b363
Subject: [PATCH 3/4] CVE-2019-9371: update libwebm
44b363
44b363
update libwebm to libwebm-1.0.0.27-358-gdbf1d10
44b363
---
44b363
 configure                                    |  8 +-
44b363
 third_party/libwebm/AUTHORS.TXT              |  8 +-
44b363
 third_party/libwebm/Android.mk               |  2 +-
44b363
 third_party/libwebm/README.libvpx            | 14 +++-
44b363
 third_party/libwebm/common/file_util.cc      | 19 ++++-
44b363
 third_party/libwebm/common/file_util.h       |  5 +-
44b363
 third_party/libwebm/common/hdr_util.cc       |  8 +-
44b363
 third_party/libwebm/common/hdr_util.h        | 10 +--
44b363
 third_party/libwebm/common/webmids.h         |  1 +
44b363
 third_party/libwebm/mkvmuxer/mkvmuxer.cc     | 77 +++++++++++++-------
44b363
 third_party/libwebm/mkvmuxer/mkvmuxer.h      |  5 +-
44b363
 third_party/libwebm/mkvmuxer/mkvmuxerutil.cc | 13 ++--
44b363
 third_party/libwebm/mkvmuxer/mkvmuxerutil.h  |  3 +
44b363
 third_party/libwebm/mkvmuxer/mkvwriter.cc    |  2 +
44b363
 third_party/libwebm/mkvparser/mkvparser.cc   | 64 +++++++++++-----
44b363
 third_party/libwebm/mkvparser/mkvparser.h    |  6 +-
44b363
 third_party/libwebm/mkvparser/mkvreader.cc   |  2 +
44b363
 17 files changed, 165 insertions(+), 82 deletions(-)
44b363
44b363
diff --git a/configure b/configure
44b363
index e5a74c6f2..56d203e6b 100755
44b363
--- a/configure
44b363
+++ b/configure
44b363
@@ -703,9 +703,7 @@ process_toolchain() {
44b363
             check_cxx "$@" <
44b363
 int z;
44b363
 EOF
44b363
-            check_cxx "$@" <
44b363
-int z;
44b363
-EOF
44b363
+            check_add_cxx_flags -std=c++11 && soft_enable webm_io
44b363
             check_cxx "$@" <
44b363
 int z;
44b363
 EOF
44b363
@@ -714,9 +712,7 @@ EOF
44b363
             enabled pthread_h && check_cxx "$@" <
44b363
 int z;
44b363
 EOF
44b363
-            check_cxx "$@" <
44b363
-int z;
44b363
-EOF
44b363
+            check_add_cxx_flags -std=c++11 && soft_enable webm_io
44b363
             check_cxx "$@" <
44b363
 int z;
44b363
 EOF
44b363
diff --git a/third_party/libwebm/AUTHORS.TXT b/third_party/libwebm/AUTHORS.TXT
44b363
index 8ab6f794c..9686ac13e 100644
44b363
--- a/third_party/libwebm/AUTHORS.TXT
44b363
+++ b/third_party/libwebm/AUTHORS.TXT
44b363
@@ -1,4 +1,4 @@
44b363
-# Names should be added to this file like so:
44b363
-# Name or Organization <email address>
44b363
-
44b363
-Google Inc.
44b363
+# Names should be added to this file like so:
44b363
+# Name or Organization <email address>
44b363
+
44b363
+Google Inc.
44b363
diff --git a/third_party/libwebm/Android.mk b/third_party/libwebm/Android.mk
44b363
index 8149a083f..b46ba101d 100644
44b363
--- a/third_party/libwebm/Android.mk
44b363
+++ b/third_party/libwebm/Android.mk
44b363
@@ -3,7 +3,7 @@ LOCAL_PATH:= $(call my-dir)
44b363
 include $(CLEAR_VARS)
44b363
 LOCAL_MODULE:= libwebm
44b363
 LOCAL_CPPFLAGS:=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
44b363
-LOCAL_CPPFLAGS+=-D__STDC_LIMIT_MACROS -Wno-extern-c-compat
44b363
+LOCAL_CPPFLAGS+=-D__STDC_LIMIT_MACROS -std=c++11
44b363
 LOCAL_C_INCLUDES:= $(LOCAL_PATH)
44b363
 LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)
44b363
 
44b363
diff --git a/third_party/libwebm/README.libvpx b/third_party/libwebm/README.libvpx
44b363
index ebb5ff2f4..16f17513e 100644
44b363
--- a/third_party/libwebm/README.libvpx
44b363
+++ b/third_party/libwebm/README.libvpx
44b363
@@ -1,5 +1,5 @@
44b363
 URL: https://chromium.googlesource.com/webm/libwebm
44b363
-Version: 0ae757087f5e6eb01dfea16cc09205b2425cfb74
44b363
+Version: dbf1d1089756e7cb5b1a04d6752310ef35912347
44b363
 License: BSD
44b363
 License File: LICENSE.txt
44b363
 
44b363
@@ -7,4 +7,14 @@ Description:
44b363
 libwebm is used to handle WebM container I/O.
44b363
 
44b363
 Local Changes:
44b363
-* <none>
44b363
+Only keep:
44b363
+ - Android.mk
44b363
+ - AUTHORS.TXT
44b363
+ - common/
44b363
+    file_util.cc/h
44b363
+    hdr_util.cc/h
44b363
+    webmids.h
44b363
+ - LICENSE.TXT
44b363
+ - mkvmuxer/
44b363
+ - mkvparser/
44b363
+ - PATENTS.TXT
44b363
diff --git a/third_party/libwebm/common/file_util.cc b/third_party/libwebm/common/file_util.cc
44b363
index 6dab146dd..6eb6428b9 100644
44b363
--- a/third_party/libwebm/common/file_util.cc
44b363
+++ b/third_party/libwebm/common/file_util.cc
44b363
@@ -17,14 +17,15 @@
44b363
 #include <cstring>
44b363
 #include <fstream>
44b363
 #include <ios>
44b363
+#include <string>
44b363
 
44b363
 namespace libwebm {
44b363
 
44b363
 std::string GetTempFileName() {
44b363
 #if !defined _MSC_VER && !defined __MINGW32__
44b363
   std::string temp_file_name_template_str =
44b363
-      std::string(std::getenv("TEST_TMPDIR") ? std::getenv("TEST_TMPDIR") :
44b363
-                                               ".") +
44b363
+      std::string(std::getenv("TEST_TMPDIR") ? std::getenv("TEST_TMPDIR")
44b363
+                                             : ".") +
44b363
       "/libwebm_temp.XXXXXX";
44b363
   char* temp_file_name_template =
44b363
       new char[temp_file_name_template_str.length() + 1];
44b363
@@ -41,7 +42,12 @@ std::string GetTempFileName() {
44b363
   return temp_file_name;
44b363
 #else
44b363
   char tmp_file_name[_MAX_PATH];
44b363
+#if defined _MSC_VER || defined MINGW_HAS_SECURE_API
44b363
   errno_t err = tmpnam_s(tmp_file_name);
44b363
+#else
44b363
+  char* fname_pointer = tmpnam(tmp_file_name);
44b363
+  int err = (fname_pointer == &tmp_file_name[0]) ? 0 : -1;
44b363
+#endif
44b363
   if (err == 0) {
44b363
     return std::string(tmp_file_name);
44b363
   }
44b363
@@ -65,6 +71,15 @@ uint64_t GetFileSize(const std::string& file_name) {
44b363
   return file_size;
44b363
 }
44b363
 
44b363
+bool GetFileContents(const std::string& file_name, std::string* contents) {
44b363
+  std::ifstream file(file_name.c_str());
44b363
+  *contents = std::string(static_cast<size_t>(GetFileSize(file_name)), 0);
44b363
+  if (file.good() && contents->size()) {
44b363
+    file.read(&(*contents)[0], contents->size());
44b363
+  }
44b363
+  return !file.fail();
44b363
+}
44b363
+
44b363
 TempFileDeleter::TempFileDeleter() { file_name_ = GetTempFileName(); }
44b363
 
44b363
 TempFileDeleter::~TempFileDeleter() {
44b363
diff --git a/third_party/libwebm/common/file_util.h b/third_party/libwebm/common/file_util.h
44b363
index 0e71eac11..a87373464 100644
44b363
--- a/third_party/libwebm/common/file_util.h
44b363
+++ b/third_party/libwebm/common/file_util.h
44b363
@@ -22,6 +22,9 @@ std::string GetTempFileName();
44b363
 // Returns size of file specified by |file_name|, or 0 upon failure.
44b363
 uint64_t GetFileSize(const std::string& file_name);
44b363
 
44b363
+// Gets the contents file_name as a string. Returns false on error.
44b363
+bool GetFileContents(const std::string& file_name, std::string* contents);
44b363
+
44b363
 // Manages life of temporary file specified at time of construction. Deletes
44b363
 // file upon destruction.
44b363
 class TempFileDeleter {
44b363
@@ -38,4 +41,4 @@ class TempFileDeleter {
44b363
 
44b363
 }  // namespace libwebm
44b363
 
44b363
-#endif  // LIBWEBM_COMMON_FILE_UTIL_H_
44b363
\ No newline at end of file
44b363
+#endif  // LIBWEBM_COMMON_FILE_UTIL_H_
44b363
diff --git a/third_party/libwebm/common/hdr_util.cc b/third_party/libwebm/common/hdr_util.cc
44b363
index e1618ce75..916f7170b 100644
44b363
--- a/third_party/libwebm/common/hdr_util.cc
44b363
+++ b/third_party/libwebm/common/hdr_util.cc
44b363
@@ -36,10 +36,10 @@ bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
44b363
   if (MasteringMetadataValuePresent(parser_mm.luminance_min))
44b363
     muxer_mm->set_luminance_min(parser_mm.luminance_min);
44b363
 
44b363
-  PrimaryChromaticityPtr r_ptr(NULL);
44b363
-  PrimaryChromaticityPtr g_ptr(NULL);
44b363
-  PrimaryChromaticityPtr b_ptr(NULL);
44b363
-  PrimaryChromaticityPtr wp_ptr(NULL);
44b363
+  PrimaryChromaticityPtr r_ptr(nullptr);
44b363
+  PrimaryChromaticityPtr g_ptr(nullptr);
44b363
+  PrimaryChromaticityPtr b_ptr(nullptr);
44b363
+  PrimaryChromaticityPtr wp_ptr(nullptr);
44b363
 
44b363
   if (parser_mm.r) {
44b363
     if (!CopyPrimaryChromaticity(*parser_mm.r, &r_ptr))
44b363
diff --git a/third_party/libwebm/common/hdr_util.h b/third_party/libwebm/common/hdr_util.h
44b363
index 3ef5388fd..78e2eeb70 100644
44b363
--- a/third_party/libwebm/common/hdr_util.h
44b363
+++ b/third_party/libwebm/common/hdr_util.h
44b363
@@ -47,15 +47,7 @@ struct Vp9CodecFeatures {
44b363
   int chroma_subsampling;
44b363
 };
44b363
 
44b363
-// disable deprecation warnings for auto_ptr
44b363
-#if defined(__GNUC__) && __GNUC__ >= 5
44b363
-#pragma GCC diagnostic push
44b363
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44b363
-#endif
44b363
-typedef std::auto_ptr<mkvmuxer::PrimaryChromaticity> PrimaryChromaticityPtr;
44b363
-#if defined(__GNUC__) && __GNUC__ >= 5
44b363
-#pragma GCC diagnostic pop
44b363
-#endif
44b363
+typedef std::unique_ptr<mkvmuxer::PrimaryChromaticity> PrimaryChromaticityPtr;
44b363
 
44b363
 bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
44b363
                              PrimaryChromaticityPtr* muxer_pc);
44b363
diff --git a/third_party/libwebm/common/webmids.h b/third_party/libwebm/common/webmids.h
44b363
index 89d722a71..fc0c20814 100644
44b363
--- a/third_party/libwebm/common/webmids.h
44b363
+++ b/third_party/libwebm/common/webmids.h
44b363
@@ -93,6 +93,7 @@ enum MkvId {
44b363
   kMkvDisplayHeight = 0x54BA,
44b363
   kMkvDisplayUnit = 0x54B2,
44b363
   kMkvAspectRatioType = 0x54B3,
44b363
+  kMkvColourSpace = 0x2EB524,
44b363
   kMkvFrameRate = 0x2383E3,
44b363
   // end video
44b363
   // colour
44b363
diff --git a/third_party/libwebm/mkvmuxer/mkvmuxer.cc b/third_party/libwebm/mkvmuxer/mkvmuxer.cc
44b363
index 15b9a908d..512031211 100644
44b363
--- a/third_party/libwebm/mkvmuxer/mkvmuxer.cc
44b363
+++ b/third_party/libwebm/mkvmuxer/mkvmuxer.cc
44b363
@@ -8,6 +8,8 @@
44b363
 
44b363
 #include "mkvmuxer/mkvmuxer.h"
44b363
 
44b363
+#include <stdint.h>
44b363
+
44b363
 #include <cfloat>
44b363
 #include <climits>
44b363
 #include <cstdio>
44b363
@@ -24,11 +26,6 @@
44b363
 #include "mkvmuxer/mkvwriter.h"
44b363
 #include "mkvparser/mkvparser.h"
44b363
 
44b363
-// disable deprecation warnings for auto_ptr
44b363
-#if defined(__GNUC__) && __GNUC__ >= 5
44b363
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44b363
-#endif
44b363
-
44b363
 namespace mkvmuxer {
44b363
 
44b363
 const float PrimaryChromaticity::kChromaticityMin = 0.0f;
44b363
@@ -72,7 +69,7 @@ bool StrCpy(const char* src, char** dst_ptr) {
44b363
   return true;
44b363
 }
44b363
 
44b363
-typedef std::auto_ptr<PrimaryChromaticity> PrimaryChromaticityPtr;
44b363
+typedef std::unique_ptr<PrimaryChromaticity> PrimaryChromaticityPtr;
44b363
 bool CopyChromaticity(const PrimaryChromaticity* src,
44b363
                       PrimaryChromaticityPtr* dst) {
44b363
   if (!dst)
44b363
@@ -776,6 +773,14 @@ bool Track::Write(IMkvWriter* writer) const {
44b363
   if (!type_ || !codec_id_)
44b363
     return false;
44b363
 
44b363
+  // AV1 tracks require a CodecPrivate. See
44b363
+  // https://github.com/Matroska-Org/matroska-specification/blob/av1-mappin/codec/av1.md
44b363
+  // TODO(tomfinegan): Update the above link to the AV1 Matroska mappings to
44b363
+  // point to a stable version once it is finalized, or our own WebM mappings
44b363
+  // page on webmproject.org should we decide to release them.
44b363
+  if (!strcmp(codec_id_, Tracks::kAv1CodecId) && !codec_private_)
44b363
+    return false;
44b363
+
44b363
   // |size| may be bigger than what is written out in this function because
44b363
   // derived classes may write out more data in the Track element.
44b363
   const uint64_t payload_size = PayloadSize();
44b363
@@ -1030,19 +1035,16 @@ bool MasteringMetadata::Write(IMkvWriter* writer) const {
44b363
       !WriteEbmlElement(writer, libwebm::kMkvLuminanceMin, luminance_min_)) {
44b363
     return false;
44b363
   }
44b363
-  if (r_ &&
44b363
-      !r_->Write(writer, libwebm::kMkvPrimaryRChromaticityX,
44b363
-                 libwebm::kMkvPrimaryRChromaticityY)) {
44b363
+  if (r_ && !r_->Write(writer, libwebm::kMkvPrimaryRChromaticityX,
44b363
+                       libwebm::kMkvPrimaryRChromaticityY)) {
44b363
     return false;
44b363
   }
44b363
-  if (g_ &&
44b363
-      !g_->Write(writer, libwebm::kMkvPrimaryGChromaticityX,
44b363
-                 libwebm::kMkvPrimaryGChromaticityY)) {
44b363
+  if (g_ && !g_->Write(writer, libwebm::kMkvPrimaryGChromaticityX,
44b363
+                       libwebm::kMkvPrimaryGChromaticityY)) {
44b363
     return false;
44b363
   }
44b363
-  if (b_ &&
44b363
-      !b_->Write(writer, libwebm::kMkvPrimaryBChromaticityX,
44b363
-                 libwebm::kMkvPrimaryBChromaticityY)) {
44b363
+  if (b_ && !b_->Write(writer, libwebm::kMkvPrimaryBChromaticityX,
44b363
+                       libwebm::kMkvPrimaryBChromaticityY)) {
44b363
     return false;
44b363
   }
44b363
   if (white_point_ &&
44b363
@@ -1057,22 +1059,22 @@ bool MasteringMetadata::Write(IMkvWriter* writer) const {
44b363
 bool MasteringMetadata::SetChromaticity(
44b363
     const PrimaryChromaticity* r, const PrimaryChromaticity* g,
44b363
     const PrimaryChromaticity* b, const PrimaryChromaticity* white_point) {
44b363
-  PrimaryChromaticityPtr r_ptr(NULL);
44b363
+  PrimaryChromaticityPtr r_ptr(nullptr);
44b363
   if (r) {
44b363
     if (!CopyChromaticity(r, &r_ptr))
44b363
       return false;
44b363
   }
44b363
-  PrimaryChromaticityPtr g_ptr(NULL);
44b363
+  PrimaryChromaticityPtr g_ptr(nullptr);
44b363
   if (g) {
44b363
     if (!CopyChromaticity(g, &g_ptr))
44b363
       return false;
44b363
   }
44b363
-  PrimaryChromaticityPtr b_ptr(NULL);
44b363
+  PrimaryChromaticityPtr b_ptr(nullptr);
44b363
   if (b) {
44b363
     if (!CopyChromaticity(b, &b_ptr))
44b363
       return false;
44b363
   }
44b363
-  PrimaryChromaticityPtr wp_ptr(NULL);
44b363
+  PrimaryChromaticityPtr wp_ptr(nullptr);
44b363
   if (white_point) {
44b363
     if (!CopyChromaticity(white_point, &wp_ptr))
44b363
       return false;
44b363
@@ -1238,7 +1240,7 @@ bool Colour::Write(IMkvWriter* writer) const {
44b363
 }
44b363
 
44b363
 bool Colour::SetMasteringMetadata(const MasteringMetadata& mastering_metadata) {
44b363
-  std::auto_ptr<MasteringMetadata> mm_ptr(new MasteringMetadata());
44b363
+  std::unique_ptr<MasteringMetadata> mm_ptr(new MasteringMetadata());
44b363
   if (!mm_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -1424,6 +1426,7 @@ VideoTrack::VideoTrack(unsigned int* seed)
44b363
       stereo_mode_(0),
44b363
       alpha_mode_(0),
44b363
       width_(0),
44b363
+      colour_space_(NULL),
44b363
       colour_(NULL),
44b363
       projection_(NULL) {}
44b363
 
44b363
@@ -1521,6 +1524,10 @@ bool VideoTrack::Write(IMkvWriter* writer) const {
44b363
                           static_cast<uint64>(alpha_mode_)))
44b363
       return false;
44b363
   }
44b363
+  if (colour_space_) {
44b363
+    if (!WriteEbmlElement(writer, libwebm::kMkvColourSpace, colour_space_))
44b363
+      return false;
44b363
+  }
44b363
   if (frame_rate_ > 0.0) {
44b363
     if (!WriteEbmlElement(writer, libwebm::kMkvFrameRate,
44b363
                           static_cast<float>(frame_rate_))) {
44b363
@@ -1545,8 +1552,24 @@ bool VideoTrack::Write(IMkvWriter* writer) const {
44b363
   return true;
44b363
 }
44b363
 
44b363
+void VideoTrack::set_colour_space(const char* colour_space) {
44b363
+  if (colour_space) {
44b363
+    delete[] colour_space_;
44b363
+
44b363
+    const size_t length = strlen(colour_space) + 1;
44b363
+    colour_space_ = new (std::nothrow) char[length];  // NOLINT
44b363
+    if (colour_space_) {
44b363
+#ifdef _MSC_VER
44b363
+      strcpy_s(colour_space_, length, colour_space);
44b363
+#else
44b363
+      strcpy(colour_space_, colour_space);
44b363
+#endif
44b363
+    }
44b363
+  }
44b363
+}
44b363
+
44b363
 bool VideoTrack::SetColour(const Colour& colour) {
44b363
-  std::auto_ptr<Colour> colour_ptr(new Colour());
44b363
+  std::unique_ptr<Colour> colour_ptr(new Colour());
44b363
   if (!colour_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -1574,7 +1597,7 @@ bool VideoTrack::SetColour(const Colour& colour) {
44b363
 }
44b363
 
44b363
 bool VideoTrack::SetProjection(const Projection& projection) {
44b363
-  std::auto_ptr<Projection> projection_ptr(new Projection());
44b363
+  std::unique_ptr<Projection> projection_ptr(new Projection());
44b363
   if (!projection_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -1628,6 +1651,8 @@ uint64_t VideoTrack::VideoPayloadSize() const {
44b363
   if (frame_rate_ > 0.0)
44b363
     size += EbmlElementSize(libwebm::kMkvFrameRate,
44b363
                             static_cast<float>(frame_rate_));
44b363
+  if (colour_space_)
44b363
+    size += EbmlElementSize(libwebm::kMkvColourSpace, colour_space_);
44b363
   if (colour_)
44b363
     size += colour_->ColourSize();
44b363
   if (projection_)
44b363
@@ -1705,9 +1730,9 @@ bool AudioTrack::Write(IMkvWriter* writer) const {
44b363
 
44b363
 const char Tracks::kOpusCodecId[] = "A_OPUS";
44b363
 const char Tracks::kVorbisCodecId[] = "A_VORBIS";
44b363
+const char Tracks::kAv1CodecId[] = "V_AV1";
44b363
 const char Tracks::kVp8CodecId[] = "V_VP8";
44b363
 const char Tracks::kVp9CodecId[] = "V_VP9";
44b363
-const char Tracks::kVp10CodecId[] = "V_VP10";
44b363
 const char Tracks::kWebVttCaptionsId[] = "D_WEBVTT/CAPTIONS";
44b363
 const char Tracks::kWebVttDescriptionsId[] = "D_WEBVTT/DESCRIPTIONS";
44b363
 const char Tracks::kWebVttMetadataId[] = "D_WEBVTT/METADATA";
44b363
@@ -2666,7 +2691,7 @@ bool Cluster::QueueOrWriteFrame(const Frame* const frame) {
44b363
   // and write it if it is okay to do so (i.e.) no other track has an held back
44b363
   // frame with timestamp <= the timestamp of the frame in question.
44b363
   std::vector<std::list<Frame*>::iterator> frames_to_erase;
44b363
-  for (std::list<Frame *>::iterator
44b363
+  for (std::list<Frame*>::iterator
44b363
            current_track_iterator = stored_frames_[track_number].begin(),
44b363
            end = --stored_frames_[track_number].end();
44b363
        current_track_iterator != end; ++current_track_iterator) {
44b363
@@ -4168,8 +4193,8 @@ bool Segment::DocTypeIsWebm() const {
44b363
   // TODO(vigneshv): Tweak .clang-format.
44b363
   const char* kWebmCodecIds[kNumCodecIds] = {
44b363
       Tracks::kOpusCodecId,          Tracks::kVorbisCodecId,
44b363
-      Tracks::kVp8CodecId,           Tracks::kVp9CodecId,
44b363
-      Tracks::kVp10CodecId,          Tracks::kWebVttCaptionsId,
44b363
+      Tracks::kAv1CodecId,           Tracks::kVp8CodecId,
44b363
+      Tracks::kVp9CodecId,           Tracks::kWebVttCaptionsId,
44b363
       Tracks::kWebVttDescriptionsId, Tracks::kWebVttMetadataId,
44b363
       Tracks::kWebVttSubtitlesId};
44b363
 
44b363
diff --git a/third_party/libwebm/mkvmuxer/mkvmuxer.h b/third_party/libwebm/mkvmuxer/mkvmuxer.h
44b363
index 46b0029dc..f2db37714 100644
44b363
--- a/third_party/libwebm/mkvmuxer/mkvmuxer.h
44b363
+++ b/third_party/libwebm/mkvmuxer/mkvmuxer.h
44b363
@@ -795,6 +795,8 @@ class VideoTrack : public Track {
44b363
   uint64_t alpha_mode() { return alpha_mode_; }
44b363
   void set_width(uint64_t width) { width_ = width; }
44b363
   uint64_t width() const { return width_; }
44b363
+  void set_colour_space(const char* colour_space);
44b363
+  const char* colour_space() const { return colour_space_; }
44b363
 
44b363
   Colour* colour() { return colour_; }
44b363
 
44b363
@@ -824,6 +826,7 @@ class VideoTrack : public Track {
44b363
   uint64_t stereo_mode_;
44b363
   uint64_t alpha_mode_;
44b363
   uint64_t width_;
44b363
+  char* colour_space_;
44b363
 
44b363
   Colour* colour_;
44b363
   Projection* projection_;
44b363
@@ -871,9 +874,9 @@ class Tracks {
44b363
 
44b363
   static const char kOpusCodecId[];
44b363
   static const char kVorbisCodecId[];
44b363
+  static const char kAv1CodecId[];
44b363
   static const char kVp8CodecId[];
44b363
   static const char kVp9CodecId[];
44b363
-  static const char kVp10CodecId[];
44b363
   static const char kWebVttCaptionsId[];
44b363
   static const char kWebVttDescriptionsId[];
44b363
   static const char kWebVttMetadataId[];
44b363
diff --git a/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc b/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc
44b363
index 355d4e22b..7636a9f4e 100644
44b363
--- a/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc
44b363
+++ b/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc
44b363
@@ -136,9 +136,8 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
44b363
     return false;
44b363
   }
44b363
 
44b363
-  if (!frame->is_key() &&
44b363
-      !WriteEbmlElement(writer, libwebm::kMkvReferenceBlock,
44b363
-                        reference_block_timestamp)) {
44b363
+  if (!frame->is_key() && !WriteEbmlElement(writer, libwebm::kMkvReferenceBlock,
44b363
+                                            reference_block_timestamp)) {
44b363
     return false;
44b363
   }
44b363
 
44b363
@@ -563,10 +562,10 @@ uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
44b363
   if (relative_timecode < 0 || relative_timecode > kMaxBlockTimecode)
44b363
     return 0;
44b363
 
44b363
-  return frame->CanBeSimpleBlock() ?
44b363
-             WriteSimpleBlock(writer, frame, relative_timecode) :
44b363
-             WriteBlock(writer, frame, relative_timecode,
44b363
-                        cluster->timecode_scale());
44b363
+  return frame->CanBeSimpleBlock()
44b363
+             ? WriteSimpleBlock(writer, frame, relative_timecode)
44b363
+             : WriteBlock(writer, frame, relative_timecode,
44b363
+                          cluster->timecode_scale());
44b363
 }
44b363
 
44b363
 uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
44b363
diff --git a/third_party/libwebm/mkvmuxer/mkvmuxerutil.h b/third_party/libwebm/mkvmuxer/mkvmuxerutil.h
44b363
index 132388da5..3355428bd 100644
44b363
--- a/third_party/libwebm/mkvmuxer/mkvmuxerutil.h
44b363
+++ b/third_party/libwebm/mkvmuxer/mkvmuxerutil.h
44b363
@@ -31,6 +31,9 @@ const int64 kMaxBlockTimecode = 0x07FFFLL;
44b363
 // Writes out |value| in Big Endian order. Returns 0 on success.
44b363
 int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size);
44b363
 
44b363
+// Writes out |f| in Big Endian order. Returns 0 on success.
44b363
+int32 SerializeFloat(IMkvWriter* writer, float f);
44b363
+
44b363
 // Returns the size in bytes of the element.
44b363
 int32 GetUIntSize(uint64 value);
44b363
 int32 GetIntSize(int64 value);
44b363
diff --git a/third_party/libwebm/mkvmuxer/mkvwriter.cc b/third_party/libwebm/mkvmuxer/mkvwriter.cc
44b363
index 84655d802..d668384d8 100644
44b363
--- a/third_party/libwebm/mkvmuxer/mkvwriter.cc
44b363
+++ b/third_party/libwebm/mkvmuxer/mkvwriter.cc
44b363
@@ -78,6 +78,8 @@ int32 MkvWriter::Position(int64 position) {
44b363
 
44b363
 #ifdef _MSC_VER
44b363
   return _fseeki64(file_, position, SEEK_SET);
44b363
+#elif defined(_WIN32)
44b363
+  return fseeko64(file_, static_cast<off_t>(position), SEEK_SET);
44b363
 #else
44b363
   return fseeko(file_, static_cast<off_t>(position), SEEK_SET);
44b363
 #endif
44b363
diff --git a/third_party/libwebm/mkvparser/mkvparser.cc b/third_party/libwebm/mkvparser/mkvparser.cc
44b363
index 37f230d0a..dcb969dcf 100644
44b363
--- a/third_party/libwebm/mkvparser/mkvparser.cc
44b363
+++ b/third_party/libwebm/mkvparser/mkvparser.cc
44b363
@@ -22,12 +22,8 @@
44b363
 
44b363
 #include "common/webmids.h"
44b363
 
44b363
-// disable deprecation warnings for auto_ptr
44b363
-#if defined(__GNUC__) && __GNUC__ >= 5
44b363
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44b363
-#endif
44b363
-
44b363
 namespace mkvparser {
44b363
+const long long kStringElementSizeLimit = 20 * 1000 * 1000;
44b363
 const float MasteringMetadata::kValueNotPresent = FLT_MAX;
44b363
 const long long Colour::kValueNotPresent = LLONG_MAX;
44b363
 const float Projection::kValueNotPresent = FLT_MAX;
44b363
@@ -40,8 +36,6 @@ inline bool isnan(double val) { return std::isnan(val); }
44b363
 inline bool isinf(double val) { return std::isinf(val); }
44b363
 #endif  // MSC_COMPAT
44b363
 
44b363
-IMkvReader::~IMkvReader() {}
44b363
-
44b363
 template <typename Type>
44b363
 Type* SafeArrayAlloc(unsigned long long num_elements,
44b363
                      unsigned long long element_size) {
44b363
@@ -330,7 +324,7 @@ long UnserializeString(IMkvReader* pReader, long long pos, long long size,
44b363
   delete[] str;
44b363
   str = NULL;
44b363
 
44b363
-  if (size >= LONG_MAX || size < 0)
44b363
+  if (size >= LONG_MAX || size < 0 || size > kStringElementSizeLimit)
44b363
     return E_FILE_FORMAT_INVALID;
44b363
 
44b363
   // +1 for '\0' terminator
44b363
@@ -5015,7 +5009,7 @@ bool MasteringMetadata::Parse(IMkvReader* reader, long long mm_start,
44b363
   if (!reader || *mm)
44b363
     return false;
44b363
 
44b363
-  std::auto_ptr<MasteringMetadata> mm_ptr(new MasteringMetadata());
44b363
+  std::unique_ptr<MasteringMetadata> mm_ptr(new MasteringMetadata());
44b363
   if (!mm_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -5035,6 +5029,10 @@ bool MasteringMetadata::Parse(IMkvReader* reader, long long mm_start,
44b363
       double value = 0;
44b363
       const long long value_parse_status =
44b363
           UnserializeFloat(reader, read_pos, child_size, value);
44b363
+      if (value < -FLT_MAX || value > FLT_MAX ||
44b363
+          (value > 0.0 && value < FLT_MIN)) {
44b363
+        return false;
44b363
+      }
44b363
       mm_ptr->luminance_max = static_cast<float>(value);
44b363
       if (value_parse_status < 0 || mm_ptr->luminance_max < 0.0 ||
44b363
           mm_ptr->luminance_max > 9999.99) {
44b363
@@ -5044,6 +5042,10 @@ bool MasteringMetadata::Parse(IMkvReader* reader, long long mm_start,
44b363
       double value = 0;
44b363
       const long long value_parse_status =
44b363
           UnserializeFloat(reader, read_pos, child_size, value);
44b363
+      if (value < -FLT_MAX || value > FLT_MAX ||
44b363
+          (value > 0.0 && value < FLT_MIN)) {
44b363
+        return false;
44b363
+      }
44b363
       mm_ptr->luminance_min = static_cast<float>(value);
44b363
       if (value_parse_status < 0 || mm_ptr->luminance_min < 0.0 ||
44b363
           mm_ptr->luminance_min > 999.9999) {
44b363
@@ -5096,7 +5098,7 @@ bool Colour::Parse(IMkvReader* reader, long long colour_start,
44b363
   if (!reader || *colour)
44b363
     return false;
44b363
 
44b363
-  std::auto_ptr<Colour> colour_ptr(new Colour());
44b363
+  std::unique_ptr<Colour> colour_ptr(new Colour());
44b363
   if (!colour_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -5194,7 +5196,7 @@ bool Projection::Parse(IMkvReader* reader, long long start, long long size,
44b363
   if (!reader || *projection)
44b363
     return false;
44b363
 
44b363
-  std::auto_ptr<Projection> projection_ptr(new Projection());
44b363
+  std::unique_ptr<Projection> projection_ptr(new Projection());
44b363
   if (!projection_ptr.get())
44b363
     return false;
44b363
 
44b363
@@ -5270,6 +5272,7 @@ bool Projection::Parse(IMkvReader* reader, long long start, long long size,
44b363
 VideoTrack::VideoTrack(Segment* pSegment, long long element_start,
44b363
                        long long element_size)
44b363
     : Track(pSegment, element_start, element_size),
44b363
+      m_colour_space(NULL),
44b363
       m_colour(NULL),
44b363
       m_projection(NULL) {}
44b363
 
44b363
@@ -5295,6 +5298,7 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
44b363
   long long stereo_mode = 0;
44b363
 
44b363
   double rate = 0.0;
44b363
+  char* colour_space = NULL;
44b363
 
44b363
   IMkvReader* const pReader = pSegment->m_pReader;
44b363
 
44b363
@@ -5307,8 +5311,8 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
44b363
 
44b363
   const long long stop = pos + s.size;
44b363
 
44b363
-  Colour* colour = NULL;
44b363
-  Projection* projection = NULL;
44b363
+  std::unique_ptr<Colour> colour_ptr;
44b363
+  std::unique_ptr<Projection> projection_ptr;
44b363
 
44b363
   while (pos < stop) {
44b363
     long long id, size;
44b363
@@ -5357,11 +5361,23 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
44b363
       if (rate <= 0)
44b363
         return E_FILE_FORMAT_INVALID;
44b363
     } else if (id == libwebm::kMkvColour) {
44b363
-      if (!Colour::Parse(pReader, pos, size, &colour))
44b363
+      Colour* colour = NULL;
44b363
+      if (!Colour::Parse(pReader, pos, size, &colour)) {
44b363
         return E_FILE_FORMAT_INVALID;
44b363
+      } else {
44b363
+        colour_ptr.reset(colour);
44b363
+      }
44b363
     } else if (id == libwebm::kMkvProjection) {
44b363
-      if (!Projection::Parse(pReader, pos, size, &projection))
44b363
+      Projection* projection = NULL;
44b363
+      if (!Projection::Parse(pReader, pos, size, &projection)) {
44b363
         return E_FILE_FORMAT_INVALID;
44b363
+      } else {
44b363
+        projection_ptr.reset(projection);
44b363
+      }
44b363
+    } else if (id == libwebm::kMkvColourSpace) {
44b363
+      const long status = UnserializeString(pReader, pos, size, colour_space);
44b363
+      if (status < 0)
44b363
+        return status;
44b363
     }
44b363
 
44b363
     pos += size;  // consume payload
44b363
@@ -5392,8 +5408,9 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
44b363
   pTrack->m_display_unit = display_unit;
44b363
   pTrack->m_stereo_mode = stereo_mode;
44b363
   pTrack->m_rate = rate;
44b363
-  pTrack->m_colour = colour;
44b363
-  pTrack->m_projection = projection;
44b363
+  pTrack->m_colour = colour_ptr.release();
44b363
+  pTrack->m_colour_space = colour_space;
44b363
+  pTrack->m_projection = projection_ptr.release();
44b363
 
44b363
   pResult = pTrack;
44b363
   return 0;  // success
44b363
@@ -7903,6 +7920,10 @@ long Block::Parse(const Cluster* pCluster) {
44b363
         return E_FILE_FORMAT_INVALID;
44b363
 
44b363
       curr.len = static_cast<long>(frame_size);
44b363
+      // Check if size + curr.len could overflow.
44b363
+      if (size > LLONG_MAX - curr.len) {
44b363
+        return E_FILE_FORMAT_INVALID;
44b363
+      }
44b363
       size += curr.len;  // contribution of this frame
44b363
 
44b363
       --frame_count;
44b363
@@ -7964,6 +7985,11 @@ long long Block::GetTimeCode(const Cluster* pCluster) const {
44b363
   const long long tc0 = pCluster->GetTimeCode();
44b363
   assert(tc0 >= 0);
44b363
 
44b363
+  // Check if tc0 + m_timecode would overflow.
44b363
+  if (tc0 < 0 || LLONG_MAX - tc0 < m_timecode) {
44b363
+    return -1;
44b363
+  }
44b363
+
44b363
   const long long tc = tc0 + m_timecode;
44b363
 
44b363
   return tc;  // unscaled timecode units
44b363
@@ -7981,6 +8007,10 @@ long long Block::GetTime(const Cluster* pCluster) const {
44b363
   const long long scale = pInfo->GetTimeCodeScale();
44b363
   assert(scale >= 1);
44b363
 
44b363
+  // Check if tc * scale could overflow.
44b363
+  if (tc != 0 && scale > LLONG_MAX / tc) {
44b363
+    return -1;
44b363
+  }
44b363
   const long long ns = tc * scale;
44b363
 
44b363
   return ns;
44b363
diff --git a/third_party/libwebm/mkvparser/mkvparser.h b/third_party/libwebm/mkvparser/mkvparser.h
44b363
index 26c2b7e5e..848d01f03 100644
44b363
--- a/third_party/libwebm/mkvparser/mkvparser.h
44b363
+++ b/third_party/libwebm/mkvparser/mkvparser.h
44b363
@@ -22,7 +22,7 @@ class IMkvReader {
44b363
   virtual int Length(long long* total, long long* available) = 0;
44b363
 
44b363
  protected:
44b363
-  virtual ~IMkvReader();
44b363
+  virtual ~IMkvReader() {}
44b363
 };
44b363
 
44b363
 template <typename Type>
44b363
@@ -527,6 +527,8 @@ class VideoTrack : public Track {
44b363
 
44b363
   Projection* GetProjection() const;
44b363
 
44b363
+  const char* GetColourSpace() const { return m_colour_space; }
44b363
+
44b363
  private:
44b363
   long long m_width;
44b363
   long long m_height;
44b363
@@ -534,7 +536,7 @@ class VideoTrack : public Track {
44b363
   long long m_display_height;
44b363
   long long m_display_unit;
44b363
   long long m_stereo_mode;
44b363
-
44b363
+  char* m_colour_space;
44b363
   double m_rate;
44b363
 
44b363
   Colour* m_colour;
44b363
diff --git a/third_party/libwebm/mkvparser/mkvreader.cc b/third_party/libwebm/mkvparser/mkvreader.cc
44b363
index 23d68f508..9d19c1be5 100644
44b363
--- a/third_party/libwebm/mkvparser/mkvreader.cc
44b363
+++ b/third_party/libwebm/mkvparser/mkvreader.cc
44b363
@@ -118,6 +118,8 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
44b363
 
44b363
   if (status)
44b363
     return -1;  // error
44b363
+#elif defined(_WIN32)
44b363
+  fseeko64(m_file, static_cast<off_t>(offset), SEEK_SET);
44b363
 #else
44b363
   fseeko(m_file, static_cast<off_t>(offset), SEEK_SET);
44b363
 #endif
44b363
-- 
44b363
2.25.1
44b363