The hardest tarball

The hardest tarball

The hardest tarball? Nov 7th, 2026 Here is a curiosity: an archive that can be constructed using a single GNU tar invocation, that is extracted in 8 distinct ways depending on what tool you use. $ printf hello > file $ touch empty $ tar —format=pax —pax-option=‘delete=?time,size:=512’ \ —transform=’s,^./file$,café,’ \ -cf hardest.tar file ./file empty

最难的 tarball?2026 年 11 月 7 日。这里有一个奇闻:一个可以通过单次 GNU tar 调用构建的归档文件,根据所用工具的不同,它有 8 种不同的解压方式。$ printf hello > file $ touch empty $ tar —format=pax —pax-option=‘delete=?time,size:=512’ \ —transform=’s,^./file$,café,’ \ -cf hardest.tar file ./file empty

It creates an archive hardest.tar from three files file ./file empty in sequence, where file is repeated so that GNU tar stores the second one as a hard link, and empty is empty. Exploiting the unique path of the second entry, the hard link is renamed to café. This triggers tar to create a pax header to store the file name as UTF-8. We add a size=512 record to the pax header, which overrides the default size=0 from the hard link. The value 512 is not a coincidence: it is exactly the size of a tar header.

它按顺序从三个文件 file、./file 和 empty 创建了一个名为 hardest.tar 的归档文件,其中 file 被重复使用,以便 GNU tar 将第二个文件存储为硬链接,而 empty 则为空文件。利用第二个条目的唯一路径,该硬链接被重命名为 café。这会触发 tar 创建一个 pax 头信息,以 UTF-8 格式存储文件名。我们在 pax 头信息中添加了一个 size=512 的记录,它覆盖了硬链接默认的 size=0。数值 512 并非巧合:它正好是一个 tar 头信息的大小。

Visually, this archive has the following structure, with two basic interpretations based on whether a hard link can have a size or not. Now, POSIX says that data blocks for a hard link “may be included” in pax archives, but the implications of this are not entirely clear. So the 512 bytes after the hard link are its data, and not the header of empty as we archived it? How can a hard link have different contents from its previous counterpart file?

从视觉上看,该归档文件具有以下结构,根据硬链接是否可以拥有大小,有两种基本的解读方式。POSIX 规定硬链接的数据块“可以包含”在 pax 归档中,但其含义并不完全明确。那么,硬链接之后的 512 字节是它的数据,而不是我们归档时 empty 的头信息吗?硬链接怎么可能拥有与其前身 file 不同的内容呢?

Extracting it This archive gives by far the richest and most surprising results I’ve encountered so far when extracting it with well-known tar utilities and libraries. The results below were produced using the latest releases of all packages at the time of writing.

解压它:在用知名的 tar 工具和库解压此归档文件时,它产生了我迄今为止遇到的最丰富、最令人惊讶的结果。以下结果是在撰写本文时使用所有软件包的最新版本产生的。

GNU tar, BusyBox, Python, Go and Perl This group is reasonable in principle: they ignore the size on the hard link, and extract file, its hard link café, and empty.

GNU tar、BusyBox、Python、Go 和 Perl:这一组在原则上是合理的:它们忽略了硬链接上的大小,并解压出 file、它的硬链接 café 以及 empty。

bsdtar This is the system tar utility of macOS, which is closer to POSIX in spirit regarding the concept of size on hard links, and writes the 512 bytes into the hard link. The end result is that file now contains the tar header of empty.

bsdtar:这是 macOS 的系统 tar 工具,在硬链接大小的概念上更符合 POSIX 的精神,它将这 512 字节写入了硬链接中。最终结果是 file 现在包含了 empty 的 tar 头信息。

7-Zip, node-tar, tar-fs, and Rust’s tar & astral-tokio-tar This group agrees with bsdtar that the 512 bytes are data of the hard link, but doesn’t write them into the hard link. Instead, they skip forward over the data, and you are left with just file and café, without empty.

7-Zip、node-tar、tar-fs 以及 Rust 的 tar 和 astral-tokio-tar:这一组同意 bsdtar 的观点,即这 512 字节是硬链接的数据,但它们没有将其写入硬链接。相反,它们跳过了这些数据,最终你只得到了 file 和 café,而没有 empty。

Java’s Commons Compress This is where you begin to need more imagination. Because café contains data, a separate file is created that contains the header of empty as data, while file keeps its original contents.

Java 的 Commons Compress:这里你开始需要更多的想象力了。因为 café 包含数据,所以创建了一个单独的文件,其中包含 empty 的头信息作为数据,而 file 则保持其原始内容。

PHP’s PharData Makes café a separate, empty file, and also extracts empty. Why not?

PHP 的 PharData:将 café 变成一个单独的空文件,同时也解压出 empty。为什么不呢?

RubyGems Does not extract café at all, but to make up for it, it creates an empty directory PaxHeaders next to file and empty.

RubyGems:根本不解压 café,但为了弥补这一点,它在 file 和 empty 旁边创建了一个名为 PaxHeaders 的空目录。

R R has an entirely different approach: it extracts empty with 512 null bytes. It mistakenly applies the size to empty instead of the hard link, and those 512 bytes are from an end-of-archive marker.

R:R 有一种完全不同的方法:它解压出的 empty 带有 512 个空字节。它错误地将大小应用到了 empty 而不是硬链接上,而那 512 字节来自归档结束标记。

Bonus: Haskell Haskell’s tar would be exactly like GNU tar, if only it did not have string decoding issues, which turn the file café into café on disk (in the year 2026, this is not a rendering quirk of your browser).

额外说明:Haskell:如果 Haskell 的 tar 没有字符串解码问题,它本应与 GNU tar 完全一样。这些问题导致磁盘上的文件 café 变成了 café(在 2026 年,这可不是你浏览器的渲染怪癖)。

.NET, Julia and uv’s tar-codec These implementations reject the tarball. I believe this is the best thing you can do, even if it’s technically not POSIX-compliant.

.NET、Julia 和 uv 的 tar-codec:这些实现拒绝了该 tarball。我认为这是你能做的最好的事情,即使从技术上讲它不符合 POSIX 标准。

More of this This tarball is one of 134 tricky tarballs that I’m collecting and categorizing in my test suite haampie/tar-minefield, developed since the last post. Its website https://stoppels.ch/tar features a big table that shows how implementations deal with all these cases, as well as detailed info per test case. A variant from the tarball of this post is included as a test case. If you’d like to discuss this, send me an email at firstname[at]lastname.ch.

更多此类内容:这个 tarball 是我正在收集并分类到我的测试套件 haampie/tar-minefield 中的 134 个棘手 tarball 之一,该套件自上一篇文章以来一直在开发。其网站 https://stoppels.ch/tar 提供了一个大表格,展示了各种实现如何处理所有这些情况,以及每个测试用例的详细信息。本文 tarball 的一个变体已被包含作为测试用例。如果你想讨论这个问题,请发送电子邮件至 firstname[at]lastname.ch。