Browse Source
Merge pull request #1180 from SixLabors/js/fix-1167
Cast to long and add test/guard.
pull/1186/head
James Jackson-South
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
10 additions and
3 deletions
-
src/ImageSharp/Memory/Buffer2D{T}.cs
-
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
-
tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs
|
|
|
@ -156,7 +156,7 @@ namespace SixLabors.ImageSharp.Memory |
|
|
|
{ |
|
|
|
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>
|
|
|
|
@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.Memory |
|
|
|
} |
|
|
|
|
|
|
|
[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(); |
|
|
|
|
|
|
|
@ -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; |
|
|
|
@ -38,6 +38,12 @@ namespace SixLabors.ImageSharp.Memory |
|
|
|
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)); |
|
|
|
|
|
|
|
@ -152,6 +152,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.DiscontiguousBuffers |
|
|
|
|
|
|
|
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 }, |
|
|
|
|