rust-cli / rust-cli/config-rs

crash due to absurd memory allocation

Open
#232 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

Some config file generate an extreme memory allocation when read, that leads to a crash.

Example program that generates the error:

use config::{Config, File, FileFormat};

fn main() {
    let s = vec![0x70, 0x4d, 0x5b, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
                 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x5d, 0x3a, 0x00, 0x00,
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x33, 0x03, 0x00,
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];

    let _ = Config::new().merge(File::from_str(std::str::from_utf8(&s).unwrap(), FileFormat::Ini));
}

Output:

$ RUST_BACKTRACE=1 ./target/debug/config-reproduce 
memory allocation of 1777777777777777840 bytes failed
Aborted (core dumped)

Stacktrace:

(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
#1  0x00007ffff7dc8864 in __GI_abort () at abort.c:79
#2  0x0000555555747e67 in std::sys::unix::abort_internal () at library/std/src/sys/unix/mod.rs:255
#3  0x0000555555581476 in std::process::abort () at library/std/src/process.rs:1957
#4  0x000055555574440e in std::alloc::rust_oom () at library/std/src/alloc.rs:330
#5  0x000055555575bb67 in alloc::alloc::__alloc_error_handler::__rg_oom () at library/alloc/src/alloc.rs:398
#6  0x0000555555582237 in alloc::alloc::handle_alloc_error () at library/alloc/src/alloc.rs:367
#7  0x00005555555fafdc in alloc::raw_vec::handle_reserve (result=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/raw_vec.rs:531
#8  0x00005555555fbb11 in alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle (slf=0x5555557f2bb0, len=0, additional=22222222222222223) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/raw_vec.rs:333
#9  0x00005555555fbacb in alloc::raw_vec::RawVec<T,A>::reserve (self=0x5555557f2bb0, len=0, additional=22222222222222223) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/raw_vec.rs:337
#10 0x0000555555602cd1 in alloc::vec::Vec<T,A>::reserve (self=0x5555557f2bb0, additional=22222222222222223) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/vec/mod.rs:803
#11 0x0000555555602492 in alloc::vec::Vec<T,A>::extend_with (self=0x5555557f2bb0, n=22222222222222223, value=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/vec/mod.rs:2226
#12 0x0000555555602c66 in alloc::vec::Vec<T,A>::resize (self=0x5555557f2bb0, new_len=22222222222222223, value=...) at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/alloc/src/vec/mod.rs:2122
#13 0x00005555555ee99d in config::path::Expression::set (self=0x7fffffffca10, root=0x7fffffffcbb8, value=...) at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/path/mod.rs:245
#14 0x00005555555848f6 in config::source::Source::collect_to (self=0x5555557f1e10, cache=0x7fffffffcbb8) at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/source.rs:27
#15 0x0000555555603af0 in <alloc::vec::Vec<alloc::boxed::Box<dyn config::source::Source+core::marker::Send+core::marker::Sync>> as config::source::Source>::collect (self=0x7fffffffdae0)
    at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/source.rs:53
#16 0x000055555560357c in config::source::Source::collect_to (self=0x7fffffffdae0, cache=0x7fffffffd380) at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/source.rs:17
#17 0x00005555555f9e20 in config::config::Config::refresh (self=0x7fffffffda80) at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/config.rs:124
#18 0x0000555555583f16 in config::config::Config::merge (self=0x7fffffffda80, source=...) at /home/capitol/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.11.0/src/config.rs:78
#19 0x0000555555583a53 in config_reproduce::main () at src/main.rs:12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced INI input and the allocation path in src/path/mod.rs, especially Expression::set, then trace how it is reached through source.rs. Add a regression test for this input and verify that parsing no longer aborts with an absurd allocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.