Skip to content

Panic in std #127563

Closed
Closed
@Trini7

Description

@Trini7

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) }

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 10, 2024
bjorn3

bjorn3 commented on Jul 10, 2024

@bjorn3
Member

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

Trini7 commented on Jul 10, 2024

@Trini7
Author

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

eggyal

eggyal commented on Jul 10, 2024

@eggyal
Contributor

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

added
O-linuxOperating system: Linux
T-libsRelevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 10, 2024
Noratrieb

Noratrieb commented on Jul 10, 2024

@Noratrieb
Member

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

Trini7 commented on Jul 10, 2024

@Trini7
Author
image
Noratrieb

Noratrieb commented on Jul 10, 2024

@Noratrieb
Member

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

Trini7

Trini7 commented on Jul 10, 2024

@Trini7
Author

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

Noratrieb

Noratrieb commented on Jul 10, 2024

@Noratrieb
Member

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.

// We can't always expect a UTF-8 environment. When we don't get that luxury,
// it's better to give a low-quality error message than none at all.
String::from_utf8_lossy(CStr::from_ptr(p).to_bytes()).into()

added a commit that references this issue on Jul 21, 2024

Rollup merge of rust-lang#127583 - Nilstrieb:invalid-utf8, r=joboet

bf8b40e

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-linuxOperating system: LinuxT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @eggyal@Trini7@bjorn3@rustbot@Noratrieb

      Issue actions

        Panic in std · Issue #127563 · rust-lang/rust