mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Make XML parsing safer; skip malformed XML lines
This commit is contained in:
@@ -33,7 +33,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, Tuple<long, bool>> depots = new Dictionary<string, Tuple<long, bool>>();
|
Dictionary<string, Tuple<long, bool>> depots = new Dictionary<string, Tuple<long, bool>>();
|
||||||
|
|
||||||
// Get the XML text reader for the configuration file, if possible
|
// Get the XML text reader for the configuration file, if possible
|
||||||
XmlTextReader xtr = FileTools.GetXmlTextReader(_config, _logger);
|
XmlReader xtr = FileTools.GetXmlTextReader(_config, _logger);
|
||||||
|
|
||||||
// Now parse the XML file for settings
|
// Now parse the XML file for settings
|
||||||
if (xtr != null)
|
if (xtr != null)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace SabreTools.Helper
|
namespace SabreTools.Helper
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -64,7 +64,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger logger = new Logger(false, "");
|
Logger logger = new Logger(false, "");
|
||||||
XmlTextReader xtr = FileTools.GetXmlTextReader(filename, logger);
|
XmlReader xtr = FileTools.GetXmlTextReader(filename, logger);
|
||||||
|
|
||||||
if (xtr == null)
|
if (xtr == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using System.Xml.Schema;
|
||||||
|
|
||||||
namespace SabreTools.Helper
|
namespace SabreTools.Helper
|
||||||
{
|
{
|
||||||
@@ -176,7 +177,7 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
/// <param name="logger">Logger object for console and file output</param>
|
||||||
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
|
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
|
||||||
public static XmlTextReader GetXmlTextReader(string filename, Logger logger)
|
public static XmlReader GetXmlTextReader(string filename, Logger logger)
|
||||||
{
|
{
|
||||||
logger.Verbose("Attempting to read file: \"" + filename + "\"");
|
logger.Verbose("Attempting to read file: \"" + filename + "\"");
|
||||||
|
|
||||||
@@ -187,10 +188,14 @@ namespace SabreTools.Helper
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlTextReader xtr;
|
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings {
|
||||||
xtr = new XmlTextReader(filename);
|
CheckCharacters = false,
|
||||||
xtr.WhitespaceHandling = WhitespaceHandling.None;
|
DtdProcessing = DtdProcessing.Ignore,
|
||||||
xtr.DtdProcessing = DtdProcessing.Ignore;
|
IgnoreComments = true,
|
||||||
|
IgnoreWhitespace = true,
|
||||||
|
ValidationFlags = XmlSchemaValidationFlags.None,
|
||||||
|
ValidationType = ValidationType.None,
|
||||||
|
});
|
||||||
return xtr;
|
return xtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user