rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.52k stars 12.47k forks source link

Panic in std #127563

Closed Trini7 closed 1 month ago

Trini7 commented 1 month ago

version: nightly-2023-11-22 os: centos-7

panic: thread '' panicked at library/std/src/sys/unix/net.rs:50:76: called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 4, error_len: Some(1) } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace thread '' panicked at library/std/src/sys/unix/net.rs:50:76: called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 4, error_len: Some(1) } thread '' panicked at library/std/src/sys/unix/net.rs:50:76: called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 4, error_len: Some(1) } thread '' panicked at library/std/src/sys/unix/net.rs:50:76: called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 4, error_len: Some(1) }

bjorn3 commented 1 month ago

You are using a nightly that is over half a year old. Try using the latest nightly to see if it reproduces. If it does, please set RUST_BACKTRACE=1 and report back the printed backtrace as well as the project on which you get this panic.

Trini7 commented 1 month ago

Based on my testing, the latest version also has this issue.

eggyal commented 1 month ago

It would appear that your libc's gai_strerror function is not returning a UTF-8 encoded string (the fourth byte is invalid).

Noratrieb commented 1 month ago

Can you share some of your system config, especially your locale? gai_strerror returning invalid UTF-8 is certainly not something expected by std.

Trini7 commented 1 month ago
image
Noratrieb commented 1 month ago

Which Chinese locale exactly? Could you show the values of the LC_ environment variables?

Trini7 commented 1 month ago

Sorry, the environment is no longer available, but it seems that using unwrap in net.rs:50:76 is too risky.

Noratrieb commented 1 month ago

It's probably not a UTF-8 locale. I would really recommend changing your locale to a UTF-8 one if possible, then this should work again. But you're right, this unwrap shouldn't be there, normal strerror uses from lossy, which will give a bad error but at least won't crash. I'll send a PR. https://github.com/rust-lang/rust/blob/b215beb567857000fdaa868cbb78702bc5ee0ee9/library/std/src/sys/pal/unix/os.rs#L135-L137