@@ -86,6 +86,11 @@ public struct VecI : IEquatable<VecI>
public static VecI FromBytes(ReadOnlySpan<byte> value)
{
+ if (value.Length < sizeof(int) * 2)
+ {
+ throw new ArgumentException("Value bytes are invalid. Span must have 8 bytes", nameof(value));
+ }
+
var x = BitConverter.ToInt32(value);
var y = BitConverter.ToInt32(value[4..]);
@@ -43,7 +43,18 @@ internal static class ClipboardHelper
}
- public static VecI GetVecI(this DataObject data, string format) => VecI.FromBytes((byte[])data.GetData(format));
+ public static VecI GetVecI(this DataObject data, string format)
+ if (!data.GetDataPresent(format))
+ return default;
+ byte[] bytes = (byte[])data.GetData(format);
+ if (bytes is { Length: < 8 })
+ return VecI.FromBytes(bytes);
public static void SetVecI(this DataObject data, string format, VecI value) => data.SetData(format, value.ToByteArray());