Introduction
Xar, the eXtensible ARchive format, was started in the OpenDarwin project in the
mid-2000s and taken up by Apple. Its table of contents is an XML document, so new kinds
of information can be added without changing the format, and it can hold checksums and
digital signatures. It is rarely seen under its own name: macOS installer packages
(.pkg files in the flat package format) are xar archives, and so were
older Safari extensions (.safariextz) and Xcode’s .xip downloads. Xcode also keeps
a xar archive in the __LLVM,__bundle section of an object file built with embedded bitcode.
Drop one of these files on the explorer to read it: the header, the table of contents (which opens as XML), every file with all its attributes (access control lists, BSD file flags and ext2 attributes decoded), every stored member opened decoded (zlib, bzip2, LZMA and xz members of any size open in windows), the checksums verified, the RSA and CMS signatures checked with their certificates and time stamp, and any subdocuments. A damaged archive is shown as far as it reads, with every problem listed.
Structure
Numbers in the header are big-endian.
0Magicxar!4 bytes4Header size usually 282 bytes6Version 12 bytes8Table of contents compressed and uncompressed lengths16 bytes24Checksum algorithm none, SHA-1, MD5, SHA-256, SHA-512, or another whose name follows in the header4 bytes28Table of contents XML compressed with zlib, after the header (28 bytes unless a checksum name follows)varies…Heap the table of contents checksum, then each file’s datathe rest
The table of contents lists every file with its name, type, owner, permissions and times, and for each file’s data its offset in the heap, its length, its encoding (such as gzip or bzip2) and checksums of the stored and extracted data. The header and table of contents page gives every field and element, checksums and signature says what each digest and signature covers, and rules the readers apply lists what libxar, libarchive and 7-Zip check.
Not described
Re-checked on 2026-11-19 against libxar’s source, libarchive’s and 7-Zip’s readers, and real packages on one Mac.
Known, not yet covered
- Reference: libxar’s other per-platform attribute modules (
fbsdattr.c,linuxattr.cand the extended-attribute code ofdarwinattr.c) were not read; theeaelements they write are the ones described, but how each platform names and encodes its attributes is not. Viewer: everyeais listed and opens as bytes, with its name and checksums checked. - Reference: the POSIX ACL elements (
acl/access,acl/default), the ext2 attributes and the subdocuments are described from libxar’s and libarchive’s source; no real archive with any of them was available (the macOS ACLs, BSD flags andFinderCreateTimewere checked against archives made by macOS’s ownxar). Viewer: they are decoded the way the sources define them, with every entry listed. - Viewer: the CMS
x-signatureis read and verified (digest, signature, certificates, time stamp), and the RSA signature is verified against the first certificate, but whether a chain leads to a root the system trusts is not decided, nor is revocation or key usage (they need the operating system’s trust settings); RSASSA-PSS signatures and curves other than P-256 and P-384 are listed as not checked. - Viewer: digest names beyond MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 (libxar accepts any OpenSSL digest name) are listed as “not computed”, and the member is not checked against them.
Unknown
- Reference: which version of Apple’s tools began writing
x-signature, and whether any style other thanRSAandCMSexists: no source read says. - Reference: what the xar project’s wiki pages (
xarformat,metadata_stat,metadata_chflags,ArchivedMetadata) say could not be re-checked from a single raw file (the raw wiki addresses answer 404); the pages now rest on libxar’s source and call anything only the wiki says “from the wiki, unverified”. - Reference: macOS’s own
xarbinary was not run on a member name with..or an absolute path; what libxar’sxar_extractdoes with such a name is from reading its source, not from a test. Viewer: such names are listed as they are, with a problem on the member, and nothing is extracted. - Viewer: the 300 MiB bzip2, LZMA and xz members that the windowed decoders read were tested in Node only, not
loaded in a browser; the mixed-codec sample (
samples/xar/out/mixed-codecs.xar, 44 KB) was tested in Node, and its gzip, bzip2 and lzma/xz members were opened in a browser by no one yet.
Links
Software
xarandpkgutil– commands built into macOS that list, expand and make xar archives and packages (macOS)- 7-Zip – free archiver that extracts xar archives (Windows)
- The Unarchiver – free extractor for many formats (macOS)
Developers
- libarchive – reads and writes xar among many formats (C)