The Hardest Tarball? stoppels.ch · 92 points · 5 comments · HN thread TL;DR The ...

@best

The Hardest Tarball? stoppels.ch · 92 points · 5 comments · HN thread

TL;DR The author builds a single tar archive with GNU tar that exploits pax headers and hard links, so that eight common tar implementations extract it in different ways, from keeping all files to rejecting the archive outright. The post is part of a 134-case test suite, tar-minefield, that compares how parsers handle such edge cases.

  • The archive is made with one GNU tar command: a hard link is renamed to a UTF-8 name (café), which forces a pax header, and a size=512 record is added to the hard link.
  • 512 bytes equals the size of a tar header, so implementations disagree on whether those bytes are data of the hard link, a header of the next entry, or an end-of-archive marker.
  • GNU tar, BusyBox, Python, Go and Perl ignore the size on the hard link and extract file, café and empty.
  • bsdtar writes the 512 bytes into the hard link, so file ends up containing a tar header; 7-Zip, node-tar, tar-fs and Rust's tar libraries skip the data and omit empty.
  • Java Commons Compress, PHP PharData, RubyGems, R and Haskell each produce a different result, from an extra file to a PaxHeaders directory to garbled names; .NET, Julia and uv's tar-codec reject the archive.
  • The author's tar-minefield suite now has 134 tricky tarballs and a results table at stoppels.ch/tar.

Discussion The thread is short and mostly reflective. Commenters find the archive and the test suite interesting, and they discuss what a tool should do with an ambiguous archive. One commenter who builds SBOM tooling explains why such ambiguity matters for automated extraction of unknown archives, and another points to the strictest parser in the test suite. The mood is appreciative and curious, with a practical debate about whether to fail fast or recover data.

  • Strict rejection is safest, but partial extraction is preferable (some): Commenters argue that rejecting an archive protects users but gives them nothing. They prefer warnings and best-effort extraction with clear caveats.
  • Strict parsers are the right choice for ambiguous archives (some): Commenters note that the strictest parser, uv's tar-codec, is best suited to catching ambiguities, and that such cases are rare in practice.
  • Explicit extraction rules should follow the original header fields (a few): One commenter proposes that a field in the original header should override the pax header whenever the pax value could have fit in the original field.
  • Real-world tools must mimic the target system's behavior (a few): A commenter building an SBOM tool says correct extraction depends on which tar implementation the processing system uses, which is hard to know for embedded devices.
  • Praise for the post and the test suite (a few): Commenters praise the author's graphics and the test suite, and link to a classic essay on JSON parsing pitfalls.

Links from the comments

#tar #archiveFormats #parsing #edgeCases #testing #security