Skip to content

Commit 7ce329a

Browse files
Merge pull request #2732 from SixLabors/fix-allocator-overlflow-2.1
[2.1] Fix overflow in MemoryAllocator.Create(options)
2 parents f21d641 + 8699557 commit 7ce329a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.github/workflows/build-and-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
sdk-preview: true
2323
runtime: -x64
2424
codecov: false
25-
- os: macos-latest
25+
- os: macos-13 # macos-latest runs on arm64 runners
2626
framework: net6.0
2727
sdk: 6.0.x
2828
sdk-preview: true
@@ -38,7 +38,7 @@ jobs:
3838
framework: net5.0
3939
runtime: -x64
4040
codecov: false
41-
- os: macos-latest
41+
- os: macos-13 # macos-latest runs on arm64 runners
4242
framework: net5.0
4343
runtime: -x64
4444
codecov: false
@@ -50,7 +50,7 @@ jobs:
5050
framework: netcoreapp3.1
5151
runtime: -x64
5252
codecov: false
53-
- os: macos-latest
53+
- os: macos-13 # macos-latest runs on arm64 runners
5454
framework: netcoreapp3.1
5555
runtime: -x64
5656
codecov: false

src/ImageSharp/Memory/Allocators/MemoryAllocator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static MemoryAllocator Create(MemoryAllocatorOptions options)
5151
UniformUnmanagedMemoryPoolMemoryAllocator allocator = new(options.MaximumPoolSizeMegabytes);
5252
if (options.AllocationLimitMegabytes.HasValue)
5353
{
54-
allocator.MemoryGroupAllocationLimitBytes = options.AllocationLimitMegabytes.Value * 1024 * 1024;
54+
allocator.MemoryGroupAllocationLimitBytes = options.AllocationLimitMegabytes.Value * 1024L * 1024L;
5555
allocator.SingleBufferAllocationLimitBytes = (int)Math.Min(allocator.SingleBufferAllocationLimitBytes, allocator.MemoryGroupAllocationLimitBytes);
5656
}
5757

tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,5 +436,21 @@ static void RunTest()
436436
}
437437
}
438438
#endif
439+
440+
[ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))]
441+
public void MemoryAllocator_Create_SetHighLimit()
442+
{
443+
RemoteExecutor.Invoke(RunTest).Dispose();
444+
static void RunTest()
445+
{
446+
const long threeGB = 3L * (1 << 30);
447+
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
448+
{
449+
AllocationLimitMegabytes = (int)(threeGB / 1024)
450+
});
451+
using MemoryGroup<byte> memoryGroup = allocator.AllocateGroup<byte>(threeGB, 1024);
452+
Assert.Equal(threeGB, memoryGroup.TotalLength);
453+
}
454+
}
439455
}
440456
}

0 commit comments

Comments
 (0)