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

Mark GenericByteArray::new_unchecked unsafe #4584

Merged
merged 1 commit into from
Jul 30, 2023

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 29, 2023
@jackwener jackwener merged commit a310056 into apache:master Jul 30, 2023
25 checks passed
@@ -159,7 +159,7 @@ impl<T: ByteArrayType> GenericByteArray<T> {
/// # Safety
///
/// Safe if [`Self::try_new`] would not error
pub fn new_unchecked(
pub unsafe fn new_unchecked(
Copy link
Member

Choose a reason for hiding this comment

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

Can you please elaborate more on the why we need unsafe here?

cc @Xuanwo

Copy link
Contributor Author

@tustvold tustvold Sep 2, 2024

Choose a reason for hiding this comment

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

See the checks done by try_new, in particular that the offsets are valid, and the data is UTF-8 (if applicable)

Copy link
Member

Choose a reason for hiding this comment

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

thanks @tustvold . so this allows creating an array without validation, thus with potentially invalid data. is this also unsafe in rust unsafe sense (potential program undefined behavior)?

Copy link
Contributor Author

@tustvold tustvold Sep 2, 2024

Choose a reason for hiding this comment

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

Yes, very much so. Many kernels and methods make assumptions about data validity that would lead to UB if not upheld.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants