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

cleanup(serde_v8): simpler ZeroCopyBuf #14095

Merged
merged 2 commits into from
Apr 1, 2022

Conversation

AaronO
Copy link
Contributor

@AaronO AaronO commented Mar 23, 2022

No description provided.

Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

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

From my limited Rust-knowledge, LGTM.

serde_v8/src/magic/zero_copy_buf.rs Outdated Show resolved Hide resolved
Comment on lines +55 to +60
unsafe { &*(&self.store[self.range.clone()] as *const _ as *const [u8]) }
}

#[allow(clippy::cast_ref_to_mut)]
fn as_slice_mut(&mut self) -> &mut [u8] {
unsafe { &mut *(&self.store[self.range.clone()] as *const _ as *mut [u8]) }
Copy link
Member

Choose a reason for hiding this comment

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

// SAFETY

Copy link
Contributor

Choose a reason for hiding this comment

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

The soundness of these methods relies on the BackingStore not being deref'd during the lifetime of the returned slices. This can happen if a SharedRef<BackingStore> is stored somewhere before deserializing the ArrayBuffer, or if a single buffer is deserialized multiple times.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, but add a safety comment as pointed by Divy

@AaronO AaronO merged commit 4b33dd8 into denoland:main Apr 1, 2022
@AaronO AaronO deleted the cleanup/serde-v8-simpler-ZeroCopyBuf branch April 1, 2022 22:10
hardfist pushed a commit to hardfist/deno that referenced this pull request Aug 7, 2024
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

5 participants