From dba798798b47b1231fdcca9cab748f18fbccf443 Mon Sep 17 00:00:00 2001 From: Sergio Garcia Murillo Date: Sat, 25 Apr 2020 23:09:48 +0200 Subject: [PATCH] Prevent seg fault when finalizing empty segment (#759) Fixes #757. --- packager/media/formats/webm/segmenter.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index e9efa6bc98..b3ffdcfb18 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -150,9 +150,11 @@ Status Segmenter::Initialize(const StreamInfo& info, } Status Segmenter::Finalize() { - uint64_t duration = - prev_sample_->pts() - first_timestamp_ + prev_sample_->duration(); - segment_info_.set_duration(FromBmffTimestamp(duration)); + if (prev_sample_) { + uint64_t duration = + prev_sample_->pts() - first_timestamp_ + prev_sample_->duration(); + segment_info_.set_duration(FromBmffTimestamp(duration)); + } return DoFinalize(); }