diff --git a/src/DotNext.IO/IO/StreamSegment.cs b/src/DotNext.IO/IO/StreamSegment.cs
index 58155d96d..58882666e 100644
--- a/src/DotNext.IO/IO/StreamSegment.cs
+++ b/src/DotNext.IO/IO/StreamSegment.cs
@@ -40,11 +40,11 @@ public StreamSegment(Stream stream, bool leaveOpen = true)
///
/// The offset in the underlying stream.
/// The length of the segment.
- /// is larger than the reamining length of the underlying stream; or if greater than the length of the underlying stream.
+ /// is larger than the remaining length of the underlying stream; or if greater than the length of the underlying stream.
public void Adjust(long offset, long length)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan((ulong)offset, (ulong)BaseStream.Length, nameof(offset));
- ArgumentOutOfRangeException.ThrowIfGreaterThan((ulong)offset, (ulong)(BaseStream.Length - offset), nameof(length));
+ ArgumentOutOfRangeException.ThrowIfGreaterThan((ulong)length, (ulong)(BaseStream.Length - offset), nameof(length));
this.length = length;
this.offset = offset;
diff --git a/src/DotNext.Tests/IO/StreamSegmentTests.cs b/src/DotNext.Tests/IO/StreamSegmentTests.cs
index a9b81b730..e1f6326b6 100644
--- a/src/DotNext.Tests/IO/StreamSegmentTests.cs
+++ b/src/DotNext.Tests/IO/StreamSegmentTests.cs
@@ -1,7 +1,22 @@
-namespace DotNext.IO;
+using System.Text;
+
+namespace DotNext.IO;
public sealed class StreamSegmentTests : Test
{
+ [Theory]
+ [InlineData(0, 4, "This")]
+ [InlineData(5, 2, "is")]
+ [InlineData(10, 4, "test")]
+ public static void AdjustSetsSegmentOfStream(int offset, int length, string expected)
+ {
+ using var ms = new MemoryStream(Encoding.UTF8.GetBytes("This is a test"));
+ using var segment = new StreamSegment(ms);
+ segment.Adjust(offset, length);
+ StreamReader reader = new(segment);
+ Equal(expected, reader.ReadToEnd());
+ }
+
[Fact]
public static void ReadByteSequentially()
{