[System.Private.Xml] Possible incorrect behavior in character counting ( maxCharsCount >= charsCount )

Open
#111,969 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
backend

Research direction

Start in src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs at the Debug.Assert on line 3626, using the linked corpus_file_for_xml_crash.txt and the provided SharpFuzz reproduction. Build .NET v6.0.36 in Debug mode with asserts enabled and run the XML reader loop. Done means the corpus no longer causes the maxCharsCount and charsCount assertion to fail.

Written by the indexing model from the issue text.

Description

area-System.Xml
Description

Hello! I decided to test System.Private.Xml module via fuzzing test.
After some time I found test case which fails Debug.Assert(maxCharsCount >= charsCount)

Image

Reproduction Steps

Download latest .NET v6.0.36 and build it in Debug mode (enable asserts), make reference in test project.
Test's project code:

using SharpFuzz;
using System.Xml;

Fuzzer.Run(stream =>
    {
        try
        {
            using (var xml = XmlReader.Create(stream))
            {
                while (xml.Read()) { }
            }
        }
        catch (XmlException) { }
    }
);

corpus_file_for_xml_crash.txt

In result, value of maxCharsCount is 80 and charsCount is 81 - that produce a crash

Expected behavior

No any crash, as usual

Actual behavior

Debug.Assert(maxCharsCount >= charsCount) is failed because 80 >= 81 is false

Regression?

No response

Known Workarounds

No response

Configuration

.NET v6.0.36 from github, Debug build (enable asserts), Linux Ubuntu x64

Other information

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.