Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects

Please error, or at least warn, when a managed type is included in INetworkSerializeByMemcpy

Open
#3,830 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Tracking type:feature
Dominant language
C#
Stars
2.3k
Forks
461
Avg merge
3d 16h
Merged PRs (30d)
20

Description

Is your feature request related to a problem? Please describe.

My coworker was unfamiliar with INetworkSerializeByMemcpy and the FixedStringNNNBytes types, and added a string field to an existing INetworkSerializeByMemcpy struct. This caused me great headaches (it made it into a publicly released patch), trying to track down segfault heap corruption that only showed up in very specific multiplayer circumstances (the string was normally null, which probably masked the issue).

Describe the solution you'd like

Please cause a build error when a managed type (a class, a string, or the like) is included in an INetworkSerializeByMemcpy type. I cannot think of any use case where it would be valid or intended to serialize a managed GC pointer by memcpy. At least a warning if nothing else.

It doesn't have to be perfect, even just checking for string would be lovely - string specifically is such a massive footgun, it's so easy to accidentally include and think it'll work fine. The fact it crashes later on via unrelated segfault heap corruption bringing down the editor, instead of a C# Exception, is especially rough.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the INetworkSerializeByMemcpy definition and its validation or serialization tests. Trace how implementing types are checked during compilation or runtime, then add coverage for string and other managed fields; done means such types produce a build error or warning instead of unsafe memcpy serialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.