Skip to main content
coreydaley.dev

Rejected under Guideline 2.5.1 for linking liblzma, a library macOS ships

App Review rejected Purrchiver 1.0 under Guideline 2.5.1, the rule that apps may only use public APIs. The flagged API wasn’t some private framework I’d gone looking for. It was liblzma, the xz compression library macOS ships in /usr/lib, which the app and its Quick Look extension both linked through libarchive. Purrchiver 1.0 was also rejected under Guideline 2.4.5(i) for how its Shortcuts actions returned files. I fixed both the same day, and this post covers both.

Why a system library counts as non-public

macOS has liblzma.5.dylib, and the SDK has a liblzma.tbd stub to link against, so -llzma (or .linkedLibrary("lzma") in a Swift package) links without complaint. What the SDK doesn’t have is lzma.h. Apple ships the library for its own use and publishes no headers for it.

That’s the distinction App Review cares about. A library without public headers isn’t public API, even if it sits in /usr/lib and the linker finds it. My package vendored the liblzma headers so libarchive’s #include <lzma.h> would resolve, then linked the system dylib. The result was a binary with undefined _lzma_* symbols bound to a private Apple library, which is exactly what the scanner flags.

You can see the same thing in your own build:

# Undefined lzma symbols = imports from somewhere else
nm -u MyApp.app/Contents/MacOS/MyApp | grep _lzma_

# Which dylibs the binary loads
otool -L MyApp.app/Contents/MacOS/MyApp | grep -i lzma

If either command prints anything, your binary imports liblzma from the system. Extensions are separate binaries, so check every .appex in the bundle too. Mine was flagged on both the app and the Quick Look extension.

The fix: compile xz yourself

I vendored the xz 5.8.3 source and compiled liblzma as a static target in the Swift package, then made libarchive’s target depend on it instead of linking the system library:

.target(
    name: "LZMA",                        // xz/liblzma, compiled from source
    cSettings: [
        .define("HAVE_CONFIG_H"),
        .define("TUKLIB_SYMBOL_PREFIX", to: "lzma_"),
        .headerSearchPath("."),
        // ...liblzma's internal include directories
    ]
),
.target(
    name: "LibArchive",
    dependencies: ["LZMA"],
    // .linkedLibrary("lzma") removed
    ...
)

Now the _lzma_* symbols are defined inside the app binary instead of imported from /usr/lib. After the change, the release build showed zero undefined _lzma_* symbols and no liblzma load command on either architecture, in both the app and the extension. xz’s license is permissive (0BSD for liblzma), so vendoring it adds no attribution burden.

A few details mattered:

  • Generate config.h with threads on. liblzma’s config.h comes from running xz’s ./configure, and the options you pass are baked into it. I used --enable-threads=posix --disable-shared --enable-static. Thread support is required here: libarchive’s xz writer calls lzma_stream_encoder_mt, the multithreaded encoder, and that function only exists in a threaded build. Purrchiver’s multithreaded xz depends on it.
  • Match the Makefile’s defines. liblzma’s own build compiles with TUKLIB_SYMBOL_PREFIX=lzma_, which namespaces its internal helper functions. SwiftPM doesn’t know that, so you set it yourself.
  • Watch the universal build. A config.h generated on Apple silicon turns on the ARM CRC32 path unconditionally, which breaks the x86_64 slice. One #if defined(__aarch64__) guard fixes it; the details are in Vendored C in a universal Mac app.

A regression test pins the fix at the source level. It reads Package.swift, ignores comment lines, and fails if .linkedLibrary("lzma") reappears. It also checks that the vendored sources and the arch guard are still there. Putting the system link back is a one-line edit, and the test exists so that edit can’t happen unnoticed.

Guideline 2.4.5(i): Shortcuts output left in the container

The second issue was in Purrchiver’s Shortcuts actions. Six of them produce a file: Extract, two Compress actions, Decompress, Encrypt, and Decrypt. Each one did its work in a fresh folder under the app’s sandbox temporary directory and returned an IntentFile pointing at the result:

// Before: the file stays behind in the app's container
return .result(value: IntentFile(fileURL: outputURL))

That works in Shortcuts. But a sandboxed app’s temporary directory is inside its container, so the output sat somewhere the user can’t easily see or manage. A later run’s cleanup removed folders more than an hour old, but until then the file just sat there. App Review counted that as saving user data to the container.

The fix is to return the bytes and delete the working copy before perform() returns:

defer { try? FileManager.default.removeItem(at: workDir) }
let data = try Data(contentsOf: outputURL)
return .result(value: IntentFile(data: data, filename: outputURL.lastPathComponent))

The user decides where the result goes with a downstream Save File action, which has its own folder picker. For Extract, the action now returns an array of files. Each one is named by its path inside the archive, so the folder structure comes through a Save File step intact. The tradeoff is memory: the output is held in RAM rather than referenced on disk.

While I was at it, I removed a diagnostics row in Settings that showed the path to a preferences file inside the container, with a Reveal in Finder button. Nothing in the app should send people into the container.

Testing “leaves nothing behind”

I didn’t want “check each action in the Shortcuts app” as the only check. The problem is that perform() returns an opaque some IntentResult & ReturnsValue<…>, so a test can’t read the returned IntentFile back.

The test checks the filesystem instead. It snapshots the temp directory, runs each action’s real perform(), and asserts that no new working directory survives. A file-URL return needs its file to still exist, so the only way perform() can succeed and leave nothing behind is by returning the data. The suite is serialized because the temp directory is shared across the process.

What to take away

  • “Ships with macOS” doesn’t mean “public API.” If the SDK has a .tbd but no header, App Review treats the library as private. The SDK has stubs for both libarchive and liblzma and headers for neither. zlib and bzip2, by contrast, ship zlib.h and bzlib.h.
  • Check imports, not just your source. nm -u and otool -L on the built app and every extension show what App Review’s scanner will see.
  • In the Mac sandbox, “temporary” still means “in the container.” Hand results back to the user as data or through a location they picked.

Related posts