Skip to content

Commit

Permalink
Merge pull request #659 from dmitry-ra/fix-issue-638
Browse files Browse the repository at this point in the history
Fix #638: Parser hangs on stream of `%Y`
  • Loading branch information
EdwardCooke authored Jul 13, 2022
2 parents 28c32c5 + 898dea8 commit 6e8d6d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions YamlDotNet.Test/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ public void SerializeCircularReference()
action.ShouldNotThrow();
}

[Fact]
public void DeserializeIncompleteDirective()
{
Action action = () => Deserializer.Deserialize<object>(UsingReaderFor("%Y"));

action.ShouldThrow<SyntaxErrorException>()
.WithMessage("While scanning a directive, found unexpected end of stream.");
}

[Fact]
public void DeserializeSkippedReservedDirective()
{
Action action = () => Deserializer.Deserialize<object>(UsingReaderFor("%Y "));

action.ShouldNotThrow();
}

[Fact]
public void DeserializeCustomTags()
{
Expand Down
9 changes: 8 additions & 1 deletion YamlDotNet/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ private void FetchDirective()

default:
// warning: skipping reserved directive line
while (!analyzer.Check('#') && !analyzer.IsBreak())
while (!analyzer.EndOfInput && !analyzer.Check('#') && !analyzer.IsBreak())
{
Skip();
}
Expand Down Expand Up @@ -2284,6 +2284,13 @@ private string ScanDirectiveName(in Mark start)
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, could not find expected directive name.");
}

// Check for end of stream

if (analyzer.EndOfInput)
{
throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, found unexpected end of stream.");
}

// Check for an blank character after the name.

if (!analyzer.IsWhiteBreakOrZero())
Expand Down

0 comments on commit 6e8d6d1

Please sign in to comment.