From 2f6065b32c26dba0f7ea5da5c980d0406c36cc55 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Tue, 29 Apr 2014 06:44:40 +1000 Subject: Fixed problem where importing invalid midi files caused crash. --- gtk2_ardour/sfdb_ui.cc | 8 ++++---- libs/ardour/ardour/smf_source.h | 1 + libs/ardour/smf_source.cc | 11 +++++++++++ libs/evoral/evoral/SMF.hpp | 1 + libs/evoral/src/SMF.cpp | 22 ++++++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 4b89cd51fe..6e08617af2 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -279,7 +279,7 @@ SoundFileBox::setup_labels (const string& filename) string error_msg; - if (SMFSource::safe_midi_file_extension (path)) { + if (SMFSource::valid_midi_file (path)) { boost::shared_ptr ms = boost::dynamic_pointer_cast ( @@ -404,7 +404,7 @@ SoundFileBox::audition () boost::shared_ptr r; - if (SMFSource::safe_midi_file_extension (path)) { + if (SMFSource::valid_midi_file (path)) { boost::shared_ptr ms = boost::dynamic_pointer_cast ( @@ -1307,7 +1307,7 @@ SoundFileOmega::reset_options () /* See if we are thinking about importing any MIDI files */ vector::iterator i = paths.begin (); - while (i != paths.end() && SMFSource::safe_midi_file_extension (*i) == false) { + while (i != paths.end() && SMFSource::valid_midi_file (*i) == false) { ++i; } bool const have_a_midi_file = (i != paths.end ()); @@ -1535,7 +1535,7 @@ SoundFileOmega::check_info (const vector& paths, bool& same_size, bool& src_needed = true; } - } else if (SMFSource::safe_midi_file_extension (*i)) { + } else if (SMFSource::valid_midi_file (*i)) { Evoral::SMF reader; reader.open(*i); diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 9c0a78f282..a068a3e385 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -77,6 +77,7 @@ public: void ensure_disk_file (); static bool safe_midi_file_extension (const std::string& path); + static bool valid_midi_file (const std::string& path); void prevent_deletion (); diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index d52923c302..c3bc78c83d 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -34,6 +34,7 @@ #include #include "evoral/Control.hpp" +#include "evoral/evoral/SMF.hpp" #include "ardour/event_type_map.h" #include "ardour/midi_model.h" @@ -48,6 +49,7 @@ using namespace ARDOUR; using namespace Glib; using namespace PBD; +using namespace Evoral; /** Constructor used for new internal-to-session files. File cannot exist. */ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags) @@ -496,6 +498,15 @@ SMFSource::mark_midi_streaming_write_completed (Evoral::Sequence