-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'a8e48616c8d8e56469a456eb1ee263268316b827' into revertAn…
…dCorrectMerge31
- Loading branch information
Showing
6 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Markup/XamlReaderProxy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// | ||
// Description: This helper class reflects into internal overloads of XamlReader.Load to use the RestrictiveXamlXmlReader | ||
// to avoid loading unsafe loose xaml. | ||
// | ||
|
||
using System; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Reflection; | ||
using System.Windows.Markup; | ||
|
||
#if REACHFRAMEWORK | ||
namespace MS.Internal.ReachFramework | ||
#elif PRESENTATIONFRAMEWORK | ||
namespace MS.Internal.PresentationFramework | ||
#else | ||
namespace MS.Internal | ||
#endif | ||
{ | ||
namespace Markup | ||
{ | ||
/// <summary> | ||
/// Provides a helper class to create delegates to reflect into XamlReader.Load | ||
/// </summary> | ||
internal class XamlReaderProxy | ||
{ | ||
/// <summary> | ||
/// The static constructor creates and stores delegates for overloads of <see cref="XamlReader.Load"/> that need to be reflected into | ||
/// so that we can safeguard entry-points for external xaml loading. | ||
/// </summary> | ||
/// <remark> Doing this in the static constructor guarantees thread safety.</remark> | ||
|
||
static XamlReaderProxy() | ||
{ | ||
MethodInfo method = _xamlReaderType.GetMethod(XamlLoadMethodName, BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(Stream), typeof(ParserContext), typeof(bool) }, null); | ||
|
||
if (method == null) | ||
{ | ||
throw new MissingMethodException(XamlLoadMethodName); | ||
} | ||
|
||
_xamlLoad3 = (XamlLoadDelegate3)method.CreateDelegate(typeof(XamlLoadDelegate3)); | ||
|
||
method = _xamlReaderType.GetMethod(XamlLoadMethodName, BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(XmlReader), typeof(bool) }, null); | ||
|
||
if (method == null) | ||
{ | ||
throw new MissingMethodException(XamlLoadMethodName); | ||
} | ||
|
||
_xamlLoad2 = (XamlLoadDelegate2)method.CreateDelegate(typeof(XamlLoadDelegate2)); | ||
} | ||
|
||
public static object Load(Stream stream, ParserContext parserContext, bool useRestrictiveXamlReader) | ||
{ | ||
return _xamlLoad3.Invoke(stream, parserContext, useRestrictiveXamlReader); | ||
} | ||
|
||
public static object Load(XmlReader reader, bool useRestrictiveXamlReader) | ||
{ | ||
return _xamlLoad2.Invoke(reader, useRestrictiveXamlReader); | ||
} | ||
|
||
private delegate object XamlLoadDelegate3(Stream stream, ParserContext parserContext, bool useRestrictiveXamlReader); | ||
private static XamlLoadDelegate3 _xamlLoad3; | ||
|
||
private delegate object XamlLoadDelegate2(XmlReader reader, bool useRestrictiveXamlReader); | ||
private static XamlLoadDelegate2 _xamlLoad2; | ||
|
||
private static readonly Type _xamlReaderType = typeof(XamlReader); | ||
private const string XamlLoadMethodName = nameof(Load); | ||
|
||
} | ||
} | ||
} |