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

Unhandled panic on read if the byte array is not appropriate size #52

Closed
askuric opened this issue May 3, 2024 · 1 comment
Closed

Comments

@askuric
Copy link
Contributor

askuric commented May 3, 2024

Here is an example of the error happening: (support-poulpe branch but the same behavior can happen in any branch)

[ 3765.847074] reachy2-beta2 docker[1742]: core  | [ros2_control_node-1] thread '<unnamed>' panicked at /home/reachy/.cargo/git/checkouts/rustypot-999c9e34d6064e19/02a9b9f/src/device/mx.rs:37:1:
[ 3765.847130] reachy2-beta2 docker[1742]: core  | [ros2_control_node-1] called `Result::unwrap()` on an `Err` value: []

This is caused by these lines:

let val = io.read(serial_port, id, $addr, size_of::<$reg_type>().try_into().unwrap())?;
let val = $reg_type::from_le_bytes(val.try_into().unwrap());

Basically if the received data from io.read are not the same size as the size of $reg_type the val.try_into().unwrap() will panic because val.try_into() will return an error which will then be unwrapped.

In my case I could only reproduce the case where the io.read returns and empty byte vector, I am not sure if other cases where the byte vector would be too small or too large can happen.

@askuric
Copy link
Contributor Author

askuric commented May 4, 2024

Fixed with #53

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