Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -36,4 +36,33 @@ namespace System.Web.Util {
}
}
// This wrapper around a managed object is opaque to SizedReference GC handle
// and therefore helps with calculating size of only relevant graph of objects
internal class DisposableGCHandleRef<T> : IDisposable
where T : class, IDisposable {
GCHandle _handle;
[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
public DisposableGCHandleRef(T t) {
Debug.Assert(t != null);
_handle = GCHandle.Alloc(t);
}
public T Target {
[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
get {
Debug.Assert(_handle.IsAllocated);
return (T)_handle.Target;
}
}
[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
public void Dispose() {
Target.Dispose();
Debug.Assert(_handle.IsAllocated);
if (_handle.IsAllocated) {
_handle.Free();
}
}
}
}

View File

@@ -15,6 +15,7 @@ using System.Text;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Web.Hosting;
using System.Diagnostics.CodeAnalysis;
/*
* Various string handling utilities
@@ -294,6 +295,7 @@ internal static class StringUtil {
// Instead use the default AppDomain, because it doesn't have string hash randomization enabled.
// Marshal the call to reuse the default StringComparer behavior.
// PERF isn't optimal, so apply consideration!
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "We carefully control the callers.")]
internal static int GetNonRandomizedStringComparerHashCode(string s) {
// Preserve the default behavior when string hash randomization is off
if (!AppSettings.UseRandomizedStringHashAlgorithm) {

View File

@@ -105,7 +105,7 @@ namespace System.Web.Util {
// This method only schedules work; it doesn't itself do any work. The lock is held for a very
// short period of time.
lock (_lockObj) {
Task newTask = _lastScheduledTask.ContinueWith(_ => SafeWrapCallback(action));
Task newTask = _lastScheduledTask.ContinueWith(_ => SafeWrapCallback(action), TaskScheduler.Default);
_lastScheduledTask = newTask; // the newly-created task is now the last one
}
}

View File

@@ -17,6 +17,7 @@ namespace System.Web.Util {
public static readonly long MaxEntityExpansion = 1024 * 1024;
[SuppressMessage("Microsoft.Security", "MSEC1208:DoNotUseLoadXml", Justification = "Handles developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3057:DoNotUseLoadXml", Justification = "Handles developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
public static XmlDocument CreateXmlDocumentFromContent(string content)
{
XmlDocument doc = new XmlDocument();
@@ -35,6 +36,7 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1210:UseXmlReaderForXPathDocument", Justification = "Handles developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3059:UseXmlReaderForXPathDocument", Justification = "Handles developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
public static XPathDocument CreateXPathDocumentFromContent(string content)
{
StringReader reader = new StringReader(content);
@@ -47,6 +49,7 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1220:ReviewDtdProcessingAssignment", Justification = "Dtd processing is needed for back-compat, but is being done as safely as possible.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3069:ReviewDtdProcessingAssignment", Justification = "Dtd processing is needed for back-compat, but is being done as safely as possible.")]
public static XmlReaderSettings CreateXmlReaderSettings()
{
XmlReaderSettings settings = new XmlReaderSettings();
@@ -68,7 +71,9 @@ namespace System.Web.Util {
// try to guess at how to set matching defaults with XmlReader.Create().
// (E.g. DtdProcessing is Parse by default using XmlTextReader directly. It's Prohibit in default XmlReaderSettings.)
[SuppressMessage("Microsoft.Security", "MSEC1205:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3054:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security", "MSEC1225:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3074:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
public static XmlReader CreateXmlReader(string filepath)
{
if (AppSettings.RestrictXmlControls)
@@ -84,7 +89,9 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1205:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3054:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security", "MSEC1225:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3074:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
public static XmlReader CreateXmlReader(Stream datastream)
{
if (AppSettings.RestrictXmlControls)
@@ -100,7 +107,9 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1205:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3054:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security", "MSEC1225:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3074:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
public static XmlReader CreateXmlReader(TextReader reader)
{
if (AppSettings.RestrictXmlControls)
@@ -116,7 +125,9 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1205:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3054:DoNotAllowDtdOnXmlTextReader", Justification = "Handles trusted or developer-controlled input xml. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security", "MSEC1225:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3074:ReviewClassesDerivedFromXmlTextReader", Justification = "NoEntitiesXmlReader is our internal mechanism for using XmlTextReaders in a reasonably safe manner.")]
public static XmlReader CreateXmlReader(Stream contentStream, string baseURI)
{
if (AppSettings.RestrictXmlControls)
@@ -179,6 +190,7 @@ namespace System.Web.Util {
#pragma warning disable 0618 // To avoid deprecation warning
[SuppressMessage("Microsoft.Security", "MSEC1201:DoNotUseXslTransform", Justification = "Handles developer-controlled input xsl. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3050:DoNotUseXslTransform", Justification = "Handles developer-controlled input xsl. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
public static XslTransform CreateXslTransform(XmlReader reader)
{
if (!AppSettings.RestrictXmlControls)
@@ -191,6 +203,7 @@ namespace System.Web.Util {
}
[SuppressMessage("Microsoft.Security", "MSEC1201:DoNotUseXslTransform", Justification = "Handles developer-controlled input xsl. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3050:DoNotUseXslTransform", Justification = "Handles developer-controlled input xsl. Optional safer codepath available via appSettings/aspnet:RestrictXmlControls configuration.")]
public static XslTransform CreateXslTransform(XmlReader reader, XmlResolver resolver)
{
if (!AppSettings.RestrictXmlControls)