Working draft

N51 linkname-bytes-after-nul

Trailing bytes after the NUL terminator in a symlink target.

Reject(draft) A strict parser must reject this archive.

Category
name
Default policy
rejects it
Files
N51-linkname-bytes-after-nul.tar test archive, 1,536 bytes sha256 77a11a796fc73bff8b8defa37b36ce35430651ef2c03264ac5d08339ba1df14e
N51-linkname-bytes-after-nul.jsonexpected result
N51-linkname-bytes-after-nul.txtannotated blocks
N51-linkname-bytes-after-nul.pygenerator script

The case

The archive has a symlink l whose linkname field contains safe, a NUL byte, and ../x.

Under POSIX, the linkname field is NUL-terminated unless it fills all 100 bytes, so the link target is safe. A reader that copies the whole field instead of stopping at the first NUL sees safe\0../x in languages with length-delimited strings, whereas C system calls stop at the NUL. Creating the symlink then fails, or the string that is checked is not the one that is used.

Because normal archivers zero-fill the remainder of the field and trailing bytes after the NUL have no valid purpose, a strict parser rejects the archive.

Decision point: whether a linkname ends at its first NUL.

Seen in: none of the scanned tarballs.

The archive

Every block of 512 bytes, to scale, with its offset. Hover over a field for its bytes.

N51-linkname-bytes-after-nul: every block of the archive0x000000header: symlink, bytes after the NUL in linknamename [0,100): "l" + 99 NULnamemode [100,108): "0000644" + NUL, 644 (octal)uid [108,116): "0000000" + NUL, 0gid [116,124): "0000000" + NUL, 0size [124,136): "00000000000" + NUL, 0mtime [136,148): "00000000000" + NUL, 0chksum [148,156): "010615\0 ", 4493: the unsigned sum of the header, this field as spacestypeflag [156,157): "2", symlinklinkname [157,257): "safe\0../x" + 91 NULlinknamemagic [257,263): "ustar" + NULversion [263,265): "00"uname [265,297): 32 NULunamegname [297,329): 32 NULgnamedevmajor [329,337): "0000000" + NUL, 0devminor [337,345): "0000000" + NUL, 0prefix [345,500): 155 NULprefixpad [500,512): 12 NULname "l" + 99 NULlinkname "safe\0../x" + 91 NUL0x0002002 zero blocks: the end-of-archive markerbytes 0 to 512 of 1024: 512 NUL0x0004002 zero blocks, continuedbytes 512 to 1024 of 1024: 512 NUL0x000600end of fileNULprintable ASCIIspacecontrol character, such as a newlinebyte over 0x7fwritten by the case itself
Every block, as text
N51-linkname-bytes-after-nul: must reject

Trailing bytes after the NUL terminator in a symlink target.

The archive has a symlink `l` whose linkname field contains `safe`, a NUL byte, and `../x`.

Under POSIX, the linkname field is NUL-terminated unless it fills all 100 bytes, so the
link target is `safe`. A reader that copies the whole field instead of stopping at the first NUL
sees `safe\0../x` in languages with length-delimited strings, whereas C system calls stop at the
NUL. Creating the symlink then fails, or the string that is checked is not the one that is used.

Because normal archivers zero-fill the remainder of the field and trailing bytes after the NUL have
no valid purpose, a strict parser rejects the archive.

Decision point: whether a linkname ends at its first NUL.
Seen in: none of the scanned tarballs.
See also: N14, trailing bytes after the NUL in a name.

0x000000  header: symlink, bytes after the NUL in linkname
          name     [  0,100)  "l" + 99 NUL
          mode     [100,108)  "0000644" + NUL  644 (octal)
          uid      [108,116)  "0000000" + NUL  0
          gid      [116,124)  "0000000" + NUL  0
          size     [124,136)  "00000000000" + NUL  0
          mtime    [136,148)  "00000000000" + NUL  0
          chksum   [148,156)  "010615\0 "  4493: the unsigned sum of the header, this field as spaces
          typeflag [156,157)  "2"  symlink
          linkname [157,257)  "safe\0../x" + 91 NUL
          magic    [257,263)  "ustar" + NUL
          version  [263,265)  "00"
          uname    [265,297)  32 NUL
          gname    [297,329)  32 NUL
          devmajor [329,337)  "0000000" + NUL  0
          devminor [337,345)  "0000000" + NUL  0
          prefix   [345,500)  155 NUL
          pad      [500,512)  12 NUL
0x000200  2 zero blocks: the end-of-archive marker
0x000600  end of file
Every byte, as a hex dump

As xxd writes it: xxd -r makes the archive of it.

