atuinsh / atuin

✨ Magical shell history
https://atuin.sh
MIT License
21.16k stars 565 forks source link

[Bug]: Atuin crashes when path contains non-unicode bytes #2428

Open printfn opened 1 month ago

printfn commented 1 month ago

What did you expect to happen?

Atuin shouldn't crash just because the I'm using non-unicode bytes in filepaths

What happened?

With atuin installed, run:

mkdir $'\xff'
cd $'\xff'

I get the following stacktrace:

thread 'main' panicked at library/std/src/env.rs:171:83:
called `Result::unwrap()` on an `Err` value: "/home/user/chess/\xFF"
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: <std::env::Vars as core::iter::traits::iterator::Iterator>::next
   4: <config::env::Environment as config::source::Source>::collect
   5: config::source::Source::collect_to
   6: <[alloc::boxed::Box<dyn config::source::Source+core::marker::Send+core::marker::Sync>] as config::source::Source>::collect
   7: config::builder::ConfigBuilder<config::builder::DefaultState>::build_internal
   8: config::builder::ConfigBuilder<config::builder::DefaultState>::build
   9: atuin_client::settings::Settings::new
  10: atuin::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Atuin doctor output

{
  "atuin": {
    "version": "18.3.0",
    "sync": {
      "cloud": true,
      "records": true,
      "auto_sync": true,
      "last_sync": "2024-10-21 10:02:53.814094109 +00:00:00"
    },
    "sqlite_version": "3.44.0"
  },
  "shell": {
    "name": "zsh",
    "default": "zsh",
    "plugins": [
      "atuin"
    ],
    "preexec": "built-in"
  },
  "system": {
    "os": "Ubuntu",
    "arch": "x86_64",
    "version": "22.04",
    "disks": [
      {
        "name": "none",
        "filesystem": "9p"
      },
      {
        "name": "/dev/sdc",
        "filesystem": "ext4"
      },
      {
        "name": "/dev/sdc",
        "filesystem": "ext4"
      },
      {
        "name": "none",
        "filesystem": "overlay"
      },
      {
        "name": "none",
        "filesystem": "overlay"
      },
      {
        "name": "none",
        "filesystem": "overlay"
      },
      {
        "name": "C:\\134",
        "filesystem": "9p"
      },
      {
        "name": "N:\\134",
        "filesystem": "9p"
      },
      {
        "name": "/dev/sdc",
        "filesystem": "ext4"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      },
      {
        "name": "/dev/sdc",
        "filesystem": "ext4"
      },
      {
        "name": "snapfuse",
        "filesystem": "fuse.snapfuse"
      }
    ]
  }
}

Code of Conduct

printfn commented 1 month ago

It looks like the bug is caused by this env::vars() line, which crashes atuin if any environment variable (in this case PWD) contains non-unicode characters:

https://github.com/mehcode/config-rs/blob/v0.13.4/src/env.rs#L239