Skip to content

locate: a large --max-database-age aborts via TimeDelta::days overflow #766

Closed

Description

@leeewee

locate compares the database age against --max-database-age (default 8) with TimeDelta::days(config.max_age as i64) (src/locate/mod.rs:622). chrono's TimeDelta::days panics when the resulting duration overflows its internal range, so a large numeric argument (which clap accepts as a usize) aborts the process inside chrono instead of being rejected or clamped.

$ printf '\0LOCATE02\0\0/foo\0' > /tmp/db.bin
$ locate -d /tmp/db.bin --max-database-age 1000000000000 foo
thread 'main' panicked at .../chrono-0.4.45/src/lib.rs:717:17:
overflow in TimeDelta::days
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101

Root cause

src/locate/mod.rs (the age-check inside the DB reader loop):

let delta = now - modified;
if delta
    > TimeDelta::days(config.max_age as i64)   // <-- mod.rs:622: panics on overflow
{
    eprintln!("{}: warning: database ‘{}’ is more than {} days old ...", ...);
}

config.max_age: usize comes straight from --max-database-age. chrono's TimeDelta::days(d) panics when d days can't be represented.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions