mirror of
https://github.com/uutils/findutils.git
synced 2026-06-10 15:48:30 -07:00
e2d84e98d5
`locate -d <file> <pattern>` panicked (slice index underflow, exit 101) when the database file is exactly one byte: `check_db` consumes that byte with `read_exact`, then `read_until(b'\0', ...)` hits EOF and appends nothing, leaving `buf` empty. `&buf[..buf.len() - 1]` then underflows `buf.len() - 1` to `usize::MAX` and slices out of bounds. Strip the trailing nul with `strip_suffix(b"\0")` (falling back to the whole buffer when `read_until` stopped at EOF without one) instead of slicing `buf.len() - 1`. An empty buffer now yields `None` (unrecognized format), so the too-short database is skipped like any other invalid one and locate exits 1 instead of crashing. Adds a regression test.