00000000: 6c00 0000 0000 0000 0000 0000 0000 0000  l...............
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 3030 3030 3634 3400 3030 3030  ....0000644.0000
00000070: 3030 3000 3030 3030 3030 3000 3030 3030  000.0000000.0000
00000080: 3030 3030 3030 3000 3030 3030 3030 3030  0000000.00000000
00000090: 3030 3000 3031 3036 3135 0020 3273 6166  000.010615. 2saf
000000a0: 6500 2e2e 2f78 0000 0000 0000 0000 0000  e.../x..........
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000100: 0075 7374 6172 0030 3000 0000 0000 0000  .ustar.00.......
00000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000140: 0000 0000 0000 0000 0030 3030 3030 3030  .........0000000
00000150: 0030 3030 3030 3030 0000 0000 0000 0000  .0000000........
00000160: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000190: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000200: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000210: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000220: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000230: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000240: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000250: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000260: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000270: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000280: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000290: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000002f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000300: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000310: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000320: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000330: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000340: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000350: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000360: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000370: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000380: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000390: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000003f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000400: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000410: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000420: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000430: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000440: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000450: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000460: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000470: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000480: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000490: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000004f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000500: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000510: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000520: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000530: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000540: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000550: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000560: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000570: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000580: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000590: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000005f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................

What implementations make of it

In the outcome column, ✅ means that the implementation follows the default policy.

implementationversionoutcomewhat it makes of it
GNU tartar (GNU tar) 1.35⚠️ acceptstree A: l → safe
bsdtarbsdtar 3.8.11 - libarchive 3.8.11⚠️ acceptstree A: l → safe
BusyBox tarBusyBox v1.38.0, defconfig⚠️ acceptstree A: l → safe
7-Zip7-Zip (z) 26.05 (x64)⚠️ acceptstree A: l → safe
Python tarfile, filter=data, as in pipCPython 3.15.2⚠️ acceptstree A: l → safe
Python tarfile, filter=tarCPython 3.15.2⚠️ acceptstree A: l → safe
Python tarfile, filter=fully_trustedCPython 3.15.2⚠️ acceptstree A: l → safe
node-tartar 7.5.22⚠️ acceptstree A: l → safe
node-tar, stricttar 7.5.22⚠️ acceptstree A: l → safe
tar-fstar-fs 3.1.3, on tar-stream 3.2.2⚠️ acceptstree A: l → safe
Java Commons CompressCommons Compress 1.28.0, Expander, on Java 27.0.1.0.2⚠️ acceptstree B: l (0 B, e3b0c442)
.NET System.Formats.TarSystem.Formats.Tar of .NET 10.0.14, ExtractToDirectory⚠️ acceptstree A: l → safe
PHP PharData, as in ComposerPharData of PHP 8.5.12, as Composer's TarDownloader calls it⚠️ acceptstree B: l (0 B, e3b0c442)
Go containerd archive.Applycontainerd v2.4.2, archive.Apply, of go1.27.3⚠️ acceptstree A: l → safe
Rust tartar 0.4.46, unpack⚠️ acceptstree A: l → safe
Rust astral-tokio-tarastral-tokio-tar 0.7.1, unpack⚠️ acceptstree A: l → safe
Rust tar-codec, as in uvtar-codec 0.0.16, with the policies of uv 0.13⚠️ acceptstree A: l → safe
RubyGemsRubyGems 4.0.20 of Ruby 4.0.9, extract_tar_gz✅ rejectserror: ArgumentError: path name contains null byte
R untar, internalutils::untar of R 4.6.2, tar = "internal"⚠️ crashesembedded nul in string: 'safe\0../x'
Perl Archive::TarArchive::Tar 3.12 of Perl v5.44.0⚠️ acceptstree A: l → safe
Haskell tartar 0.7.2.0, extract, of GHC 9.14⚠️ acceptstree A: l → safe
Julia Tar.jlTar 1.10.0 of Julia 1.13.3⚠️ acceptstree A: l → safe
untar (PyPI)untar 0.5.0, extract, on CPython 3.15.2✅ rejectserror: Error: Archive contains bytes after the NUL of the link target b'safe\x00../x'
live-bootstrap untarmescc-tools-extra a151c245e512, as live-bootstrap pins it⚠️ acceptstree A: l → safe
live-bootstrap untar, --non-strictmescc-tools-extra a151c245e512, as live-bootstrap pins it⚠️ acceptstree A: l → safe

Prevalence in release tarballs

The table below shows how many release tarballs have the features of this test case.

ecosystemtarballswith itshare
Spack37,5530none
nixpkgs18,9900none
Guix10,1680none
PyPI10,0000none
crates.io5,0000none
RubyGems5,0000none
live-bootstrap1710none
total (distinct)82,5860none

See also