Skip to content

Commit

Permalink
fix: unbound allocation
Browse files Browse the repository at this point in the history
When reading an array, if the length is near int.MaxValue,
the if would overflow and the condition would allow it to proceed.

This fixes the potential attack vector
  • Loading branch information
paulpach committed Jan 15, 2021
1 parent f5d84ec commit 1fe1bf6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/NetworkReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public static T[] ReadArray<T>(this NetworkReader reader)
int length = reader.ReadPackedInt32();
if (length < 0)
return null;
if (reader.Position + length > reader.Length)
if (length > reader.Length - reader.Position)
throw new EndOfStreamException("Can't read " + length + " elements because it would read past the end of the stream. ");
var result = new T[length];
for (int i = 0; i < length; i++)
Expand Down

0 comments on commit 1fe1bf6

Please sign in to comment.