.net xml things don't like null terminated strings

master
UbitUmarov 2020-05-18 01:12:40 +01:00
parent 9ecee558b5
commit e308ab8843
3 changed files with 33 additions and 3 deletions

View File

@ -193,8 +193,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
coa = null;
try
{
int len = data.Length;
if (len < 32)
return false;
if (data[len - 1] == 0)
--len;
// Quickly check if this is a coalesced object, without fully parsing the XML
using (MemoryStream ms = new MemoryStream(data))
using (MemoryStream ms = new MemoryStream(data, 0, len, false))
{
using (XmlTextReader reader = new XmlTextReader(ms))
{

View File

@ -63,7 +63,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
String fixedData = ExternalRepresentationUtils.SanitizeXml(xmlData);
using (XmlTextReader wrappedReader = new XmlTextReader(fixedData, XmlNodeType.Element, null))
{
using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment}))
using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment }))
{
try
{
@ -79,6 +79,31 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
}
}
public static SceneObjectGroup FromOriginalXmlData(byte[] data)
{
int len = data.Length;
if(len < 32)
return null;
if(data[len -1 ] == 0)
--len;
using (MemoryStream ms = new MemoryStream(data,0, len, false))
{
using (XmlReader reader = XmlReader.Create(ms, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment }))
{
try
{
return FromOriginalXmlFormat(reader);
}
catch (Exception e)
{
m_log.Error("[SERIALIZER]: Deserialization of xml data failed ", e);
string s = Utils.BytesToString(data);
return null;
}
}
}
}
/// <summary>
/// Deserialize a scene object from the original xml format
/// </summary>

View File

@ -808,7 +808,7 @@ namespace OpenSim.Region.Framework.Scenes
}
else
{
SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlFormat(Utils.BytesToString(sceneObjectAsset.Data));
SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlData(sceneObjectAsset.Data);
if (null != sog)
{
sog.TemporaryInstance = true;