Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji in manifest crashes annotate-snippets #13772

Closed
DaniPopes opened this issue Apr 18, 2024 · 1 comment · Fixed by #13780
Closed

Emoji in manifest crashes annotate-snippets #13772

DaniPopes opened this issue Apr 18, 2024 · 1 comment · Fixed by #13780
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@DaniPopes
Copy link

DaniPopes commented Apr 18, 2024

Problem

Cargo panics when reading a manifest file that contains emojis in invalid positions, while trying to display an error for them.

Cargo.toml:

😀

Steps

$ cargo new repro
$ cd repro
$ echo "😀" > Cargo.toml
$ cargo check
thread 'main' panicked at /rust/deps/annotate-snippets-0.11.1/src/renderer/display_list.rs:914:45:
byte index 1 is not a char boundary; it is inside '😀' (bytes 0..4) of `😀`
stack backtrace:
   0:     0x556fa0dd2ad5 - std::backtrace_rs::backtrace::libunwind::trace::hc79cced6f418596d
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x556fa0dd2ad5 - std::backtrace_rs::backtrace::trace_unsynchronized::h06f3eef6c8a22cf0
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x556fa0dd2ad5 - std::sys_common::backtrace::_print_fmt::hba273d0c77fc3421
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x556fa0dd2ad5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h409f1e3c1e32650e
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x556fa0e05d6b - core::fmt::rt::Argument::fmt::h8811fe3c91cda7b3
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/core/src/fmt/rt.rs:142:9
   5:     0x556fa0e05d6b - core::fmt::write::h7a8f70a9b146d9ee
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/core/src/fmt/mod.rs:1153:17
   6:     0x556fa0dccabf - std::io::Write::write_fmt::h32fb818656611c58
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/io/mod.rs:1843:15
   7:     0x556fa0dd28ae - std::sys_common::backtrace::_print::h0dc0bbf9b429a58b
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x556fa0dd28ae - std::sys_common::backtrace::print::hf60182bd4aee207d
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x556fa0dd46b9 - std::panicking::default_hook::{{closure}}::hd90db44a41f772dc
  10:     0x556fa0dd43d5 - std::panicking::default_hook::hd86be16b87521210
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:291:9
  11:     0x556fa0dd4bc4 - std::panicking::rust_panic_with_hook::ha4f8caa112a16574
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:788:13
  12:     0x556fa0dd4aa6 - std::panicking::begin_panic_handler::{{closure}}::hc879855deab44ed0
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:657:13
  13:     0x556fa0dd2f99 - std::sys_common::backtrace::__rust_end_short_backtrace::h85e59f289fdfff6c
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/sys_common/backtrace.rs:171:18
  14:     0x556fa0dd47d7 - rust_begin_unwind
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:645:5
  15:     0x556fa0e02ee6 - core::panicking::panic_fmt::h0baef2c59e253f8d
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/core/src/panicking.rs:72:14
  16:     0x556fa0e09b0b - core::str::slice_error_fail_rt::h0fde66b0a6d20273
  17:     0x556fa0e096ea - core::str::slice_error_fail::hbfd47a9ba2a36f47
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/core/src/str/mod.rs:89:5
  18:     0x556fa0427fc9 - annotate_snippets[e4e707aa9ab1739b]::renderer::display_list::format_message
  19:     0x556fa042a09e - <annotate_snippets[e4e707aa9ab1739b]::renderer::Renderer>::render
  20:     0x556fa0383380 - cargo[f8998d74d42138ce]::util::toml::emit_diagnostic
  21:     0x556fa03fa4c8 - cargo[f8998d74d42138ce]::util::toml::read_manifest
  22:     0x556fa01bda70 - <cargo[f8998d74d42138ce]::core::workspace::Packages>::load
  23:     0x556fa01ad9d2 - <cargo[f8998d74d42138ce]::core::workspace::Workspace>::find_root
  24:     0x556fa01a396b - <cargo[f8998d74d42138ce]::core::workspace::Workspace>::new
  25:     0x556f9fc2d552 - <clap_builder[332e728b3c5c62a0]::parser::matches::arg_matches::ArgMatches as cargo[f8998d74d42138ce]::util::command_prelude::ArgMatchesExt>::workspace
  26:     0x556f9fc4e397 - cargo[94ff50f027133d42]::commands::check::exec
  27:     0x556f9fc74ce1 - <cargo[94ff50f027133d42]::cli::Exec>::exec
  28:     0x556f9fc6b035 - cargo[94ff50f027133d42]::main
  29:     0x556f9fbe5fc3 - std[2c420855e262d42e]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  30:     0x556f9fbf7229 - std[2c420855e262d42e]::rt::lang_start::<()>::{closure#0}
  31:     0x556fa0dc1526 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hf3af2e81b57eee1a
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/core/src/ops/function.rs:284:13
  32:     0x556fa0dc1526 - std::panicking::try::do_call::hb3a235e132e17a7b
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:552:40
  33:     0x556fa0dc1526 - std::panicking::try::h9a35e2fbb67ddfb8
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:516:19
  34:     0x556fa0dc1526 - std::panic::catch_unwind::h70d81b8297945eb2
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panic.rs:149:14
  35:     0x556fa0dc1526 - std::rt::lang_start_internal::{{closure}}::h27683abc3351933d
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/rt.rs:141:48
  36:     0x556fa0dc1526 - std::panicking::try::do_call::h2c3b862fb38ac0d1
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:552:40
  37:     0x556fa0dc1526 - std::panicking::try::hf08b476bbfbd814f
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panicking.rs:516:19
  38:     0x556fa0dc1526 - std::panic::catch_unwind::hd5ad4d488136ca1a
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/panic.rs:149:14
  39:     0x556fa0dc1526 - std::rt::lang_start_internal::heb1252f709ae92c2
                               at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/library/std/src/rt.rs:141:20
  40:     0x556f9fc7b0b5 - main
  41:     0x7f037831acd0 - <unknown>
  42:     0x7f037831ad8a - __libc_start_main
  43:     0x556f9fbc4029 - <unknown>
  44:                0x0 - <unknown>

Possible Solution(s)

No response

Notes

Version

cargo 1.79.0-nightly (48eca1b16 2024-04-12)
release: 1.79.0-nightly
commit-hash: 48eca1b164695022295ce466b64b44e4e0228b08
commit-date: 2024-04-12
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Manjaro 23.1.4 (Vulcan) [64-bit]
@DaniPopes DaniPopes added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 18, 2024
@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix labels Apr 18, 2024
@Muscraft
Copy link
Member

I tried to debug this, and it appears that the issue is caused by toml_edit returning bad byte spans when a multi-byte character is the first thing in a manifest. It will give the span of (0..1) when it should be (0..4) (in this case).

epage added a commit to epage/toml_edit that referenced this issue Apr 18, 2024
epage added a commit to epage/toml_edit that referenced this issue Apr 18, 2024
epage added a commit to epage/toml_edit that referenced this issue Apr 18, 2024
epage added a commit to epage/cargo that referenced this issue Apr 18, 2024
bors added a commit that referenced this issue Apr 19, 2024
fix(toml): Don't crash on parse errors that point to multi-byte character

This pulls in toml-rs/toml#713

Fixes #13772
@bors bors closed this as completed in 0a5c7d9 Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants