Closed baoyachi closed 6 months ago
The input str is not a valid utf8-encoded string
Valid UTF-8 is an invariant of the str
type and line 3 in that reproducer violates the safety requirement of std::str::from_utf8_unchecked
.
Code is allowed to make the assumption that str
always contains valid UTF-8, so the Debug
implementation is not at fault IMHO. This is a bug in your code. See also: https://doc.rust-lang.org/stable/std/primitive.str.html#invariant
@y21 Thx.
I tried this code:
I expected to see this happen: cargo run ok.
Instead, this happened: cargo run failed.
Meta
rustc --version --verbose
:The source code address that caused this occurrence:https://doc.rust-lang.org/src/core/fmt/mod.rs.html#2349-2350
The input str is not a valid utf8-encoded string, causing
&self[from..i]
to directly violently retrieve the array subscript and panic.The error message that caused this issue is: byte index 67 is not a char boundary; It is inside '澯' (bytes 66.. 69) of
IS~1-2023-05-18 01:10:45~10.111.5.199:36448~10.111.6.52:1523~澯~