144 points thatslast 9 hours ago 31 comments
bartvk 9 hours ago | parent
At the bottom, there's a link to much more edge cases.
It reminds me of this beauty: "Parsing JSON is a Minefield" https://news.ycombinator.com/item?id=16897061
weryberl5 7 hours ago | parent
rmast 8 hours ago | parent
But the ambiguity of this tar files… I guess the “correct” extraction for what I’m doing would require figuring out what the system that is processing the tar files used and copy that behavior, which is non-trivial if you don’t know what an embedded device is using behind the scenes.
stabbles 8 hours ago | parent
For your use case it would make sense to pick the strictest tar parser, such that you can error or warn on most ambiguities. In practice these ambiguities are rare.
rmast 6 hours ago | parent
woodruffw 6 hours ago | parent
(Another way of saying that is that we live in a post-Postel world[1].)
[1]: https://alexgaynor.net/2025/mar/25/postels-law-and-the-three...
rmast 4 hours ago | parent
dataflow 8 hours ago | parent
I feel like the most faithful extraction would dictate that any field in the original header should take precedence over the PaxHeader's iff the PaxHeader field's value would've been representable in the original field. Anyone have thoughts?
woodruffw 5 hours ago | parent
pax does not prescribe what to do in these kinds of invalid states, so there’s a long tail of people making educated guesses.
dataflow 3 hours ago | parent
woodruffw 3 hours ago | parent
(On a more basic level, I can imagine it would be even more differential prone for the precedence rule to be “pax, but not always.” pax still makes it complicated but that would be another whole circle of hell.)
molticrystal 8 hours ago | parent
While this is the safest choice, it is the least helpful, I would always prefer to get something out of an archive then nothing. Damage/irregularity to an archive shouldn't prevent data inspection, just a warning and a way to fall back with caveats for what can be extracted.
pixl97 7 hours ago | parent
Now if I'm a user trying to extract the file then I'd want to get as much as possible.
rwmj 7 hours ago | parent
stabbles 7 hours ago | parent
The POSIX standard promotes best-effort extraction, which is reasonable for backups, but a liability for distribution.
Julia's Tar.jl was developed for Pkg.jl and tar-codec for uv, so these are focused on the security aspect of software distribution.
yjftsjthsd-h 5 hours ago | parent
stabbles 2 hours ago | parent
wolrah 4 hours ago | parent
I would argue the correct answer can have both.
Fail by default, fail with a clear error that says the file is damaged, then offer an explicitly opt-in path to try your best anyways, preferably one where the command line option is something like --dangerous-try-extract-anyways and will itself fail on non-broken files so it can't just be shoved in a script as a way to "make sure it works".
Joker_vD 7 hours ago | parent
How so? If the data blocks are included, then those are the intended content of the file behind that hard link. They should overwrite the previous content of the file.
> So the 512 bytes after the hard link are its data, and not the header of empty as we archived it?
Yes, precisely.
> How can a hard link have different contents from its previous counterpart file?
Why, very simply: while the archive was being created, the file behind the two different hard links changed; the archival utility noticed it, and included the new content of the file as the content for the second hard link instead of rewinding and overwriting the original file in the archive (which would be impossible to do on a tape, you know). At least I believe that's what was the rationale for this allowance, and the intended behavior on the extraction.
woodruffw 6 hours ago | parent
(I maintain several of the tar parsers mentioned in this post, which I appreciate for its clear treatment of a larger differential problem in the tar ecosystem.)
Joker_vD 6 hours ago | parent
stabbles 5 hours ago | parent
djha-skin 6 hours ago | parent
Hit up Wikipedia for tarball format and you may agree with me. It's a classic example of a standard where you look at it and go, "??? Who asked for that?". I'm not surprised the article focuses on pax when finding tar inconsistencies. Original tar is just fine.
woodruffw 6 hours ago | parent
(Users also want things like filenames that are longer than 100 characters, for obvious reasons.)
wpollock 5 hours ago | parent
woodruffw 4 hours ago | parent
JdeBP 5 hours ago | parent
* https://mbsd.evolvis.org/pax.htm
* https://manpages.debian.org/trixie/pax/index.html
No, it's not libarchive's bsdtar. There's more than 1 tar in the BSD world.
zahlman 4 hours ago | parent
Surely "tarpit" is a more natural name?
woodruffw 4 hours ago | parent