From 4e6d11fe0c51df1f525c4157f44d38834f074dd7 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Sat, 23 Jan 2021 16:05:27 -0600 Subject: [PATCH] Don't clear tags until after loading to guard against bad XML file --- src/Tags.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Tags.cpp b/src/Tags.cpp index 31711b157..c1b109b40 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -1245,24 +1245,26 @@ void TagsEditorDialog::OnLoad(wxCommandEvent & WXUNUSED(event)) return; } - // Remember title and track in case they're read only - wxString title = mLocal.GetTag(TAG_TITLE); - wxString track = mLocal.GetTag(TAG_TRACK); - - // Clear current contents - mLocal.Clear(); - // Load the metadata + decltype(mLocal) temp; XMLFileReader reader; - if (!reader.Parse(&mLocal, fn)) { + if (!reader.Parse(&temp, fn)) { // Inform user of load failure AudacityMessageBox( reader.GetErrorStr(), XO("Error Loading Metadata"), wxOK | wxCENTRE, this); + return; } + // Remember title and track in case they're read only + wxString title = mLocal.GetTag(TAG_TITLE); + wxString track = mLocal.GetTag(TAG_TRACK); + + // Replace existing tags with loaded ones + mLocal = temp; + // Restore title if (!mEditTitle) { mLocal.SetTag(TAG_TITLE, title);