Skip to content

Commit 6c2ae96

Browse files
authored
Use safe version of Helper.ToBytes when calculating data hashes in Species.cs (#271)
1 parent 8939b18 commit 6c2ae96

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

WarpLib/Sociology/Species.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,9 @@ public void ComputeVersionHash()
23412341
Builder.Append(MathHelper.GetSHA1(Helper.ToBytes(Helper.ToInterleaved(Helper.Combine(DescendantParticles.Select(p => p.Coordinates))))));
23422342
Builder.Append(MathHelper.GetSHA1(Helper.ToBytes(Helper.ToInterleaved(Helper.Combine(DescendantParticles.Select(p => p.Angles))))));
23432343

2344-
Builder.Append(MathHelper.GetSHA1(Helper.ToBytes(HalfMap1.GetHostContinuousCopy())));
2345-
Builder.Append(MathHelper.GetSHA1(Helper.ToBytes(HalfMap2.GetHostContinuousCopy())));
2346-
Builder.Append(MathHelper.GetSHA1(Helper.ToBytes(Mask.GetHostContinuousCopy())));
2344+
Builder.Append(MathHelper.GetSHA1(Helper.ToBytesSafe(HalfMap1.GetHostContinuousCopy())));
2345+
Builder.Append(MathHelper.GetSHA1(Helper.ToBytesSafe(HalfMap2.GetHostContinuousCopy())));
2346+
Builder.Append(MathHelper.GetSHA1(Helper.ToBytesSafe(Mask.GetHostContinuousCopy())));
23472347

23482348
Version = MathHelper.GetSHA1(Helper.ToBytes(Builder.ToString().ToCharArray())).Substring(0, 8);
23492349
}

WarpLib/Tools/Helper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,15 @@ public static byte[] ToBytes(float[] data)
11061106

11071107
return Bytes;
11081108
}
1109+
1110+
public static byte[] ToBytesSafe(float[] data)
1111+
{
1112+
// truncates data in byte array if necessary
1113+
byte[] Bytes = new byte[Math.Min(1 << 19, data.Length * sizeof(float))];
1114+
Buffer.BlockCopy(data, 0, Bytes, 0, Bytes.Length);
1115+
1116+
return Bytes;
1117+
}
11091118

11101119
public static byte[] ToBytes(int[] data)
11111120
{

0 commit comments

Comments
 (0)