Bug 15276

Summary: cut: transforms 0x00 to 0x0a
Product: Busybox Reporter: ValdikSS <iam>
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.35.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description ValdikSS 2023-01-22 20:50:47 UTC
Cut utility incorrectly replaces null-byte (0x00) with \n (0x0a).

Tested with Busybox 1.36.0 and Busybox 1.20.0 ("Busybox in VM" link on the website).

Busybox:
$ echo -ne "\x00\x01\x02\x03\x04\x05\x06" | ./busybox cut -b 1-3 | hexdump -C
00000000  0a 01 02 03 0a                                    |.....|
00000005

GNU coreutils:
$ echo -ne "\x00\x01\x02\x03\x04\x05\x06" | cut -b 1-3 | hexdump -C
00000000  00 01 02 0a                                       |....|
00000004
Comment 1 Eric Blake 2023-07-20 14:57:54 UTC
For what it's worth, POSIX says	that cut is only required to operate on text files; a file with an embedded NUL byte is not a text file, so all bets are off on what behavior to expect:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html, INPUT FILES

That said, gratuitous differences from other implementations are still worth patching.