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

Avoid UB on opaque types. #1365

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Avoid UB on opaque types. #1365

merged 1 commit into from
Feb 27, 2024

Conversation

adetaylor
Copy link
Collaborator

autocxx generates opaque types of a given length, represented by an array of bytes. Unless autocxx is configured to use CppRef, references exist to those types, and as those references pass through C++ they may not obey Rust aliasing rules. This is the main motivation behind adopting CppRef, but meanwhile, to reduce such theoretical UB, we mark the data as both MaybeUninit and UnsafeCell such that Rust makes fewer assumptions about the underlying data.

Per comments, this doesn't eliminate the chance of UB.

autocxx generates opaque types of a given length, represented by an array of
bytes. Unless autocxx is configured to use CppRef, references exist to those
types, and as those references pass through C++ they may not obey Rust aliasing
rules. This is the main motivation behind adopting CppRef<T>, but meanwhile, to
reduce such theoretical UB, we mark the data as both MaybeUninit and UnsafeCell
such that Rust makes fewer assumptions about the underlying data.

Per comments, this doesn't eliminate the chance of UB.
@adetaylor adetaylor merged commit 5e6673d into main Feb 27, 2024
21 checks passed
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.

1 participant