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

Able to convert OpaqueIpcMessage to "smaller" sized types. #239

Open
gatoWololo opened this issue Jul 26, 2019 · 0 comments
Open

Able to convert OpaqueIpcMessage to "smaller" sized types. #239

gatoWololo opened this issue Jul 26, 2019 · 0 comments

Comments

@gatoWololo
Copy link

The following minimal example reproduces the error (I'm using the latest crates.io version of ipc-channel but I bet it works with latest commit on master as well):

use ipc_channel::ipc;
use ipc_channel::router::ROUTER;

fn main() -> Result<(), std::io::Error> {
    let (sender, receiver) = ipc::channel::<(i32, i32)>()?;
    // Use this second channel to force main thread to block until child thread
    // is done.
    let (sender2, receiver2) = ipc::channel()?;

    ROUTER.add_route(receiver.to_opaque(), Box::new(move |msg|{
        match msg.to::<i32>() {
            Ok(val) => println!("Val: {:?}", val),
            Err(e) =>  println!("Error: {:?}", e),
        };
        sender2.send(());
    }));

    sender.send((1234, 5678)).unwrap();
    receiver2.recv().unwrap();
    Ok(())
}

Which happily outputs: Val: 1234.

Basically I'm able to convert the (i32, i32) to a i32 through to::<i32>(). I only tried it for numerical types, but it seems we have observed this behavior for less trivial types: servo/servo#23818 (comment)

I'm planning to (ab)use this behavior... but it seems a little undefined-behaviory to me?

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