Browse Source

Change position guard from MustBeLessThanTo to MustBeLessThanOrEqualTo

pull/1291/head
Brian Popow 6 years ago
parent
commit
5c6b6c72c7
  1. 2
      src/ImageSharp/IO/BufferedReadStream.cs
  2. 16
      tests/ImageSharp.Tests/IO/BufferedReadStreamTests.cs

2
src/ImageSharp/IO/BufferedReadStream.cs

@ -87,7 +87,7 @@ namespace SixLabors.ImageSharp.IO
set
{
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Position));
Guard.MustBeLessThan(value, this.Length, nameof(this.Position));
Guard.MustBeLessThanOrEqualTo(value, this.Length, nameof(this.Position));
// Only reset readBufferIndex if we are out of bounds of our working buffer
// otherwise we should simply move the value by the diff.

16
tests/ImageSharp.Tests/IO/BufferedReadStreamTests.cs

@ -322,7 +322,21 @@ namespace SixLabors.ImageSharp.Tests.IO
using (var reader = new BufferedReadStream(this.configuration, stream))
{
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = -stream.Length);
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = stream.Length);
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = stream.Length + 1);
}
}
}
[Fact]
public void BufferedStreamCanSetPositionToEnd()
{
var bufferSize = 8;
this.configuration.StreamProcessingBufferSize = bufferSize;
using (MemoryStream stream = this.CreateTestStream(bufferSize * 2))
{
using (var reader = new BufferedReadStream(this.configuration, stream))
{
reader.Position = reader.Length;
}
}
}

Loading…
Cancel
Save