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

Unsound public functions that are wrongly marked as safe #24

Open
safe4u opened this issue Jul 7, 2024 · 0 comments
Open

Unsound public functions that are wrongly marked as safe #24

safe4u opened this issue Jul 7, 2024 · 0 comments

Comments

@safe4u
Copy link

safe4u commented Jul 7, 2024

Hi, thanks for your contribution to substreams.

However, we have found some unsound problems in this crate.
The functions read_u32_from_heap, get_output_data, and decode_ptr are unsafe since they have requirements for the caller. Otherwise using these functions would lead to illegal memory access and more undefined behaviors.

It is certainly ok to mark the unsafe functions as safe and use them with care privately.
But considering the crate substreams is available in crates.io and these functions are public, we think it's quite necessary to make these functions more sound.

POC

use substreams::memory::get_output_data;
fn main() {
    let mut slice: [u8; 4] = [1,2,3,4];
    let data = get_output_data(slice.as_mut_ptr());
    // get an illegal Vec<u8> with 'safe' Rust and could lead to further problems
}

Suggestions

Here are some action suggestions we suggested:

  1. Mark these functions as 'unsafe' and write a clear Safety section.
  2. (recommended) For function read-u32_from_heap and decode_ptr, modify the paramter to [u8] instead of seperated pointer and len.
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

No branches or pull requests

1 participant