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

Corrupt data in struct passed to method via reflection on Unix #6834

Closed
stephentoub opened this issue Oct 18, 2016 · 6 comments
Closed

Corrupt data in struct passed to method via reflection on Unix #6834

stephentoub opened this issue Oct 18, 2016 · 6 comments
Assignees

Comments

@stephentoub
Copy link
Member

Repro:

using System;
using System.Reflection;

public class Program
{
    public static void Main(string[] args)
    {
        var r = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);
        DoStuff(r);
        typeof(Program).GetTypeInfo().GetDeclaredMethod("DoStuff").Invoke(null, new object[] { r });
    }

    public static void DoStuff(RectangleF r)
    {
        Console.WriteLine(r);
    }
}

public struct RectangleF
{
    private float _x, _y, _width, _height;

    public RectangleF(float x, float y, float width, float height)
    {
        _x = x; _y = y; _width = width; _height = height;
    }

    public override string ToString() => $"[{_x}, {_y}, {_width}, {_height}]";
}

On CentOS and Ubuntu, this outputs various forms of:

[1.2, 3.4, 5.6, 7.8]
[1.2, 3.4, 1.699571E-38, 0]

with the reflection-based call getting garbage for two of the floats in the struct.

I got the above repro using the 1.0.1 release, but I started looking into it because of a CI failure in a new test I was adding on top of the latest coreclr pulled into corefx. (The issue that was happening in CI was only happening on CentOS for some reason, not on Ubuntu or OSX. I've not tried the above repro on OSX.)

@stephentoub stephentoub changed the title Corrupt data in struct passed to method via reflection on CentOS Corrupt data in struct passed to method via reflection on Unix Oct 18, 2016
@cmckinsey
Copy link
Contributor

@stephentoub smells like ABI issue. this is on x64?

@janvorli janvorli self-assigned this Oct 18, 2016
@janvorli
Copy link
Member

Let me dig into that.

@stephentoub
Copy link
Member Author

this is on x64?

Yup

@janvorli
Copy link
Member

It is really a bug in copying float args to the transition frame in the runtime. It happens when a struct uses two xmm registers. The offset to the next floating point register in the transition frame is shifted by 8 instead of by 16. I have fixed the same issue in the runtime for passing floating point arguments about a year ago, but obviously haven't realized that we have it at this other place.
I will submit a PR with a fix and a related regression test soon.

@stephentoub
Copy link
Member Author

Thanks, @janvorli.

@janvorli
Copy link
Member

Fixed by dotnet/coreclr#7716

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants