From 2cce28ca43361f9cd5823e4605bbd2230d2228fd Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Feb 2010 08:09:03 +0100 Subject: [PATCH] Fix for the case "overwrite element at the end of the file" Fixes a crash in mmg when saving chapters to a Matroska file. --- ChangeLog | 5 +++++ src/common/kax_analyzer.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 177b28452..3c96043b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-11 Moritz Bunkus + + * mmg, mkvpropedit: Fixed another bug causing a crash writing + chapters/other elements to existing Matroska files. + 2010-02-10 Moritz Bunkus * Build system: bug fix: Improved detection of Boost::Filesystem diff --git a/src/common/kax_analyzer.cpp b/src/common/kax_analyzer.cpp index 986059197..485857bc6 100644 --- a/src/common/kax_analyzer.cpp +++ b/src/common/kax_analyzer.cpp @@ -400,6 +400,17 @@ kax_analyzer_c::adjust_segment_size() { */ bool kax_analyzer_c::handle_void_elements(int data_idx) { + // Is the element at the end of the file? If so truncate the file + // and remove the element from the m_data structure if that was + // requested. Then we're done. + if (m_data.size() == (data_idx + 1)) { + m_file->truncate(m_data[data_idx]->m_pos + m_data[data_idx]->m_size); + adjust_segment_size(); + if (0 == m_data[data_idx]->m_size) + m_data.erase(m_data.begin() + data_idx); + return false; + } + // Are the following elements EbmlVoid elements? int end_idx = data_idx + 1; while ((m_data.size() > end_idx) && (m_data[end_idx]->m_id == EbmlVoid::ClassInfos.GlobalId))