1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-02-06 11:42:17 +01:00

more progress on bug 113

better handling of error conditions in all BuildFromXML methods, per comment: 

// BuildFromXML methods should always return a BlockFile, not NULL,  
// even if the result is flawed (e.g., refers to nonexistent file), 
// as testing will be done in DirManager::ProjectFSCK().
This commit is contained in:
v.audacity
2010-07-30 03:04:37 +00:00
parent 874e530d84
commit 3729f067be
9 changed files with 139 additions and 188 deletions

View File

@@ -216,18 +216,17 @@ void ODDecodeBlockFile::SaveXML(XMLWriter &xmlFile)
/// Constructs a ODPCMAliasBlockFile from the xml output of WriteXML.
/// Also schedules the ODPCMAliasBlockFile for OD loading.
// BuildFromXML methods should always return a BlockFile, not NULL,
// even if the result is flawed (e.g., refers to nonexistent file),
// as testing will be done in DirManager::ProjectFSCK().
BlockFile *ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
{
wxFileName summaryFileName;
wxFileName audioFileName;
sampleCount aliasStart=0, aliasLen=0;
int aliasChannel=0;
long nValue;
unsigned int decodeType=0;
float rms=0.0f;
while(*attrs)
{
@@ -237,20 +236,14 @@ BlockFile *ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
break;
const wxString strValue = value;
if( !wxStricmp(attr, wxT("summaryfile")) )
{
// Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
if (!XMLValueChecker::IsGoodFileString(strValue))
return NULL;
#ifdef _WIN32
if (strValue.Length() + 1 + dm.GetProjectDataDir().Length() > MAX_PATH)
return NULL;
#endif
dm.AssignFile(summaryFileName,value,FALSE);
}
if (!wxStricmp(attr, wxT("summaryfile")) &&
// Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
XMLValueChecker::IsGoodFileString(strValue)
#ifdef _WIN32
&& (strValue.Length() + 1 + dm.GetProjectDataDir().Length() <= MAX_PATH)
#endif
)
dm.AssignFile(summaryFileName, strValue, false);
else if( !wxStricmp(attr, wxT("audiofile")) )
{
if (XMLValueChecker::IsGoodPathName(strValue))
@@ -258,28 +251,25 @@ BlockFile *ODDecodeBlockFile::BuildFromXML(DirManager &dm, const wxChar **attrs)
else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
// Allow fallback of looking for the file name, located in the data directory.
audioFileName.Assign(dm.GetProjectDataDir(), strValue);
else
return NULL;
else if (XMLValueChecker::IsGoodPathString(strValue))
// If the file is missing, we failed XMLValueChecker::IsGoodPathName()
// and XMLValueChecker::IsGoodFileName, because both do existence tests,
// but we want to keep the reference to the file because it's a good path string.
audioFileName.Assign(strValue);
}
else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
{ // integer parameters
if( !wxStricmp(attr, wxT("aliasstart")) )
{ // integer parameters
if (!wxStricmp(attr, wxT("aliasstart")) && (nValue >= 0))
aliasStart = nValue;
else if( !wxStricmp(attr, wxT("aliaslen")) )
else if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
aliasLen = nValue;
else if( !wxStricmp(attr, wxT("aliaschannel")) )
else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
aliasChannel = nValue;
else if( !wxStricmp(attr, wxT("decodetype")) )
decodeType = nValue;
}
}
//file doesn't exist, but IsGoodFileName Checks that it does - maybe we should have a different method to check for valid names?
if ( /*!XMLValueChecker::IsGoodFileName(summaryFileName.GetFullName(), summaryFileName.GetPath(wxPATH_GET_VOLUME)) || */
!XMLValueChecker::IsGoodFileName(audioFileName.GetFullName(), audioFileName.GetPath(wxPATH_GET_VOLUME)) ||
(aliasLen <= 0) || (aliasLen < 0.0) || !XMLValueChecker::IsValidChannel(aliasChannel) || (rms < 0.0))
return NULL;
return new ODDecodeBlockFile(summaryFileName, audioFileName,
aliasStart, aliasLen, aliasChannel,decodeType);