Skip to content

Conversation

@Berrysoft
Copy link
Member

Closes #581
Closes #582

@Berrysoft Berrysoft added this to the v0.18 milestone Dec 18, 2025
@Berrysoft Berrysoft self-assigned this Dec 18, 2025
@Berrysoft Berrysoft added bug Something isn't working package: buf Related to compio-buf labels Dec 18, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds explicit safety requirements to buffer length manipulation methods by making map_advanced and map_vec_advanced unsafe functions. This ensures callers are aware that these methods call set_len internally, which has safety requirements about the validity of the new length.

Key changes:

  • Made BufResultExt::map_advanced and VecBufResultExt::map_vec_advanced trait methods unsafe
  • Updated all call sites to wrap these method calls in unsafe blocks
  • Removed begin_or_cap() method in Slice<T> and replaced its usage with begin_or_len()

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
compio-driver/src/op.rs Added unsafe to trait method signatures for map_advanced and map_vec_advanced, with safety documentation explaining the requirements
compio-buf/src/slice.rs Removed begin_or_cap() helper method and changed range() to use begin_or_len() instead
compio-process/src/windows.rs Updated ChildStdout and ChildStderr read implementations to call map_advanced() in unsafe blocks
compio-process/src/unix.rs Updated ChildStdout and ChildStderr read implementations to call map_advanced() in unsafe blocks
compio-net/src/socket.rs Updated multiple socket receive methods to call map_advanced() and map_vec_advanced() in unsafe blocks
compio-fs/src/stdio/windows.rs Updated Stdin read implementation to call map_advanced() in an unsafe block
compio-fs/src/pipe.rs Updated Receiver read implementations to call map_advanced() and map_vec_advanced() in unsafe blocks
compio-fs/src/file.rs Updated File read implementations to call map_advanced() and map_vec_advanced() in unsafe blocks
compio-fs/src/async_fd.rs Updated AsyncFd read implementations to call map_advanced() and map_vec_advanced() in unsafe blocks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Berrysoft
Copy link
Member Author

Clippy suggests that we should not use as_slice as the method name. @George-Miao I suggest as_init.

@George-Miao
Copy link
Member

@Berrysoft Sure. Sounds good to me.

@Berrysoft
Copy link
Member Author

It's a bit massive to change the names. I chose another way to fix the CI.

@Berrysoft
Copy link
Member Author

Ping @George-Miao

Copy link
Member

@George-Miao George-Miao left a comment

Choose a reason for hiding this comment

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

LGTM

@George-Miao George-Miao merged commit 2b2dfa4 into compio-rs:master Dec 21, 2025
53 checks passed
@Berrysoft Berrysoft deleted the dev/unsafe-map-advanced branch December 21, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working package: buf Related to compio-buf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SetLen for Slice is unsound map_advanced is unsound

2 participants