Browse Source
Merge pull request #1291 from SixLabors/bp/bufferStreamGuard
Change position guard from MustBeLessThanTo to MustBeLessThanOrEqualTo
pull/1303/head
James Jackson-South
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
2 deletions
-
src/ImageSharp/IO/BufferedReadStream.cs
-
tests/ImageSharp.Tests/IO/BufferedReadStreamTests.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.
|
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|