Skip to content

Commit

Permalink
Fix error when a stream returns less than the requested amount of bytes
Browse files Browse the repository at this point in the history
Fixes aaubry#560
+semver:patch
  • Loading branch information
aaubry committed Jan 14, 2021
1 parent b3ae4c7 commit c7ec908
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions YamlDotNet/Core/LookAheadBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,25 @@ public void Cache(int length)

private void FillBuffer()
{
var readCount = input.Read(buffer, writeOffset, blockSize);
writeOffset = blockSize - writeOffset;
endOfInput = readCount < blockSize;
count += readCount;
var remainingSize = blockSize;
do
{
var readCount = input.Read(buffer, writeOffset, remainingSize);
if (readCount == 0)
{
endOfInput = true;
break;
}

remainingSize -= readCount;
writeOffset += readCount;
count += readCount;
} while (remainingSize > 0);

if (writeOffset == buffer.Length)
{
writeOffset = 0;
}
}

/// <summary>
Expand Down

0 comments on commit c7ec908

Please sign in to comment.