fix: memory corruption issue in NativeMemoryManager (#1013)

This commit is contained in:
bd_ 2024-08-17 18:44:12 -07:00 committed by GitHub
parent 7a20eaf57e
commit e5af635bd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.Collections; using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe; using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
#endregion #endregion
@ -134,6 +135,15 @@ namespace nadena.dev.modular_avatar.core.armature_lock
void SetInUseMask(int offset, int length, bool value) void SetInUseMask(int offset, int length, bool value)
{ {
if (offset < 0)
{
throw new ArgumentOutOfRangeException();
}
// We perform trial creations of segments (and then immediately free them if they exceed the bounds of the
// array). As such, we clamp the length, rather than throwing an exception.
length = Math.Min(length, InUseMask.Array.Length - offset);
unsafe unsafe
{ {
UnsafeUtility.MemSet((byte*)InUseMask.Array.GetUnsafePtr() + offset, value ? (byte)1 : (byte)0, length); UnsafeUtility.MemSet((byte*)InUseMask.Array.GetUnsafePtr() + offset, value ? (byte)1 : (byte)0, length);