From 0c4c835b2722d074d60aab5f427eb958d894b537 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 17 Aug 2016 17:27:48 -0400 Subject: [PATCH] Write and read the wide aliasStart fields carefully... ...They may never have been large enough to matter, but some seek offsets into files were written as 64 bits but read back as only 32. It ought to be consistent. --- src/Legacy.cpp | 3 +++ src/blockfile/LegacyAliasBlockFile.cpp | 14 ++++++++++---- src/blockfile/ODDecodeBlockFile.cpp | 14 ++++++++++---- src/blockfile/ODPCMAliasBlockFile.cpp | 14 ++++++++++---- src/blockfile/PCMAliasBlockFile.cpp | 14 ++++++++++---- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/Legacy.cpp b/src/Legacy.cpp index 4e2792e73..88abd17cb 100644 --- a/src/Legacy.cpp +++ b/src/Legacy.cpp @@ -206,7 +206,10 @@ static bool ConvertLegacyTrack(wxTextFile *f, XMLFileWriter &xmlFile) xmlFile.WriteAttr(wxT("name"), localName); xmlFile.WriteAttr(wxT("alias"), 1); xmlFile.WriteAttr(wxT("aliaspath"), aliasPath); + + // This was written but not read again? xmlFile.WriteAttr(wxT("aliasstart"), aliasStart); + xmlFile.WriteAttr(wxT("aliaslen"), aliasLen); xmlFile.WriteAttr(wxT("aliaschannel"), aliasChannel); xmlFile.WriteAttr(wxT("summarylen"), localLen); diff --git a/src/blockfile/LegacyAliasBlockFile.cpp b/src/blockfile/LegacyAliasBlockFile.cpp index 280f36295..beb9d0d6e 100644 --- a/src/blockfile/LegacyAliasBlockFile.cpp +++ b/src/blockfile/LegacyAliasBlockFile.cpp @@ -68,7 +68,8 @@ void LegacyAliasBlockFile::SaveXML(XMLWriter &xmlFile) xmlFile.WriteAttr(wxT("alias"), 1); xmlFile.WriteAttr(wxT("name"), mFileName.GetFullName()); xmlFile.WriteAttr(wxT("aliaspath"), mAliasedFileName.GetFullPath()); - xmlFile.WriteAttr(wxT("aliasstart"), mAliasStart); + xmlFile.WriteAttr(wxT("aliasstart"), + static_cast( mAliasStart )); xmlFile.WriteAttr(wxT("aliaslen"), mLen); xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel); xmlFile.WriteAttr(wxT("summarylen"), mSummaryInfo.totalSummaryBytes); @@ -89,6 +90,7 @@ BlockFilePtr LegacyAliasBlockFile::BuildFromXML(const wxString &projDir, const w int summaryLen=0; bool noRMS = false; long nValue; + long long nnValue; while(*attrs) { @@ -116,11 +118,15 @@ BlockFilePtr LegacyAliasBlockFile::BuildFromXML(const wxString &projDir, const w // but we want to keep the reference to the missing file because it's a good path string. aliasFileName.Assign(strValue); } + else if ( !wxStricmp(attr, wxT("aliasstart")) ) + { + if (XMLValueChecker::IsGoodInt64(strValue) && + strValue.ToLongLong(&nnValue) && (nnValue >= 0)) + aliasStart = nnValue; + } else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { // integer parameters - if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0)) - aliasStart = nValue; - else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) + if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) aliasLen = nValue; else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel)) aliasChannel = nValue; diff --git a/src/blockfile/ODDecodeBlockFile.cpp b/src/blockfile/ODDecodeBlockFile.cpp index a00b04f23..3c86c0439 100644 --- a/src/blockfile/ODDecodeBlockFile.cpp +++ b/src/blockfile/ODDecodeBlockFile.cpp @@ -207,7 +207,8 @@ void ODDecodeBlockFile::SaveXML(XMLWriter &xmlFile) mFileNameMutex.Unlock(); LockRead(); xmlFile.WriteAttr(wxT("audiofile"), mAudioFileName.GetFullPath()); - xmlFile.WriteAttr(wxT("aliasstart"), mAliasStart); + xmlFile.WriteAttr(wxT("aliasstart"), + static_cast( mAliasStart )); xmlFile.WriteAttr(wxT("aliaslen"), mLen); xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel); xmlFile.WriteAttr(wxT("decodetype"), (size_t)mType); @@ -229,6 +230,7 @@ BlockFilePtr ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr sampleCount aliasStart=0, aliasLen=0; int aliasChannel=0; long nValue; + long long nnValue; unsigned int decodeType=0; while(*attrs) @@ -261,11 +263,15 @@ BlockFilePtr ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr // but we want to keep the reference to the file because it's a good path string. audioFileName.Assign(strValue); } + else if ( !wxStricmp(attr, wxT("aliasstart")) ) + { + if (XMLValueChecker::IsGoodInt64(strValue) && + strValue.ToLongLong(&nnValue) && (nnValue >= 0)) + aliasStart = nnValue; + } else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { // integer parameters - if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0)) - aliasStart = nValue; - else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) + if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) aliasLen = nValue; else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel)) aliasChannel = nValue; diff --git a/src/blockfile/ODPCMAliasBlockFile.cpp b/src/blockfile/ODPCMAliasBlockFile.cpp index 87cdb705d..2f7500494 100644 --- a/src/blockfile/ODPCMAliasBlockFile.cpp +++ b/src/blockfile/ODPCMAliasBlockFile.cpp @@ -247,7 +247,8 @@ void ODPCMAliasBlockFile::SaveXML(XMLWriter &xmlFile) LockRead(); xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath()); - xmlFile.WriteAttr(wxT("aliasstart"), mAliasStart); + xmlFile.WriteAttr(wxT("aliasstart"), + static_cast( mAliasStart)); xmlFile.WriteAttr(wxT("aliaslen"), mLen); xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel); @@ -269,6 +270,7 @@ BlockFilePtr ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **at sampleCount aliasStart=0, aliasLen=0; int aliasChannel=0; long nValue; + long long nnValue; while(*attrs) { @@ -300,11 +302,15 @@ BlockFilePtr ODPCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **at // but we want to keep the reference to the missing file because it's a good path string. aliasFileName.Assign(strValue); } + else if ( !wxStricmp(attr, wxT("aliasstart")) ) + { + if (XMLValueChecker::IsGoodInt64(strValue) && + strValue.ToLongLong(&nnValue) && (nnValue >= 0)) + aliasStart = nnValue; + } else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { // integer parameters - if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0)) - aliasStart = nValue; - else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) + if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) aliasLen = nValue; else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel)) aliasChannel = nValue; diff --git a/src/blockfile/PCMAliasBlockFile.cpp b/src/blockfile/PCMAliasBlockFile.cpp index 0a1765b3f..e30e8dbb2 100644 --- a/src/blockfile/PCMAliasBlockFile.cpp +++ b/src/blockfile/PCMAliasBlockFile.cpp @@ -165,7 +165,8 @@ void PCMAliasBlockFile::SaveXML(XMLWriter &xmlFile) xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName()); xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath()); - xmlFile.WriteAttr(wxT("aliasstart"), mAliasStart); + xmlFile.WriteAttr(wxT("aliasstart"), + static_cast( mAliasStart )); xmlFile.WriteAttr(wxT("aliaslen"), mLen); xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel); xmlFile.WriteAttr(wxT("min"), mMin); @@ -186,6 +187,7 @@ BlockFilePtr PCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr float min = 0.0f, max = 0.0f, rms = 0.0f; double dblValue; long nValue; + long long nnValue; while(*attrs) { @@ -217,11 +219,15 @@ BlockFilePtr PCMAliasBlockFile::BuildFromXML(DirManager &dm, const wxChar **attr // but we want to keep the reference to the missing file because it's a good path string. aliasFileName.Assign(strValue); } + else if ( !wxStricmp(attr, wxT("aliasstart")) ) + { + if (XMLValueChecker::IsGoodInt64(strValue) && + strValue.ToLongLong(&nnValue) && (nnValue >= 0)) + aliasStart = nnValue; + } else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { // integer parameters - if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0)) - aliasStart = nValue; - else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) + if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0)) aliasLen = nValue; else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel)) aliasChannel = nValue;