[CSHARP-3297] JsonScanner.GetNextToken() never returns with incomplete regular expressions Created: 30/Dec/20  Updated: 28/Oct/23  Resolved: 19/Feb/21

Status: Closed
Project: C# Driver
Component/s: Json
Affects Version/s: None
Fix Version/s: 2.12.0

Type: Bug Priority: Minor - P4
Reporter: Ryan Kyser Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows



 Description   

In the following example, jsonReader.ReadBsonType() will never return.

 

using (var jsonReader = new JsonReader("/"))
{
    Console.WriteLine("before");            
    jsonReader.ReadBsonType();
    Console.WriteLine("after");
}

 

The problem resides within JsonScanner.GetRegularExpressionToken() as it doesn't account for a -1 return code from buffer.Read() during the RegularExpressionState.InPattern state. GetRegularExpressionToken() will spin indefinitely without yielding.

This can be fixed with a single line:

 case RegularExpressionState.InPattern:
    switch (c)
    {
        case '/': state = RegularExpressionState.InOptions; break;
        case '\\': state = RegularExpressionState.InEscapeSequence; break;
        // This is the fix
        case -1: state = RegularExpressionState.Invalid; break;
        default: state = RegularExpressionState.InPattern; break;
    }
    break;

I will be submitting a pull request soon.



 Comments   
Comment by Githook User [ 19/Feb/21 ]

Author:

{'name': 'Ryan Kyser', 'email': 'ryan.kyser@avasure.com'}

Message: CSHARP-3297: Handle incomplete regex patterns in JsonScanner
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f4e6f6e5ab462267033b82e362d5f070fdba4480

Comment by James Kovacs [ 22/Jan/21 ]

Hi, Ryan,

This ticket was closed in error by an automated process as it doesn't see conversations on GitHub PRs. I've re-opened the issue while you and rstam work through any remaining issues/questions on your PR. Thank you for your contribution!

James

Comment by Ryan Kyser [ 22/Jan/21 ]

Hi there!

I saw that this was closed. There is an open pull request that I have been working on with Robert Stam.

I don't know what your process is, but does it make sense to keep this open until that pull request is resolved?

Thanks!

Comment by Backlog - Core Eng Program Management Team [ 22/Jan/21 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Ryan Kyser [ 30/Dec/20 ]

Pull request: https://github.com/mongodb/mongo-csharp-driver/pull/430

Generated at Wed Feb 07 21:44:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.