Skip to content

RTL_OSVERSIONINFOEX uses incorrect charset #27456

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!

Activity

  1. added a commit that references this issue on Sep 24, 2018
  2. transferred this issue fromdotnet/corefxon Jan 31, 2020
  3. added this to the 3.0 milestone on Jan 31, 2020
  4. ghost locked as resolved and limited conversation to collaborators on Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions