From 560473e0d689f772f7532395bb0a5636875a1c40 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Mon, 26 Aug 2019 17:12:34 -0400
Subject: [PATCH] decoder: properly initialize frames

MediaFrame doesn't have a ptr_ or allocated_ fields, so casting it
to VideoFrame and calling VideoFrame::copyFrom causes an invalid read.

Change-Id: Icb1a0a20be04d212357f5eb53d09ed08ab58cde3
---
 src/media/media_decoder.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp
index 830e8c65a6..720ccbfd20 100644
--- a/src/media/media_decoder.cpp
+++ b/src/media/media_decoder.cpp
@@ -333,7 +333,9 @@ MediaDecoder::decode(AVPacket& packet)
         return ret == AVERROR_EOF ? Status::Success : Status::DecodeError;
     }
 
-    auto f = std::make_shared<MediaFrame>();
+    auto f = (inputDecoder_->type == AVMEDIA_TYPE_VIDEO)
+              ? std::static_pointer_cast<MediaFrame>(std::make_shared<VideoFrame>())
+              : std::static_pointer_cast<MediaFrame>(std::make_shared<AudioFrame>());
     auto frame = f->pointer();
     ret = avcodec_receive_frame(decoderCtx_, frame);
     if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
-- 
GitLab