dotnet / dotnet/roslyn

[Unsafe evolution] StructLayout with explicitly specified Pack or Size should require unsafe

Open
#85,173 5 comments 0 reactions 1 assignee Claimed by @jjonescz View on GitHub
Area-Language Design Feature - Unsafe Evolution
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

StructLayout with explicitly specific Pack or Size can be used to create misaligned fields that in turn allows creating misaligned managed references. Safe code must be prohibited from creating unaligned managed references - documented in https://github.com/dotnet/designs/blob/main/accepted/2025/memory-safety/caller-unsafe.md (look for "Alignment of managed references").

Context: https://github.com/dotnet/runtime/issues/133236

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.