MODELDEF, DECORATE, GLDEFS parsers: fixed a crash when checking a file path when said path contained unsupported characters.

This commit is contained in:
MaxED 2016-01-01 18:10:16 +00:00
parent 0ecd5285dd
commit 59da0cf2b1
4 changed files with 39 additions and 6 deletions

View file

@ -660,6 +660,9 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
return false;
}
// Check invalid path chars
if(!CheckInvalidPathChars(token)) return false;
// Absolute paths are not supported...
if(Path.IsPathRooted(includelump))
{

View file

@ -98,15 +98,18 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
return false;
}
//check invalid path chars
if(!parser.CheckInvalidPathChars(token)) return false;
//check extension
string fileExt = Path.GetExtension(token);
if(string.IsNullOrEmpty(fileExt))
string modelext = Path.GetExtension(token);
if(string.IsNullOrEmpty(modelext))
{
parser.ReportError("Model '" + token + "' won't be loaded. Models without extension are not supported by GZDoom");
return false;
}
if(fileExt != ".md3" && fileExt != ".md2")
if(modelext != ".md3" && modelext != ".md2")
{
parser.ReportError("Model '" + token + "' won't be loaded. Only MD2 and MD3 models are supported");
return false;
@ -149,11 +152,14 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
return false;
}
//check invalid path chars
if(!parser.CheckInvalidPathChars(token)) return false;
//check extension
string ext = Path.GetExtension(token);
if(Array.IndexOf(ModelData.SUPPORTED_TEXTURE_EXTENSIONS, ext) == -1)
string texext = Path.GetExtension(token);
if(Array.IndexOf(ModelData.SUPPORTED_TEXTURE_EXTENSIONS, texext) == -1)
{
parser.ReportError("Image format '" + ext + "' is not supported");
parser.ReportError("Image format '" + texext + "' is not supported");
return false;
}

View file

@ -168,6 +168,9 @@ namespace CodeImp.DoomBuilder.ZDoom
return false;
}
//mxd. Check invalid path chars
if(!CheckInvalidPathChars(filename)) return false;
//mxd. Absolute paths are not supported...
if(Path.IsPathRooted(filename))
{

View file

@ -594,6 +594,27 @@ namespace CodeImp.DoomBuilder.ZDoom
return result;
}
//mxd. This replicates System.IO.Path.CheckInvalidPathChars() internal function
public bool CheckInvalidPathChars(string path)
{
foreach(char c in path)
{
int num = c;
switch(num)
{
case 34: case 60: case 62: case 124:
ReportError("unsupported character \"" + c + "\" in path \"" + path + "\".");
return false;
default:
if(num >= 32) continue;
goto case 34;
}
}
return true;
}
//mxd. Language type
protected abstract string GetLanguageType();