From e5a1243abc04c3f6f62e94425fea25b2ad84b577 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 1 Aug 2015 18:58:05 -0700 Subject: [PATCH] Mantis #7657 and #7514. This should alleviate the problem of bad object assets being passed around via HG and archives. No guarantees that all the leaks have been found, but at least it detects and fixes these bad assets upon: (1) storing and getting assets over HG -- assuming the core HG asset service is being used (not the case with OSGrid!) (2) importing assets via OAR and IAR Instantiation of bad assets now should also work, instead of producing an exception, but the bad assets themselves aren't being fixed in the DB. That should be done with a cleaning tool -- see Perl script in Mantis #7657. Virus! --- .../External/ExternalRepresentationUtils.cs | 19 ++++++++++++++++ .../Framework/Scenes/Scene.Inventory.cs | 3 ++- .../Serialization/SceneObjectSerializer.cs | 7 +++--- .../HypergridService/HGAssetService.cs | 22 +++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 64de18b47f..125408690f 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -190,6 +190,9 @@ namespace OpenSim.Framework.Serialization.External if (xmlData == string.Empty || homeURL == string.Empty || userService == null) return xmlData; + // Deal with bug + xmlData = ExternalRepresentationUtils.SanitizeXml(xmlData); + using (StringWriter sw = new StringWriter()) using (XmlTextWriter writer = new XmlTextWriter(sw)) using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) @@ -364,5 +367,21 @@ namespace OpenSim.Framework.Serialization.External { return homeURL + "/" + uuid + ";" + name; } + + /// + /// Sanitation for bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) + /// + /// + /// + public static string SanitizeXml(string xmlData) + { + string fixedData = xmlData; + if (fixedData != null) + // Loop, because it may contain multiple + while (fixedData.Contains("xmlns:xmlns:")) + fixedData = fixedData.Replace("xmlns:xmlns:", "xmlns:"); + return fixedData; + } + } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index c14ce1e5e9..dde54d57c8 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -37,6 +37,7 @@ using OpenMetaverse; using OpenMetaverse.Packets; using log4net; using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; using OpenSim.Region.Framework; using OpenSim.Framework.Client; using OpenSim.Region.Framework.Interfaces; @@ -2225,7 +2226,7 @@ namespace OpenSim.Region.Framework.Scenes bbox = Vector3.Zero; offsetHeight = 0; - string xmlData = Utils.BytesToString(assetData); + string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(assetData)); try { diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index cb13ca4b7d..463ef223b8 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -52,7 +52,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static IUserManagement m_UserManagement; - + /// /// Deserialize a scene object from the original xml format /// @@ -60,7 +60,8 @@ namespace OpenSim.Region.Framework.Scenes.Serialization /// The scene object deserialized. Null on failure. public static SceneObjectGroup FromOriginalXmlFormat(string xmlData) { - using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) + 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 })) return FromOriginalXmlFormat(reader); } @@ -322,7 +323,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization List sceneObjects = new List(); CoalescedSceneObjects coa = null; - string xmlData = Utils.BytesToString(data); + string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data)); if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) { diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs index a829932dd9..b83fb1ee50 100644 --- a/OpenSim/Services/HypergridService/HGAssetService.cs +++ b/OpenSim/Services/HypergridService/HGAssetService.cs @@ -129,6 +129,14 @@ namespace OpenSim.Services.HypergridService if (!m_AssetPerms.AllowedExport(asset.Type)) return null; + // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) + // Fix bad assets before sending them elsewhere + if (asset.Type == (int)AssetType.Object && asset.Data != null) + { + string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data)); + asset.Data = Utils.StringToBytes(xml); + } + return asset.Data; } @@ -139,6 +147,14 @@ namespace OpenSim.Services.HypergridService if (!m_AssetPerms.AllowedImport(asset.Type)) return string.Empty; + // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) + // Fix bad assets before storing on this server + if (asset.Type == (int)AssetType.Object && asset.Data != null) + { + string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data)); + asset.Data = Utils.StringToBytes(xml); + } + return base.Store(asset); } @@ -160,9 +176,15 @@ namespace OpenSim.Services.HypergridService meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName; } + // Only for Object protected byte[] AdjustIdentifiers(byte[] data) { string xml = Utils.BytesToString(data); + + // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) + // Fix bad assets before sending them elsewhere + xml = ExternalRepresentationUtils.SanitizeXml(xml); + return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero)); }