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