coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Some input in `date` are panicking the binary

Open ioperations opened this issue 3 years ago • 5 comments

using gnu date command

date --version
    gnu 8.30
date "+%Y-%m-%d %H-%M-%S%:::z"
    2022-08-5 09-53-28+00

while executing coreutils' date command

date --version
    0.0.14
date "+%Y-%m-%d %H-%M-%S%:::z"
$ RUST_BACKTRACE=1 ./target/debug/coreutils date "+%Y-%m-%d %H-%M-%S%:::z"
thread 'main' panicked at 'a Display implementation returned an error unexpectedly: Error', /usr/src/rustc-1.59.0/library/alloc/src/string.rs:2399:14
stack backtrace:
   0: rust_begin_unwind
             at /usr/src/rustc-1.59.0/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /usr/src/rustc-1.59.0/library/core/src/panicking.rs:116:14
   2: core::result::unwrap_failed
             at /usr/src/rustc-1.59.0/library/core/src/result.rs:1690:5
   3: core::result::Result<T,E>::expect
             at /usr/src/rustc-1.59.0/library/core/src/result.rs:975:23
   4: <T as alloc::string::ToString>::to_string
             at /usr/src/rustc-1.59.0/library/alloc/src/string.rs:2398:9
   5: uu_date::uumain::uumain
             at ./src/uu/date/src/date.rs:246:37
   6: uu_date::uumain
             at ./src/uu/date/src/date.rs:145:1
   7: coreutils::main
             at ./src/bin/coreutils.rs:95:31
   8: core::ops::function::FnOnce::call_once
             at /usr/src/rustc-1.59.0/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

ioperations avatar Aug 05 '22 09:08 ioperations

Thanks, it should be easy to fix

sylvestre avatar Aug 05 '22 10:08 sylvestre

Other occurrence found by the fuzzer published in issue #3785

 ./target/debug/coreutils date '+~\x0a~%\x0a'
thread 'main' panicked at 'a Display implementation returned an error unexpectedly: Error', /rustc/34a6cae28e7013ff0e640026a8e46f315426829d/library/alloc/src/string.rs:2490:14
# or
./target/debug/coreutils date '++%:2\\\x0f' 

I guess this is the same issue

sylvestre avatar Aug 14 '22 19:08 sylvestre

It looks like chrono does not support %::z or %:::z format specifiers. I think the right solution is to upstream it there?

resistor avatar Aug 18 '22 05:08 resistor

Looks like this was just added to chrono, actually: https://github.com/chronotope/chrono/commit/5f5410163b6655cd0098530f2c6c44bbcc87d102

resistor avatar Aug 18 '22 05:08 resistor

I have still same problem when running app with this arguments in latest git version of chrono cargo run -- "+␅+%+␄^%)"

qarmin avatar Aug 27 '22 06:08 qarmin

Apparently this behaviour is fixed in main, commit https://github.com/uutils/coreutils/commit/af2833761c7d2b8ba9717503683d2b06f848812a

idwer avatar Nov 18 '22 18:11 idwer

Excellent! I think we can close this after we made a regression test for it.

tertsdiepraam avatar Nov 18 '22 19:11 tertsdiepraam

working on it :)

sylvestre avatar Nov 18 '22 20:11 sylvestre

What about other panics from issue like cargo run '+~\x0a~%\x0a' or cargo run "+␅+%+␄^%)" ? New issue should be created?

qarmin avatar Nov 27 '22 19:11 qarmin

yes please

sylvestre avatar Nov 27 '22 19:11 sylvestre