mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 18:27:55 +08:00
#18364: Fixing possible stack overflows in Shape Tracing
Work Item: 18364 --HG-- branch : 1.x
This commit is contained in:
@@ -21,6 +21,8 @@ namespace Orchard.DesignerTools.Services {
|
|||||||
private readonly IThemeManager _themeManager;
|
private readonly IThemeManager _themeManager;
|
||||||
private readonly IWebSiteFolder _webSiteFolder;
|
private readonly IWebSiteFolder _webSiteFolder;
|
||||||
private readonly IAuthorizer _authorizer;
|
private readonly IAuthorizer _authorizer;
|
||||||
|
private bool _processing;
|
||||||
|
|
||||||
private int _shapeId;
|
private int _shapeId;
|
||||||
|
|
||||||
public ShapeTracingFactory(
|
public ShapeTracingFactory(
|
||||||
@@ -57,6 +59,13 @@ namespace Orchard.DesignerTools.Services {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent reentrance as some methods could create new shapes, and trigger this event
|
||||||
|
if(_processing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_processing = true;
|
||||||
|
|
||||||
if (context.ShapeType != "Layout"
|
if (context.ShapeType != "Layout"
|
||||||
&& context.ShapeType != "DocumentZone"
|
&& context.ShapeType != "DocumentZone"
|
||||||
&& context.ShapeType != "PlaceChildContent"
|
&& context.ShapeType != "PlaceChildContent"
|
||||||
@@ -66,16 +75,19 @@ namespace Orchard.DesignerTools.Services {
|
|||||||
&& context.ShapeType != "DateTimeRelative") {
|
&& context.ShapeType != "DateTimeRelative") {
|
||||||
|
|
||||||
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
|
var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
|
||||||
var currentTheme = _themeManager.GetRequestTheme(_workContext.HttpContext.Request.RequestContext);
|
var currentTheme = _workContext.CurrentTheme;
|
||||||
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
|
var shapeTable = _shapeTableManager.GetShapeTable(currentTheme.Id);
|
||||||
|
|
||||||
if (!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) {
|
if (!shapeTable.Descriptors.ContainsKey(shapeMetadata.Type)) {
|
||||||
|
_processing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
|
shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
|
||||||
shapeMetadata.OnDisplaying(OnDisplaying);
|
shapeMetadata.OnDisplaying(OnDisplaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_processing = false;
|
||||||
}
|
}
|
||||||
public void Displaying(ShapeDisplayingContext context) {}
|
public void Displaying(ShapeDisplayingContext context) {}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ namespace Orchard.Environment {
|
|||||||
class WorkContextImplementation : WorkContext {
|
class WorkContextImplementation : WorkContext {
|
||||||
readonly IComponentContext _componentContext;
|
readonly IComponentContext _componentContext;
|
||||||
readonly ConcurrentDictionary<string, Func<object>> _stateResolvers = new ConcurrentDictionary<string, Func<object>>();
|
readonly ConcurrentDictionary<string, Func<object>> _stateResolvers = new ConcurrentDictionary<string, Func<object>>();
|
||||||
|
readonly ConcurrentDictionary<string, object> _states = new ConcurrentDictionary<string, object>();
|
||||||
readonly IEnumerable<IWorkContextStateProvider> _workContextStateProviders;
|
readonly IEnumerable<IWorkContextStateProvider> _workContextStateProviders;
|
||||||
|
|
||||||
public WorkContextImplementation(IComponentContext componentContext) {
|
public WorkContextImplementation(IComponentContext componentContext) {
|
||||||
@@ -24,8 +25,10 @@ namespace Orchard.Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override T GetState<T>(string name) {
|
public override T GetState<T>(string name) {
|
||||||
var resolver = _stateResolvers.GetOrAdd(name, FindResolverForState<T>);
|
return (T)_states.GetOrAdd(name, (x) => {
|
||||||
return (T)resolver();
|
var resolver = _stateResolvers.GetOrAdd(x, FindResolverForState<T>);
|
||||||
|
return resolver();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Func<object> FindResolverForState<T>(string name) {
|
Func<object> FindResolverForState<T>(string name) {
|
||||||
@@ -39,7 +42,7 @@ namespace Orchard.Environment {
|
|||||||
|
|
||||||
|
|
||||||
public override void SetState<T>(string name, T value) {
|
public override void SetState<T>(string name, T value) {
|
||||||
_stateResolvers[name] = () => value;
|
_stateResolvers[name] = () => _states[name] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user