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

index out of bounds panic - Introduced from 0.5.0 release #12

Closed
polarathene opened this issue Oct 6, 2023 · 3 comments
Closed

index out of bounds panic - Introduced from 0.5.0 release #12

polarathene opened this issue Oct 6, 2023 · 3 comments

Comments

@polarathene
Copy link

Hi, I'm trying to get Gura support merged into the config-rs crate, but seem to have run into a bug?
 
The following test case is failing:

#[test]
fn test_gura_vec() {
    let c = Config::builder()
        .add_source(File::from_str(
            r#"
            hosts: [
                "alpha",
                "omega"
            ]
            "#,
            FileFormat::Gura,
        ))
        .build()
        .unwrap();

    let v = c.get_array("hosts").unwrap();
    let mut vi = v.into_iter();
    assert_eq!(vi.next().unwrap().into_string().unwrap(), "alpha");
    assert_eq!(vi.next().unwrap().into_string().unwrap(), "omega");
    assert!(vi.next().is_none());
}

with the following error:

failures:

---- test_gura_vec stdout ----
thread 'test_gura_vec' panicked at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:1241:26:
index out of bounds: the len is 97 but the index is 97
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test_gura_vec

test result: FAILED. 5 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

The bounds len will change based on the text for the hosts config, but is otherwise the same failure.

It references the 0.5.1 crate I used with parser.rs at line 1241, but I'm not sure what to make of that:

"Expected string for key but got \"{}\"",

Backtrace
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
   1: core::panicking::panic_fmt
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_bounds_check
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:162:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/slice/index.rs:261:10
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/slice/index.rs:18:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/vec/mod.rs:2675:9
   6: gura::parser::key
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:1241:26
   7: core::ops::function::Fn::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:79:5
   8: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
   9: gura::parser::matches
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:857:15
  10: gura::parser::pair
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:1491:27
  11: core::ops::function::Fn::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:79:5
  12: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  13: gura::parser::matches
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:857:15
  14: gura::parser::object
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:1444:15
  15: core::ops::function::Fn::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:79:5
  16: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  17: gura::parser::matches
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:857:15
  18: gura::parser::start
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:392:18
  19: gura::parser::parse
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gura-0.5.1/src/parser.rs:968:18
  20: serde_gura::de::from_str
             at /home/polarathene/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_gura-0.1.5/src/de.rs:25:18
  21: config::file::format::gura::parse
             at ./src/file/format/gura.rs:26:38
  22: config::file::format::FileFormat::parse
             at ./src/file/format/mod.rs:131:33
  23: <config::file::format::FileFormat as config::format::Format>::parse
             at ./src/file/format/mod.rs:153:9
  24: <config::file::File<T,F> as config::source::Source>::collect
             at ./src/file/mod.rs:145:9
  25: config::source::Source::collect_to
             at ./src/source.rs:22:9
  26: <[alloc::boxed::Box<dyn config::source::Source+core::marker::Sync+core::marker::Send>] as config::source::Source>::collect
             at ./src/source.rs:116:13
  27: config::source::Source::collect_to
             at ./src/source.rs:22:9
  28: config::builder::ConfigBuilder<config::builder::DefaultState>::build_internal
             at ./src/builder.rs:279:9
  29: config::builder::ConfigBuilder<config::builder::DefaultState>::build
             at ./src/builder.rs:247:9
  30: file_gura::test_gura_vec
             at ./tests/file_gura.rs:76:13
  31: file_gura::test_gura_vec::{{closure}}
             at ./tests/file_gura.rs:75:20
  32: core::ops::function::FnOnce::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5
  33: core::ops::function::FnOnce::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5

This failure appears to be due to a change in gura-rs-parser, but it's unclear what that could be as releases aren't tagged, nor is there any changelog.

  • 0.4.2 is working, and 0.5.0 is where it appears to have broken.
  • I tried adapting the PR to the serde_gura crate and re-using the json5 serde logic we have, same failure while same generic code works for the json5 format.

crates.io does list each version published and the date. I can kinda leverage git blame with Cargo.toml to try track down version 0.5.0, crates.io states it was released Nov 25th 2021. Presumably this commit might be the one that introduced the bug? (or this one that followed after it, which was on the release day Nov 25th)

@Genarito
Copy link
Member

Genarito commented Oct 7, 2023

Hi @polarathene! Thanks for reporting the problem, I'll be working on it and will let you know as soon as I upload the new version

@Genarito
Copy link
Member

Genarito commented Oct 7, 2023

@polarathene I've fixed the bug in the 0.5.3 version.

  • Here is the release.
  • Here is the published Cargo crate.
  • A new test was added to official testing repository.

It should raise an InvalidIndentationError as it's indented in the first level due to r#. The working example should be:

#[test]
fn test_gura_vec() {
    let c = Config::builder()
        .add_source(File::from_str(
            r#"
hosts: [
    "alpha",
    "omega"
]
            "#,
            FileFormat::Gura,
        ))
        .build()
        .unwrap();

    let v = c.get_array("hosts").unwrap();
    let mut vi = v.into_iter();
    assert_eq!(vi.next().unwrap().into_string().unwrap(), "alpha");
    assert_eq!(vi.next().unwrap().into_string().unwrap(), "omega");
    assert!(vi.next().is_none());
}

Thanks!

@polarathene
Copy link
Author

Wow that was really fast! I am not used to a bugfix so quickly, thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants