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

Document AllocateUninitializedArray security and performance traps #8249

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion xml/System/GC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,19 @@ If pinned is set to `true`, `T` must not be a reference type or a type that cont
<param name="length">Specifies the length of the array.</param>
<param name="pinned">Specifies whether the allocated array must be pinned.</param>
<summary>Allocates an array while skipping zero-initialization, if possible.</summary>
<returns>An array object with uninitialized memory except if it contains references or if it's too small for unpinned.</returns>
<returns>An array object with uninitialized memory.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks

If pinned is set to `true`, `T` must not be a reference type or a type that contains object references.

Skipping zero-initialization is a security risk. The unitialized array can contain invalid valuetype instances or sensitive information created by other parts of the application.
The code operating on unitialized arrays should be heavily scrutinized to ensure that the unitialized data is never read.

Skipping zero-initialization is only profitable for large arrays, such as buffers of several kilobytes or more.
jkotas marked this conversation as resolved.
Show resolved Hide resolved

]]></format>
</remarks>
</Docs>
Expand Down