Skip to content

Commit f4f689c

Browse files
Merge pull request #1291 from SixLabors/bp/bufferStreamGuard
Change position guard from MustBeLessThanTo to MustBeLessThanOrEqualTo
2 parents 493e422 + 5c6b6c7 commit f4f689c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ImageSharp/IO/BufferedReadStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override long Position
8787
set
8888
{
8989
Guard.MustBeGreaterThanOrEqualTo(value, 0, nameof(this.Position));
90-
Guard.MustBeLessThan(value, this.Length, nameof(this.Position));
90+
Guard.MustBeLessThanOrEqualTo(value, this.Length, nameof(this.Position));
9191

9292
// Only reset readBufferIndex if we are out of bounds of our working buffer
9393
// otherwise we should simply move the value by the diff.

tests/ImageSharp.Tests/IO/BufferedReadStreamTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,21 @@ public void BufferedStreamThrowsOnBadPosition(int bufferSize)
322322
using (var reader = new BufferedReadStream(this.configuration, stream))
323323
{
324324
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = -stream.Length);
325-
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = stream.Length);
325+
Assert.Throws<ArgumentOutOfRangeException>(() => reader.Position = stream.Length + 1);
326+
}
327+
}
328+
}
329+
330+
[Fact]
331+
public void BufferedStreamCanSetPositionToEnd()
332+
{
333+
var bufferSize = 8;
334+
this.configuration.StreamProcessingBufferSize = bufferSize;
335+
using (MemoryStream stream = this.CreateTestStream(bufferSize * 2))
336+
{
337+
using (var reader = new BufferedReadStream(this.configuration, stream))
338+
{
339+
reader.Position = reader.Length;
326340
}
327341
}
328342
}

0 commit comments

Comments
 (0)