coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

head, tail: an invalid count with a leading zero is reported without the leading zeros

Open kennywillbe opened this issue 3 months ago • 0 comments

head and tail strip leading zeros from the count argument before parsing it, and the resulting error names the stripped string rather than the argument as typed.

$ tail -c0fb a
tail: invalid number of bytes: 'fb'
$ tail -c007z a
tail: invalid number of bytes: '7z'

GNU names the argument as given:

$ tail -c0fb a
tail: invalid number of bytes: '0fb'
$ tail -c007z a
tail: invalid number of bytes: '007z'

head behaves the same way. The stripping happens in parse_signed_num_max (src/uucore/src/lib/features/parser/parse_signed_num.rs), where trimmed is passed to the size parser and so ends up in the error, while the caller formats whatever string the error carries.

Noticed while working on #13136; it is independent of that issue, which is about which suffixes are accepted.

kennywillbe avatar Aug 29 '26 11:08 kennywillbe