You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, thank you for your contribution in this project, I an testing our static analysis tool in github's Rust project and I notice the following code:
When processing a JSON with a "type" field containing a number (not a string), the shred function passes floating-point bytes to maybe_add_value with code 'f'.
In maybe_add_value, when it encounters the key "type", it unconditionally uses unsafe { str::from_utf8_unchecked(value) } on those bytes.
Since the bytes come from f.to_le_bytes() for a floating-point number, they aren't valid UTF-8, causing undefined behavior when interpreted as a string.
There are no checks or validations to ensure the bytes form valid UTF-8 before the unsafe operation.
This creates a direct path from user input to a memory safety violation through the add function.
A valid path to call this fn: pub fn add -> pub fn shred -> fn maybe_add_value
POC
fn main() {
let mut db = Database::new(); // Assuming appropriate constructor
let mut batch = Batch::new();
// JSON with "type" field containing a number instead of a string
let json = r#"{"type": 123.456}"#;
// Call the public function leading to undefined behavior
let result = db.add(json, &mut batch);
println!("{:?}", result);
}
The text was updated successfully, but these errors were encountered:
Hello, thank you for your contribution in this project, I an testing our static analysis tool in github's Rust project and I notice the following code:
The unsoundness occurs because:
When processing a JSON with a "type" field containing a number (not a string), the shred function passes floating-point bytes to maybe_add_value with code 'f'.
In maybe_add_value, when it encounters the key "type", it unconditionally uses unsafe { str::from_utf8_unchecked(value) } on those bytes.
Since the bytes come from f.to_le_bytes() for a floating-point number, they aren't valid UTF-8, causing undefined behavior when interpreted as a string.
There are no checks or validations to ensure the bytes form valid UTF-8 before the unsafe operation.
This creates a direct path from user input to a memory safety violation through the add function.
A valid path to call this fn: pub fn add -> pub fn shred -> fn maybe_add_value
POC
The text was updated successfully, but these errors were encountered: