Skip to content

Commit

Permalink
Make parts of ResourceManager trimming safe (#38432)
Browse files Browse the repository at this point in the history
We'll need a feature switch to turn off support for the parts that read text strings out of resources to make this fully safe.
  • Loading branch information
MichalStrehovsky authored Jul 6, 2020
1 parent fe664d6 commit c8a9942
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ internal class CultureNameResourceSetPair
private Dictionary<string, ResourceSet>? _resourceSets;
private readonly string? _moduleDir; // For assembly-ignorant directory location
private readonly Type? _locationInfo; // For Assembly or type-based directory layout

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
private readonly Type? _userResourceSet; // Which ResourceSet instance to create

private CultureInfo? _neutralResourcesCulture; // For perf optimizations.

private CultureNameResourceSetPair? _lastUsedResourceCache;
Expand Down Expand Up @@ -166,7 +169,9 @@ protected ResourceManager()
//
// Note: System.Windows.Forms uses this method at design time.
//
private ResourceManager(string baseName, string resourceDir, Type? userResourceSet)
private ResourceManager(string baseName, string resourceDir,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type? userResourceSet)
{
if (null == baseName)
throw new ArgumentNullException(nameof(baseName));
Expand Down Expand Up @@ -199,7 +204,9 @@ public ResourceManager(string baseName, Assembly assembly)
CommonAssemblyInit();
}

public ResourceManager(string baseName, Assembly assembly, Type? usingResourceSet)
public ResourceManager(string baseName, Assembly assembly,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type? usingResourceSet)
{
if (null == baseName)
throw new ArgumentNullException(nameof(baseName));
Expand Down Expand Up @@ -263,6 +270,7 @@ public virtual bool IgnoreCase

// Returns the Type of the ResourceSet the ResourceManager uses
// to construct ResourceSets.
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
public virtual Type ResourceSetType => _userResourceSet ?? typeof(RuntimeResourceSet);

protected UltimateResourceFallbackLocation FallbackLocation
Expand Down Expand Up @@ -753,6 +761,7 @@ internal ResourceManagerMediator(ResourceManager rm)
// NEEDED BOTH BY FILE-BASED AND ASSEMBLY-BASED
internal Type? LocationInfo => _rm._locationInfo;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
internal Type? UserResourceSet => _rm._userResourceSet;

internal string? BaseNameField => _rm.BaseNameField;
Expand Down

0 comments on commit c8a9942

Please sign in to comment.