Repository navigation
Description
Description
When CA5390 (Do not hard-code encryption key) or CA5403 (Do not hard-code certificate) is enabled, the compilation of the method below uses more than 6 GB after 80 seconds, and the memory keeps growing. In the project where we found it (AnalysisMode=All), the compiler used more than 25 GB for tens of minutes, and the CI runner was lost.
The method calls a xorshift generator whose seed is a constant, and passes a string built from its values to Encoding.UTF8.GetBytes. With the seed as a parameter, the build takes 2 seconds.
Encoding.GetBytes is a source method of these rules. TaintedDataSymbolMapExtensions.IsSourceMethod computes ValueContentAnalysis for the method to know whether the argument is a constant, and the values of state that the analysis tracks through the interprocedural analysis of Next do not converge.
Repro
Repro.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>.editorconfig:
root = true
[*.cs]
dotnet_diagnostic.CA5390.severity = warningRepro.cs:
using System.Text;
public static class Repro
{
public static int Run(int count)
{
var state = 0x9E3779B97F4A7C15UL; // constant seed: this is the trigger
var length = 0;
for (var i = 0; i < count; i++)
{
var text = Next(ref state).ToString();
if (Next(ref state) % 2 == 0)
{
text = "-";
}
length += Encoding.UTF8.GetBytes(text).Length;
}
return length;
// xorshift64
static ulong Next(ref ulong state)
{
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
return state;
}
}
}dotnet build -p:UseSharedCompilation=false
Watch the memory of csc.exe, and kill it before it uses all the memory of the machine.
Actual
| SDK | Constant seed | Seed as parameter (Run(ulong state, int count)) |
|---|---|---|
| 11.0.100 (NetAnalyzers 11.0.100) | 2.5 GB after 15 s, 4.8 GB after 45 s, 6.0 GB after 80 s (killed) | 2.2 s |
| 10.0.404 (NetAnalyzers 10.0.404) | 2.3 GB after 15 s, 4.8 GB after 60 s, 6.05 GB after 86 s (killed) | 2.1 s |
CA5403 alone gives the same result. No other CA5xxx rule does on its own.
Each of these changes also makes the build complete in about 2 seconds: inlining the xorshift steps in the loop, calling Next once per iteration instead of twice, replacing the if with a conditional expression, replacing Encoding.UTF8.GetBytes(text) with long.Parse(text). Making Next a private static method, or a local function that captures state, or using 10 as the loop bound, does not change the result.
Expected
The analysis completes in about the same time and memory as with the seed as a parameter: when the set of possible values does not converge, it should widen to an unknown value, or stop after a bound.
Stack
dotnet-stack report of csc.exe at 4.2 GB (SDK 11.0.100), analyzer thread:
System.Collections.Generic.HashSet`1.Resize(int32,bool)
System.Collections.Generic.HashSet`1.Add(!0)
ValueContentAnalysis.ValueContentAbstractValue.MergeBinaryOperation(...)
DataFlowOperationVisitor`4.VisitCompoundAssignment(ICompoundAssignmentOperation, object)
DataFlowOperationVisitor`4.VisitCore / Visit / VisitArray
ValueContentAnalysis+ValueContentDataFlowOperationVisitor.DefaultVisit(...)
DataFlowOperationVisitor`4.Flow(...)
DataFlowAnalysis`5.Flow / RunCore / Run
DataFlowOperationVisitor`4.PerformInterproceduralAnalysis(...)
DataFlowOperationVisitor`4.VisitInvocation_LocalFunction(...)
DataFlowOperationVisitor`4.VisitInvocation_LambdaOrDelegateOrLocalFunction(...)
DataFlowOperationVisitor`4.VisitInvocation(...)
ValueContentAnalysis+ValueContentDataFlowOperationVisitor.VisitBinaryOperatorCore(...)
DataFlowOperationVisitor`4.VisitBinaryOperator(...)
ValueContentAnalysis+ValueContentDataFlowOperationVisitor.VisitBinaryOperatorCore(...)
DataFlowOperationVisitor`4.VisitBinaryOperator(...)
DataFlowOperationVisitor`4.FlowBranch(...)
DataFlowAnalysis`5.RunCore / Run
Analyzer.Utilities.SingleThreadedConcurrentDictionary`2.GetOrAdd(...)
ValueContentAnalysis.TryGetOrComputeResult(...)
SourceTriggeredTaintedDataAnalyzerBase+<>c__DisplayClass6_1.<Initialize>b__4()
System.Lazy`1.ViaFactory / ExecutionAndPublication / CreateValue / get_Value
TaintedDataSymbolMapExtensions.IsSourceMethod(...)
SourceTriggeredTaintedDataAnalyzerBase+<>c__DisplayClass6_1.<Initialize>b__7(OperationAnalysisContext)
AnalyzerExecutor.ExecuteOperationAction(...)
In the original project, ImmutableHashSet<T>.Union was at the top of the same frames.
Workarounds
- Pass the seed as a parameter.
- Disable
CA5390andCA5403. dotnet_code_quality.max_interprocedural_lambda_or_local_function_call_chain = 0(whenNextis a local function;dotnet_code_quality.interprocedural_analysis_kind = Nonedoes not help in that case), ordotnet_code_quality.interprocedural_analysis_kind = None(whenNextis a regular method).
Versions
- .NET SDK 11.0.100 (commit 297acf930f), Roslyn 5.12.0-1.26529.118,
Microsoft.CodeAnalysis.NetAnalyzers.dll11.1.26.53018.Microsoft.CodeAnalysis.NetAnalyzers11.0.100 is the latest version on nuget.org. - .NET SDK 10.0.404, Roslyn 5.9.0-1.26529.119,
Microsoft.CodeAnalysis.NetAnalyzers.dll10.4.426.53019. - Windows 11 (10.0.28000), x64, AMD Ryzen 9 9900X.
Activity
github-actions commentedon Nov 24, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@Evangelink| @dotnet/dotnet-analyzershigh- The issue names CA5390/CA5403 and ValueContentAnalysis, matching the NetAnalyzers CODEOWNERS section.Similar issues: #57327 (
potentially related) #56280 (potentially related)➡️ Summary: CA5390 and CA5403 cause unbounded memory growth in ValueContentAnalysis on a constant-seeded xorshift loop. Add a widening or iteration bound so non-converging value sets become unknown.