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

RTL_OSVERSIONINFOEX uses incorrect charset #27456

Closed
kpreisser opened this issue Sep 23, 2018 · 0 comments
Closed

RTL_OSVERSIONINFOEX uses incorrect charset #27456

kpreisser opened this issue Sep 23, 2018 · 0 comments

Comments

@kpreisser
Copy link

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!

jkotas referenced this issue in jkotas/corefx Sep 24, 2018
- Ensure that the OS version string is marshaled as Unicode
- Avoid allocating the version string when it is not needed

Fixes #32423
ViktorHofer referenced this issue in dotnet/corefx Sep 24, 2018
- Ensure that the OS version string is marshaled as Unicode
- Avoid allocating the version string when it is not needed

Fixes #32423
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants