-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
Hi, thanks for your time to read this issue. Our static analysis tool found there might be an unsound issue in your value_to_string_unchecked converting the vallue to utf8 str:
Lines 28 to 37 in 587f1c4
| pub fn value_to_string_unchecked(value: Value) -> String { | |
| unsafe { | |
| let str = string::rb_string_value_ptr(&value) as *const u8; | |
| let len = string::rb_str_len(value) as usize; | |
| let vec = ::std::slice::from_raw_parts(str, len).to_vec(); | |
| String::from_utf8_unchecked(vec) | |
| } | |
| } |
This may introduce invalid utf8 conversion and producing an invalid value, which is considered as undefined behaviors in Rust. We expect either to mark the whole function as unsafe or leverage the safe verison to convert because this library can take raw bytes from the Ruby sys and missed the validation of utf8. As a reference, the safe version of the utf8 conversion in std is:
Could you please help us double check the potential probelm? Thanks again for your time.
Metadata
Metadata
Assignees
Labels
No labels