From e308ab8843bdebed32351518242ca280fd345db2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 18 May 2020 01:12:40 +0100 Subject: [PATCH] .net xml things don't like null terminated strings --- .../CoalescedSceneObjectsSerializer.cs | 7 ++++- .../Serialization/SceneObjectSerializer.cs | 27 ++++++++++++++++++- .../Region/Framework/Scenes/UuidGatherer.cs | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs index 096b09fcc8..4a32b22793 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs @@ -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)) { diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index fbc950cec1..d4552b2e4c 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -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; + } + } + } + } + /// /// Deserialize a scene object from the original xml format /// diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 6fba2860af..65076f4cd1 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -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;