coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

printf does not have limits for the maximum value of its arguments

Open jaggededgedjustice opened this issue 4 years ago • 3 comments

The GNU printf command limits the value of arguments it will accept, for example

$ printf '%.*d\n' 10 0
0000000000
$ printf '%.*d\n' 2147483648 0
bash: printf: warning: 0: Numerical result out of range

The version of printf in this repo does not apply this limit so it will produce 2 billion 0s. This is causing the gnu tests to fail when attempting to generate the final log as it has to process a log from a test that is ~2GB in size.

If this isn't considered a bug then the gnu tests should be patched to remove the problematic check.

jaggededgedjustice avatar Mar 22 '21 18:03 jaggededgedjustice

Note that your example is using the Bash built-in printf, which produces different output then GNU printf in this case:

$ printf '%.*d\n' 2147483648 0
-bash: printf: warning: 0: Numerical result out of range

$ /usr/bin/printf '%.*d\n' 2147483648 0
/usr/bin/printf: invalid precision: ‘2147483648’

tdulcet avatar Mar 23 '21 11:03 tdulcet

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 13 '23 12:01 stale[bot]

Hasn't been fixed yet

tertsdiepraam avatar Jan 13 '23 22:01 tertsdiepraam

Hi @tertsdiepraam if possible I want to give this a try. But what is the maximum acceptable range of a valid output?

howjmay avatar Mar 09 '23 06:03 howjmay

@howjmay I've tried some values and the maximum allowed value in GNU seems to be 2^31 - 1 = 2147483647. So basically whatever fits in a i32 I suppose.

tertsdiepraam avatar Mar 09 '23 10:03 tertsdiepraam

Thank you!

howjmay avatar Mar 09 '23 11:03 howjmay

Fixed in https://github.com/uutils/coreutils/pull/6511

cakebaker avatar Jul 01 '24 13:07 cakebaker