Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ImageSharp/Memory/Buffer2D{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ internal Memory<T> GetSafeRowMemory(int y)
{
DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y));
DebugGuard.MustBeLessThan(y, this.Height, nameof(y));
return this.FastMemoryGroup.View.GetBoundedSlice(y * this.Width, this.Width);
return this.FastMemoryGroup.View.GetBoundedSlice(y * (long)this.Width, this.Width);
}

/// <summary>
Expand Down Expand Up @@ -200,7 +200,7 @@ internal static void SwapOrCopyContent(Buffer2D<T> destination, Buffer2D<T> sour
}

[MethodImpl(InliningOptions.ColdPath)]
private Memory<T> GetRowMemorySlow(int y) => this.FastMemoryGroup.GetBoundedSlice(y * this.Width, this.Width);
private Memory<T> GetRowMemorySlow(int y) => this.FastMemoryGroup.GetBoundedSlice(y * (long)this.Width, this.Width);

[MethodImpl(InliningOptions.ColdPath)]
private Memory<T> GetSingleMemorySlow() => this.FastMemoryGroup.Single();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -38,6 +38,12 @@ internal static Memory<T> GetBoundedSlice<T>(this IMemoryGroup<T> group, long st
Guard.MustBeLessThan(start, group.TotalLength, nameof(start));

int bufferIdx = (int)(start / group.BufferLength);

if (bufferIdx < 0)
{
throw new ArgumentOutOfRangeException(nameof(start));
}

if (bufferIdx >= group.Count)
{
throw new ArgumentOutOfRangeException(nameof(start));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void GetBoundedSlice_WhenArgsAreCorrect(long totalLength, int bufferLengt

public static TheoryData<long, int, long, int> GetBoundedSlice_ErrorData = new TheoryData<long, int, long, int>()
{
{ 300, 100, -1, 91 },
{ 300, 100, 110, 91 },
{ 42, 7, 0, 8 },
{ 42, 7, 1, 7 },
Expand Down