rtbo/squiz-box

Failed to extract tar file header with gnu longname

Closed this issue · 0 comments

I want to extract this file https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.4187+1ae839cd2.tar.xz, but ended with error,

/tmp/zig-linux-x86_64-0.11.0-dev.4187+1ae839cd2.tar.xz
Downloading zig tarball ...
Downloading finished ...
object.Exception@/home/john/.dub/packages/squiz-box-a962211f212ad10429d43091dea885c8a2eaa812/squiz-box/src/squiz_box/box/tar.d(724): Unexpected Tar entry type: 'L'
----------------
/home/user/.dub/packages/squiz-box-a962211f212ad10429d43091dea885c8a2eaa812/squiz-box/src/squiz_box/box/tar.d:724 uint squiz_box.box.tar.posixModeFileType(squiz_box.box.tar.Typeflag) [0x572d67]
/home/user/.dub/packages/squiz-box-a962211f212ad10429d43091dea885c8a2eaa812/squiz-box/src/squiz_box/box/tar.d:384 void squiz_box.box.tar.TarUnbox.readHeaderBlock() [0x5718dc]
/home/user/.dub/packages/squiz-box-a962211f212ad10429d43091dea885c8a2eaa812/squiz-box/src/squiz_box/box/tar.d:329 void squiz_box.box.tar.TarUnbox.popFront() [0x57157a]
/usr/include/dlang/dmd/std/algorithm/iteration.d:996 std.typecons.Flag!("each").Flag std.algorithm.iteration.each!(app.main().__lambda3).each!(squiz_box.box.tar.TarUnbox).each(squiz_box.box.tar.TarUnbox) [0x56e6be]
source/app.d:43 _Dmain [0x558104]
Program exited with code 1

Python 3's tarfile library is able to extract the file successfully. It contains a logic related to gnu longname,

    def _proc_gnulong(self, tarfile):
        """Process the blocks that hold a GNU longname
           or longlink member.
        """
        buf = tarfile.fileobj.read(self._block(self.size))

        # Fetch the next header and process it.
        try:
            next = self.fromtarfile(tarfile)
        except HeaderError as e:
            raise SubsequentHeaderError(str(e)) from None

        # Patch the TarInfo object from the next header with
        # the longname information.
        next.offset = self.offset
        if self.type == GNUTYPE_LONGNAME:
            next.name = nts(buf, tarfile.encoding, tarfile.errors)
        elif self.type == GNUTYPE_LONGLINK:
            next.linkname = nts(buf, tarfile.encoding, tarfile.errors)

        # Remove redundant slashes from directories. This is to be consistent
        # with frombuf().
        if next.isdir():
            next.name = next.name.removesuffix("/")

        return next

A similar error also appears in Julia. JuliaIO/Tar.jl#14