Bug 15276 - cut: transforms 0x00 to 0x0a
Summary: cut: transforms 0x00 to 0x0a
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.35.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-22 20:50 UTC by ValdikSS
Modified: 2023-07-20 14:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.