webm2pes: avoid null deref w/track->GetCodecId()

check pointer value before converting to string

fixes CVE-2018-19212

BUG=webm:1605

Change-Id: Idbe51dc8e0e454019003ba1ac7afa175f7bf8950
diff --git a/m2ts/webm2pes.cc b/m2ts/webm2pes.cc
index f510acf..fc4b314 100644
--- a/m2ts/webm2pes.cc
+++ b/m2ts/webm2pes.cc
@@ -20,6 +20,14 @@
 
 const std::size_t Webm2Pes::kMaxPayloadSize = 32768;
 
+namespace {
+
+std::string ToString(const char* str) {
+  return std::string((str == nullptr) ? "" : str);
+}
+
+}  // namespace
+
 //
 // PesOptionalHeader methods.
 //
@@ -382,9 +390,10 @@
        ++track_index) {
     const mkvparser::Track* track = tracks->GetTrackByIndex(track_index);
     if (track && track->GetType() == mkvparser::Track::kVideo) {
-      if (std::string(track->GetCodecId()) == std::string("V_VP8")) {
+      const std::string codec_id = ToString(track->GetCodecId());
+      if (codec_id == std::string("V_VP8")) {
         codec_ = VideoFrame::kVP8;
-      } else if (std::string(track->GetCodecId()) == std::string("V_VP9")) {
+      } else if (codec_id == std::string("V_VP9")) {
         codec_ = VideoFrame::kVP9;
       } else {
         fprintf(stderr, "Webm2Pes: Codec must be VP8 or VP9.\n");