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

C# 7.3 allows unmanaged pointer to fixed field without pinning #26743

Closed
saucecontrol opened this issue May 9, 2018 · 2 comments
Closed

C# 7.3 allows unmanaged pointer to fixed field without pinning #26743

saucecontrol opened this issue May 9, 2018 · 2 comments

Comments

@saucecontrol
Copy link
Member

saucecontrol commented May 9, 2018

Version Used: C# 7.3 / VS 15.7.1

Steps to Reproduce:

Using an explicit this pointer to work around #26688, I am able to take the address of a fixed field, giving me an unmanaged pointer without pinning. If I'm understanding the relaxed restrictions correctly, this should not be possible, as the pointer should only be useable as an indexer.

unsafe struct Foo
{
	private fixed byte buff1[256];
	private fixed byte buff2[256];

	public void DoUnsafeThing()
	{
		Buffer.MemoryCopy(&this.buff1[0], &this.buff2[0], 256, 256);
	}
}
@jcouv
Copy link
Member

jcouv commented May 9, 2018

Tagging @VSadov to confirm.

For reference, the speclet on the relevant C# 7.3 feature.

@jcouv jcouv added this to the 15.8 milestone May 9, 2018
@gafter gafter self-assigned this May 16, 2018
@gafter gafter added this to Next Up in Compiler: Gafter May 16, 2018
@OmarTawfik OmarTawfik self-assigned this May 16, 2018
@gafter gafter removed this from Next Up in Compiler: Gafter May 16, 2018
@OmarTawfik
Copy link
Contributor

  • public int* M => &this.Bar[0];
  • public int* M => &Bar[0];

Both forms were previously illegal, and now the first form is allowed (a bug, I believe). I think we should tighten the constraints and make both forms illegal.

@gafter gafter removed their assignment Jun 1, 2018
@gafter gafter added the Bug label Jun 1, 2018
@OmarTawfik OmarTawfik added the 4 - In Review A fix for the issue is submitted for review. label Jun 4, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants