https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291567

            Bug ID: 291567
           Summary: bsdtar produces corrupted gzip/zstd streams when
                    writing compressed archives to stdout, while the same
                    commands using -f file create valid archives.
           Product: Base System
           Version: 15.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: [email protected]
          Reporter: [email protected]

Summary

bsdtar produces corrupted gzip/zstd streams when writing compressed archives to
stdout, while the same invocations with -f file produce valid archives. This
affects both -z (gzip) and --zstd filters and is reproducible on multiple
FreeBSD releases and architectures.
Environment

    FreeBSD 15.0-RELEASE GENERIC amd64

    FreeBSD 14.3-RELEASE-p5 GENERIC amd64

    FreeBSD 14.3-RELEASE-p5 GENERIC arm64

Common for all systems:

    tar, gzip and zstd are from base system.

Steps to reproduce

All commands run in an empty temporary directory, with a synthetic data set:

    Generate some test data:

mkdir -p /tmp/bsdtar-test/data
dd if=/dev/urandom of=/tmp/bsdtar-test/data/file.bin bs=1k count=64 status=none
cd /tmp/bsdtar-test

    Gzip via stdout (broken):

tar -cz data > stdout-gzip.tgz
gzip -t stdout-gzip.tgz
# gzip reports: "trailing garbage ignored"

    Gzip via -f (OK):

tar -cz -f file-gzip.tgz data
gzip -t file-gzip.tgz
# exit status 0, no warnings

    Zstd via builtin --zstd + stdout (broken):

tar --zstd -c data > stdout-zstd.tzst
zstd -t stdout-zstd.tzst
# zstd: "unsupported format"

tar -tf stdout-zstd.tzst
# lists some entries, then:
# tar: Truncated input file (...), Error exit delayed from previous errors.

    Zstd via builtin --zstd + -f (OK):

tar --zstd -cf file-zstd.tzst data
zstd -t file-zstd.tzst   # OK
tar -tf file-zstd.tzst   # full listing OK

    Zstd via external filter (reference, OK):

tar -c data | zstd -o pipe-zstd.tzst
zstd -t pipe-zstd.tzst   # OK

In all cases the stdout‑generated files (stdout-gzip.tgz, stdout-zstd.tzst) are
close in size to their -f counterparts, but are rejected by the native
compressor tools, while the -f and pipe variants are valid.
Actual vs expected behavior

    Actual:

        tar -cz data > file.tgz: gzip -t reports trailing garbage ignored on
the resulting file.

        tar --zstd -c data > file.tzst: zstd -t reports unsupported format; tar
-tf sees some entries and then fails with a truncated archive error.

        Using an external compressor (tar -c | gzip, tar -c | zstd) or -f with
the builtin filters always produces valid archives.

    Expected:

        Writing a compressed archive to stdout (tar -cz data > file, tar --zstd
-c data > file) should produce the same valid gzip/zstd stream as tar -cz -f
file / tar --zstd -cf file.

Additional notes

    The issue only appears when bsdtar both performs compression and writes the
archive to a non‑seekable destination (stdout/pipe with shell redirection).

    The fact that:

        -f file with builtin gzip/zstd is always OK, and

        tar -c | gzip / tar -c | zstd is always OK,
        strongly suggests a bug in the libarchive/bsdtar write/flush path for
compressed output to non‑seekable file descriptors (finalization or padding
after EOF, or similar), rather than in the external compressor tools.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to