Skip to content

Fix SA1627/SA1651 crash on <include> with no documented member - #4380

Merged
AArnott merged 1 commit into
masterfrom
aarnott-fuzz-sa1627-sa1651-empty-include
Oct 25, 2026
Merged

AArnott merged 1 commit into
masterfrom
aarnott-fuzz-sa1627-sa1651-empty-include

Conversation

@AArnott

@AArnott AArnott commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Found by the fuzz harness (tools/StyleCop.Analyzers.Fuzz, mutate campaigns with random seeds 2026/909/87109/95028 over the extracted-literal corpus).

Bug: SA1627 and SA1651 throw XmlException: Root element is missing (AD0001) when an <include> documentation comment is placed before the closing brace of an undocumented type (valid code; the compiler only reports CS1587). The expanded include documentation is empty, and it was passed straight to XElement.Parse.

Fix: return early when the expanded documentation is null or empty.

Tests: TestIncludedDocumentationBeforeCloseBraceOfUndocumentedTypeAsync in SA1627UnitTests and SA1651UnitTests. Both failed with AD0001 before the fix.

Analyzer cost: one string.IsNullOrEmpty check on a path that already parses XML. Negligible.

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.63%. Comparing base (46245d0) to head (3821604).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4380   +/-   ##
=======================================
  Coverage   97.63%   97.63%           
=======================================
  Files        1345     1345           
  Lines      151674   151698   +24     
  Branches     5216     5218    +2     
=======================================
+ Hits       148082   148106   +24     
  Misses       2268     2268           
  Partials     1324     1324           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AArnott
AArnott marked this pull request as ready for review October 25, 2026 14:39
Copilot AI balanced review requested due to automatic review settings October 25, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow guards address the crash without changing nonempty-documentation analysis, and both affected analyzers have targeted regression tests.

No open issues 🎉

What changed in this PR

This PR prevents SA1627 and SA1651 from crashing when an orphaned <include> documentation comment produces empty expanded XML.

Changes:

  • Skip XML parsing when expanded documentation is null or empty, preserving analysis of nonempty documentation.
  • Add regression tests for both analyzers covering an include comment before an undocumented type’s closing brace.
File Description
test/​StyleCop.Analyzers.Test/​DocumentationRules/​SA1651UnitTests.cs Adds regression coverage for the SA1651 crash.
test/​StyleCop.Analyzers.Test/​DocumentationRules/​SA1627UnitTests.cs Adds regression coverage for the SA1627 crash.
src/​StyleCop.Analyzers/​DocumentationRules/​SA1651DoNotUsePlaceholderElements.cs Returns false before parsing empty documentation.
src/​StyleCop.Analyzers/​DocumentationRules/​SA1627DocumentationTextMustNotBeEmpty.cs Returns early before parsing empty documentation.

Review effort: Balanced

@AArnott
AArnott merged commit 0829ac3 into master Oct 25, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-fuzz-sa1627-sa1651-empty-include branch October 25, 2026 14:46
This was referenced Nov 11, 2026
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants