From aaf1d809a0ebbc2eb7dcd9ea7146cfe7bb4702f1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 May 2017 10:50:21 +0100 Subject: [PATCH] Don't crash when failing to parse a KDM. --- src/tools/dcpomatic_kdm.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 75149a718..072cc2b0e 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -158,7 +158,6 @@ public: dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP); right->Add (dkdm_sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP); - _dkdm_id[_dkdm->AddRoot("root")] = Config::instance()->dkdms(); add_dkdm_view (Config::instance()->dkdms(), shared_ptr ()); h = new wxStaticText (overall_panel, wxID_ANY, _("Output")); @@ -372,7 +371,22 @@ private: { wxFileDialog* d = new wxFileDialog (this, _("Select DKDM file")); if (d->ShowModal() == wxID_OK) { - shared_ptr new_dkdm (new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)))); + shared_ptr new_dkdm; + try { + new_dkdm.reset ( + new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE))) + ); + } catch (dcp::KDMFormatError& e) { + error_dialog ( + this, + wxString::Format ( + _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all.\n\n%s"), + std_to_wx(e.what()).data() + ) + ); + return; + } + shared_ptr group = dynamic_pointer_cast (selected_dkdm ()); if (!group) { group = Config::instance()->dkdms (); -- 2.30.2