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

OOB string indexing panic with incorrect Cargo.toml #13374

Closed
Nemo157 opened this issue Jan 31, 2024 · 1 comment · Fixed by #13375
Closed

OOB string indexing panic with incorrect Cargo.toml #13374

Nemo157 opened this issue Jan 31, 2024 · 1 comment · Fixed by #13375
Assignees
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jan 31, 2024

Problem

When mistyping a Cargo.toml cargo panics when attempting to parse it

Steps

  1. Create a Cargo.toml with
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[[bench.foo]]
  1. cargo check:
thread 'main' panicked at src/cargo/util/toml/mod.rs:124:38:
byte index 18446744073709551615 is out of bounds of `[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[[bench.foo]]
`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/098d4fd74c078b12bfc2e9438a2a04bc18b393bc/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/098d4fd74c078b12bfc2e9438a2a04bc18b393bc/library/core/src/panicking.rs:72:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/098d4fd74c078b12bfc2e9438a2a04bc18b393bc/library/core/src/str/mod.rs:88:9
   4: cargo::util::toml::read_manifest
   5: <cargo::core::workspace::Packages>::load
   6: <cargo::core::workspace::Workspace>::find_root
   7: <cargo::core::workspace::Workspace>::new
   8: <clap_builder::parser::matches::arg_matches::ArgMatches as cargo::util::command_prelude::ArgMatchesExt>::workspace
   9: cargo::commands::check::exec
  10: cargo::cli::main
  11: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.77.0-nightly (84976cd69 2024-01-12)
release: 1.77.0-nightly
commit-hash: 84976cd699f4aea56cb3a90ce3eedeed9e20d5a5
commit-date: 2024-01-12
host: x86_64-unknown-linux-gnu
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: NixOS 23.11.0 [64-bit]
@Nemo157 Nemo157 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jan 31, 2024
@weihanglo
Copy link
Member

Thanks for the report!

Start panicking since #13172 I guess. cc @Muscraft

@rustbot label +S-accepted -S-triage +A-diagnostics

@rustbot rustbot added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Jan 31, 2024
@epage epage self-assigned this Jan 31, 2024
@bors bors closed this as completed in 0f37cfb Jan 31, 2024
weihanglo pushed a commit to weihanglo/cargo that referenced this issue Feb 4, 2024
fix(diagnostic): Don't panic on empty spans

### What does this PR try to resolve?

There is another level to this bug where we better point to where the
error occurs, see toml-rs/toml#669.

Fixes rust-lang#13374

### How should we test and review this PR?

### Additional information
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-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants