Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix evil allocations, marshaling overhead #329

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kein
Copy link

@Kein Kein commented Apr 13, 2021

StrToPtr() had at least 4 extra allocations of byte[] and char[] arrays that will make Unity's GC and frametime stability sad, taking into account you can updated 5 times per 20 seconds, which is few frames apart.
Also, there was 0 reason to have that marshaling invoke overhead where it zeroes byte by byte in a loop. There is no point, we already overwrite whole memory via .Copy() and we only allocate as much as needed for the string bytes, no extra. No security concerns here.

The only question that eludes me is the limitation of 128 bytes. It was not enforced on managed side in old code, and I could not find anything in native library. So I assume it is enforced on RPC server side then? Either way since limit is 128 bytes aka 128 ASCII characters at min, it makes sense to limit allocated data to 128 chars max to avoid sending perhaps megabytes of mistakenly generated by user string (I assume it will throw in pipe/socket).

StrToPtr() had at least 4 extra allocations of byte[] and char[] arrays that will make Unity's GC and frametime stability sad, taking into account you can updated 5 times per 20 seconds, which is few frames apart.
Also, there was 0 reason to have that marshaling invoke overhead where it zeroes byte by byte in a loop. There is no point, we already overwrite whole memory via .Copy() and we only allocate as much as needed, no extra. No security concerns here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant