YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

Exception if string is indented by more spaces than the MaxBufferLength in Scanner.cs

Open stuartbean opened this issue 4 years ago • 0 comments

Literal: |2-
          <hr>

This yaml (valid as far as I can tell) causes exception in Scanner.cs due to the following code exceeding the buffer:

                // Have we find a non-empty line?

                if (!analyzer.IsBreak())
                {
                    if (isLiteral && isFirstLine == true)
                    {
                        int localIndent = cursor.LineOffset;
                        int i = 0;
                        for (; !analyzer.IsBreak(i) && analyzer.IsSpace(i); ++i, ++localIndent) ; // BUG HERE
                        if (analyzer.IsBreak(i) && localIndent > cursor.LineOffset)
                        {
                            isFirstLine = false;
                            indentOfFirstLine = localIndent;
                        }
                    }
                    break;
                }

I cannot work out how to modify this code to achieve its original intent and protect against exceeding the buffer overrun. For now I've simply added a limit check in the for loop. I'll put up a PR with the unit test and "fix".

stuartbean avatar Jul 15 '20 06:07 stuartbean