coreutils
coreutils copied to clipboard
head, tail: an invalid count with a leading zero is reported without the leading zeros
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.