Contain tarzstd and fastzip extraction within the root

What does this MR do?

Routes every write made by the tarzstd and fastzip extractors through os.Root, so extraction stays inside the target directory.

  • tarzstd: creates directories, files and symlinks through os.Root, and applies deferred directory and symlink metadata deepest first.
  • fastzip: can't be patched yet (v0.2.0 is the latest release), so the runner wraps it:
    1. Pre-scan: reject the archive if a file or directory entry would be written through an on-disk symlink that escapes the root.
    2. Extract: run fastzip with symlink entries hidden, so it writes only files and directories.
    3. Symlinks: create them through os.Root, replacing an empty directory if one is in the way.
    4. Times: restore the parent directories' times that step 3 changed.

Why was this MR needed?

A symlink left on disk by an earlier extraction, or shipped in the archive itself, could make a later entry write, replace or chmod files outside the build directory, because the containment check only looked at the path string. Outward symlinks must keep working (venvs rely on them), so the fix blocks writing through them rather than rejecting them.

What's the best way to test this MR?

go test -race -count=1 ./commands/helpers/archive/...

What are the relevant issue numbers?

Closes #39687

Edited by Ashvin Sharma

Merge request reports

Loading
Loading