Skip to content

Commit

Permalink
Fix LookAheadBuffer trying to read from the stream after reaching its…
Browse files Browse the repository at this point in the history
… end

+semver:patch
  • Loading branch information
aaubry committed Jan 15, 2021
1 parent c1bab8d commit 515f4ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions YamlDotNet.Test/Core/ScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.IO;
using System.Reflection;
using System;
using System.Linq;

#if !PORTABLE && !NETCOREAPP1_0
using System.Runtime.Serialization.Formatters.Binary;
Expand Down Expand Up @@ -407,6 +408,14 @@ public void Slow_stream_is_parsed_correctly()
scanner.MoveNext();
}

[Fact]
public void Issue_553_562()
{
var yaml = "MainItem4:\n" + string.Join("\n", Enumerable.Range(1, 100).Select(e => $"- {{item: {{foo1: {e}, foo2: 'bar{e}' }}}}"));

var scanner = new Scanner(new StringReader(yaml));
while (scanner.MoveNext()) ;
}

private void AssertPartialSequenceOfTokensFrom(Scanner scanner, params Token[] tokens)
{
Expand Down
10 changes: 9 additions & 1 deletion YamlDotNet/Core/LookAheadBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// SOFTWARE.

using System;
using System.Diagnostics;
using System.IO;
using YamlDotNet.Helpers;

Expand Down Expand Up @@ -125,14 +126,19 @@ public void Cache(int length)

private void FillBuffer()
{
if (endOfInput)
{
return;
}

var remainingSize = blockSize;
do
{
var readCount = input.Read(buffer, writeOffset, remainingSize);
if (readCount == 0)
{
endOfInput = true;
break;
return;
}

remainingSize -= readCount;
Expand All @@ -144,6 +150,8 @@ private void FillBuffer()
{
writeOffset = 0;
}

Debug.Assert(writeOffset == 0 || writeOffset == blockSize);
}

/// <summary>
Expand Down

0 comments on commit 515f4ec

Please sign in to comment.