Skip to content

Security: TAR pre-scan misses GNU long-name and long-link metadata #854

Description

@rustytrees

Bug description

preScanTarGz validates PAX path and linkpath overrides, but it does not
apply GNU L (long name) and K (long link) records to the following entry.
Zig 0.16's TAR iterator does apply those records. Malt can therefore validate
the placeholder ustar name or link target while std.tar.pipeToFileSystem
extracts a different effective value.

This is not a claim that std.tar fails to sanitize entry names. Zig calls
sanitizePath on the effective entry name. The mismatch is in Malt's pre-scan.
sanitizePath does not validate symlink targets, and Malt cannot track a
symlink whose GNU long name it never applied.

A malicious bottle can use GNU K to create a symlink with an escaping target
after Malt approved a benign placeholder. It can also use GNU L to hide a
symlink's effective name and then write a later file through that symlink
outside the extraction directory.

Affected code:

Regression tests:

  • extractTarGz rejects an escaping GNU long-link target
  • extractTarGz rejects a write through a GNU long-named symlink
  • extractTarGz accepts safe GNU long-name and long-link metadata

Homebrew catalog reference

No official trigger was found in the bounded archive sample. The scan checked
13,457 entries from the fontconfig, libpng, node, openssl@3,
proctools, sqlite, unzip, xz, zstd, minimal-racket, nagios, and
unbound bottles. None used a GNU L or K record. The formula API does not
expose bottle entry types, so this does not rule out other or historical
bottles.

Expected behavior

The pre-scan must consume GNU L and K records with the same one-entry
lifetime and size/NUL rules as Zig's iterator. It must validate the same name
and link target that extraction will use. Malt's existing Rust-bottle-compatible
one-level symlink policy must remain intact.

Fix: #838

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions