From 1339344a7fd3d0b578a2ee86185a582383a37cc8 Mon Sep 17 00:00:00 2001 From: Yaokun Zhang - nju <76199015+yaokunzhang@users.noreply.github.com> Date: Tue, 12 May 2026 22:28:59 +0800 Subject: [PATCH] Add advisory for potato: RefStr::from_slice() allows invalid UTF-8 from safe code --- crates/potato/RUSTSEC-0000-0000.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 crates/potato/RUSTSEC-0000-0000.md diff --git a/crates/potato/RUSTSEC-0000-0000.md b/crates/potato/RUSTSEC-0000-0000.md new file mode 100644 index 0000000000..12723083d8 --- /dev/null +++ b/crates/potato/RUSTSEC-0000-0000.md @@ -0,0 +1,27 @@ +```toml +[advisory] +id = "RUSTSEC-0000-0000" +package = "potato" +date = "2026-05-02" +url = "https://github.com/fawdlstty/potato/issues/1" +informational = "unsound" +categories = ["memory-corruption"] +keywords = ["undefined-behavior", "utf-8"] + +[versions] +patched = [] +``` + +# `RefStr::from_slice()` allows constructing invalid UTF-8 from safe code + +`RefStr::from_slice(data, start, len)` is declared safe but uses +`unsafe { data.get_unchecked(start) }` internally without validating `start` +and `len`. Callers can construct a `RefStr` pointing to arbitrary bytes. + +Combined with `to_str()`, which calls `std::str::from_utf8_unchecked()` on +the underlying bytes, a caller can produce an invalid `&str` that violates +Rust's safety requirements. For example, slicing a multi-byte UTF-8 character +in the middle produces an invalid `&str`. + +Both `from_slice()` and `to_str()` are public safe APIs, so this undefined +behavior can be triggered without writing any `unsafe` code. \ No newline at end of file