jqnatividad / qsv

Blazing-fast Data-Wrangling toolkit
https://qsv.dathere.com
The Unlicense
2.48k stars 70 forks source link

`sniff`: panic on zero length file #803

Closed kika closed 1 year ago

kika commented 1 year ago

Describe the bug

qsv sniff panics when run on a zero length file

To Reproduce Steps to reproduce the behavior:

  1. touch empty.csv
  2. qsv sniff empty.csv
  3. PROFIT!11

Expected behavior Either a message to stderr that the file is empty or just silently ignore (nothing to sniff - nothing to do?)

Screenshots/Backtrace/Sample Data

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551615', /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/github.com-1ecc6299db9ec823/qsv-sniffer-0.6.0/src/sniffer.rs:313:50
stack backtrace:
   0:        0x10254b068 - __mh_execute_header
   1:        0x10224f268 - __mh_execute_header
   2:        0x1025337b4 - __mh_execute_header
   3:        0x10254ae90 - __mh_execute_header
   4:        0x102544f30 - __mh_execute_header
   5:        0x102544c30 - __mh_execute_header
   6:        0x1025459a8 - __mh_execute_header
   7:        0x10254b740 - __mh_execute_header
   8:        0x10254b6b0 - __mh_execute_header
   9:        0x1025455b0 - __mh_execute_header
  10:        0x1025d62e4 - __mh_execute_header
  11:        0x1025d63e0 - __mh_execute_header
  12:        0x1023d340c - __mh_execute_header
  13:        0x1020d2a68 - __mh_execute_header
  14:        0x1021d47bc - __mh_execute_header
  15:        0x102205494 - __mh_execute_header
  16:        0x1020eaab4 - __mh_execute_header
  17:        0x102207790 - __mh_execute_header

Desktop (please complete the following information):

kika commented 1 year ago

I also observe the same panic if I just qsv sniff < nonempty.csv while qsv sniff nonempty.csv works just fine.

jqnatividad commented 1 year ago

Thanks for the report @kika .

sniff actually doesn't work with stdin, so adjusted it accordingly.

And as suggested, it also now handles empty files.