Repository navigation
Bound binary operation values in ValueContentAnalysis - #57337
Evangelink wants to merge 3 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change that bounds binary-operation literal tracking to limit memory growth.
No open issues 🎉
What changed in this PR
This PR addresses excessive memory growth in CA5390 and CA5403 by applying ValueContentAnalysis’s existing 10-literal limit to binary-operation results. Operations producing more than 10 distinct values now widen to unknown, trading some analysis precision for bounded resource use.
Changes:
- Bound distinct binary results during construction and dispose the pooled set on every exit path.
- Add boundary, duplicate-result, and constant-seed xorshift regression tests.
- Document the literal limit and its precision tradeoff.
| File | Description |
|---|---|
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/ValueContentAbstractValueTests.cs |
Tests the result limit, widening, and duplicate handling. |
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.NetCore.Analyzers/Security/TaintedDataAnalyzerTestBase.cs |
Adds a shared xorshift reproduction with a configurable sink. |
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.NetCore.Analyzers/Security/DoNotHardCodeEncryptionKeyTests.cs |
Adds the CA5390 xorshift regression test. |
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.NetCore.Analyzers/Security/DoNotHardCodeCertificateTests.cs |
Adds the CA5403 xorshift regression test. |
src/Microsoft.CodeAnalysis.NetAnalyzers/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs |
Bounds binary results and guarantees pooled-set disposal. |
src/Microsoft.CodeAnalysis.NetAnalyzers/docs/writing-dataflow-analysis-based-analyzers.md |
Documents bounded literal tracking and widening behavior. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
I think this conflicts with some of the cleanup and perf improvements landed in #57054 |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Thanks for flagging this. I checked the ValueContentAnalysis changes from #57054: its |
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
add5b50113bfa24ce10fc4b842baa6f3d15891b4↑ Both affected rules completed post-merge performance checks.
↓ Prior CI also reported an unresolved telemetry failure; new-head CI has not been inspected.
↓ Full security suite was not run; widening can reduce precision.
↑ The bounded implementation completed the same workloads.
↓ The matched-source comparison adds a reachable sink because current source prunes the original sink-free example.
Constant-seed xorshift code can cause CA5390 and CA5403 to consume excessive memory as binary operations multiply the tracked literal values. Bound distinct binary results using the existing 10-literal limit, widening to unknown on the 11th result; duplicate results do not count against the limit. Dispose the pooled set on all paths. This can reduce analysis precision for operations with more than 10 distinct results.
Fixes #57335
Measurements
On Windows, the SDK 11.0.100 compiler (
csc, no shared compilation) analyzed the constant-seed xorshift with a reachable key or certificate sink using Debug analyzer builds from the baseline and this change. Private memory was sampled every 100 ms; baseline runs were stopped at 120 seconds or 4096 MiB. The following comparison was measured before merging main:Baseline times are censored, not completed-build times. Compiler
/reportanalyzeroutput confirmed the targeted rules executed in the fixed runs. The current-source comparison includes a reachable sink because the current analyzer prunes the original sink-free example; a published analyzer separately reproduced the original issue without that sink.After merging main, one fixed-analyzer run per rule completed with exit 0: CA5390 in 2.313 s at 54.13 MiB peak private memory and CA5403 in 2.404 s at 55.67 MiB. These are not a matched comparison with the earlier baseline.
Validation
AvoidDeadConditionalCodetests: 267 passed, 1 skipped.