Skip to content

RTL_OSVERSIONINFOEX uses incorrect charset #27456

Closed
@kpreisser

Description

@kpreisser

Hi,

this is a similar issue as CommunityToolkit/WindowsCommunityToolkit#2095.

On Windows, RuntimeInformation.OSDescription calls Interop.RtlGetVersion() using the RTL_OSVERSIONINFOEX structure, which is currently defined as follows:
https://github.com/dotnet/corefx/blob/a75d30306975040b0e22390d04a3b3de094d1817/src/Common/src/Interop/Windows/NtDll/Interop.RTL_OSVERSIONINFOEX.cs#L12-L22

Note that the CharSet is not specified, which means the runtime will assume a ANSI charset, whereas the native RtlGetVersion() expects Unicode. This means the szCSDVersion field will not correctly be marshalled and Marshal.SizeOf<NtDll.RTL_OSVERSIONINFOEX>() returns 148 instead of 276.

The declaration should be changed to:

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        internal struct RTL_OSVERSIONINFOEX
        {
            // ...
        }

Code

Run the following C# program with .NET Core on Windows 7 SP1:

using System;
using System.Runtime.InteropServices;

class DisplayOSDescription
{
    static void Main()
    {
        Console.WriteLine($"OSDescription: '{RuntimeInformation.OSDescription}'");
        Console.ReadLine();
    }
}

Actual Output:

OSDescription: 'Microsoft Windows 6.1.7601 S'

Expected Output:

OSDescription: 'Microsoft Windows 6.1.7601 Service Pack 1'

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions