#1092340 coreutils: numfmt: removes data between first NUL and new-line

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
наб
Date:
2025-01-08 00:45:02 UTC
Severity:
normal
#1092340#5
Date:
2025-01-07 13:48:03 UTC
From:
To:
Dear Maintainer,

$ printf '2024\0TODOs\n' | numfmt -d '' --to iec-i
2.0Ki

So, '\0TODOs' was removed from the input line.

Best,

#1092340#10
Date:
2025-01-08 00:42:41 UTC
From:
To:
Hi наб,

As far as I know, this tool works with text input, as most Unix tools.
What you introduced is not a text file, per POSIX.1-2024, Volume 1,
Chapter 3, definition 3.387:

	3.387 Text File

	A file that contains characters organized into zero or more
	lines.  The lines do not contain NUL characters and none can
	exceed {LINE_MAX} bytes in length, including the <newline>
	character.  Although POSIX.1-2024 does not distinguish between
	text files and binary files (see the ISO C standard), many
	utilities only produce predictable or meaningful output when
	operating on text files. The standard utilities that have such
	restrictions always specify "text files" in their STDIN or INPUT
	FILES sections.

You could say it's a binary file, although POSIX claims to not
differentiate between text files and binary files (but they do), but
let's agree that a binary file is what POSIX doesn't consider a text
file.  What you're experiencing is "[non] predictable [nor] meaningful
output", in standardese, a.k.a., undefined behavior, I'd say.


Have a lovely New Year!
Alex