Skip to content

Commit

Permalink
Add workaround for macOS TAR archive xattrs
Browse files Browse the repository at this point in the history
This commit introduces a workaround for an issue with TAR archives
created with libarchive on Darwin/macOS. When encountering a file that
has extended attributes, such as the com.apple.provenance attribute, it
will add a corresponding AppleDouble file with the prefix "._" in the
same directory. Because these files have the same filename otherwise,
the buf tool will see these when they correspond to proto files and
subsequently fail to parse them as protobuf IDL.

Due to the fact that libarchive is used by default with the version of
tar that ships with macOS, and the provenance extended attribute is set
by macOS under many conditions when SIP is enabled, archives with these
files are likely to occur on macOS.

This workaround is not needed by .zip as libarchive .zip files do not
seem to have the same behavior.

Closes #2387.
  • Loading branch information
jchadwick-buf committed Oct 17, 2023
1 parent c1b5844 commit 03c232b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions private/pkg/storage/storagearchive/storagearchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"math"
"strings"

"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/storage"
Expand Down Expand Up @@ -109,6 +110,19 @@ func Untar(
if tarHeader.Size < 0 {
return fmt.Errorf("invalid size for tar file %s: %d", tarHeader.Name, tarHeader.Size)
}
if strings.HasPrefix(tarHeader.FileInfo().Name(), "._") {
// When creating tar archives using libarchive on macOS, extended
// attributes on files will be stored as an AppleDouble file with
// a prefix of "._". These entries must be omitted in processing.
// This concession is accepted under the following reasoning:
// 1. Filename is the only distinctive property of these entries.
// 2. Protobuf IDL files prefixed with ._ are extremely uncommon.
// 3. Multiple passes through the archive header are undesirable.
// If this proves to be too obtrusive, we can use multiple passes
// and possibly use PAXHeaders to precisely exclude only relevant
// attribute files without omitting all files prefixed with "._".
continue
}
path, ok, err := unmapArchivePath(tarHeader.Name, mapper, stripComponentCount)
if err != nil {
return err
Expand Down

0 comments on commit 03c232b

Please sign in to comment.