coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

head: errors on very large argument to -c but shouldn't

Open jfinkels opened this issue 11 months ago • 3 comments

Environment: Ubuntu 20.04, uutils main branch (git commit d39dcad47ca4d9fa96e8f8132b4d1c298f1f7753), GNU coreutils v9.6.3-3189c-dirty.

Steps to reproduce:

head --bytes=-18446744073709551616000 < /dev/null

What happens now: uutils head complains that the number is too large:

head: invalid number of bytes: '18446744073709551616000': Value too large for defined data type

What I expected to happen: GNU head terminates successfully with no output.

Notes: this is causing a failure in the GNU test file tests/head/head-c.sh.

jfinkels avatar Jan 19 '25 16:01 jfinkels

Can we know what the behavior is in case the number of bytes overflows unsigned long long without actually testing it (it would be kind of costly I guess) ? Like is it said somewhere esle than the actual int type in the GNU code ?

If not, maybe we can cap the value to u64::MAX, and assume this will be enough until someone proves us otherwise.

RenjiSann avatar Jan 24 '25 22:01 RenjiSann

Capping the value to u64::MAX is probably good enough to pass the test, I don't know what the GNU head behavior actually is.

jfinkels avatar Feb 14 '25 00:02 jfinkels

coreutils state that in case of overflow it would silently cap to MAX value but on any system I try the given command

head --bytes=-18446744073709551616000 < /dev/null

I get the error message head: invalid number of bytes: '18446744073709551616000': Value too large for defined data type

so not sure if this is not a bad behavior from coreutils

codeOverFlow avatar Mar 16 '25 19:03 codeOverFlow