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

fix(vm): Don't let rustc think the Array type can't exist #398

Merged
merged 2 commits into from
Nov 23, 2017

Conversation

Marwes
Copy link
Member

@Marwes Marwes commented Nov 22, 2017

The use of Void in the Array type was meant to absolutely prevent the Array type from existing except behind a pointer which is invalid (except the empty array I guess) as the elements are stored inline behind the length field.

Unfortunately rust-lang/rust#45225 made rustc think that fields of the Array type could not exist at all and placed fields of Array at the start of any struct containing them, causing any write to the Array to overwrite other fields.

Fixes #396

THe use of `Void` in the `Array` type was meant to absolutely prevent
the `Array` type from existing except behind a pointer which is invalid
(except the empty array I guess) as the elements are stored inline
behind the length field.

Unfortunately rust-lang/rust#45225 made rustc
think that fields of the `Array` type could not exist at all and placed
fields of `Array` at the start of any struct containing them, causing
any write to the `Array` to overwrite other fields.
@Marwes
Copy link
Member Author

Marwes commented Nov 22, 2017

Needs Manishearth/compiletest-rs#87

@eddyb
Copy link

eddyb commented Nov 23, 2017

Since having a valid value of type Array depends on a valid value of type Void, which cannot possibly exist, Array also cannot possibly exist, and it's UB to craft one out of thin air.
EDIT: See also rust-lang/rust#45225 (comment).

@Marwes Marwes merged commit 85e03c0 into gluon-lang:master Nov 23, 2017
vm/src/array.rs Outdated
/// Abstract array type which have their length store inline with the elements.
/// Fills the same role as Box<[T]> but takes only 8 bytes on the stack instead of 16
#[repr(C)]
pub struct Array<T: Copy> {
len: usize,
array_start: [T; 0],
_marker: self::internal::CantConstruct,
Copy link
Member

@brendanzab brendanzab Nov 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought just having private fields meant that folks couldn't construct it 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intention is that it shouldn't be constructed even accidentally from this module.

@Marwes Marwes deleted the array_offset branch December 4, 2017 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants