jdx/mise · error

invalid OCI layer path

Error message

invalid OCI layer path {}

What it means

When unpacking OCI base-image layers, `clean_layer_path` normalizes each tar entry path and rejects any path containing a parent-directory (`..`) component or a Windows prefix, since such entries would escape the rootfs. This is a path-traversal safety check on untrusted layer contents.

Solutions

  1. Use a different, trusted base image whose layer tarballs contain normalized paths.
  2. Re-inspect the layer contents (`tar -tf layer.tar | grep '\.\.'`) to find and remove offending entries.
  3. Rebuild the image with a toolchain that sanitizes tar entry paths (e.g. up-to-date buildkit).
Defensive patterns

Strategy: validation

Validate before calling

// before pulling, verify the image is from a trusted source
if (!trustedRegistries.includes(new URL(imageRef).host)) throw new Error(`refusing untrusted image ${imageRef}`);

Type guard

const isSafeLayerPath = (p) => !p.split('/').some(seg => seg === '..' || seg === '');

Try / catch

try { unpackBaseLayers(img) } catch (e) { if (String(e).includes('invalid OCI layer path')) { console.error('Base image layer contains escaping paths; use a trusted image.'); process.exit(1); } throw e; }

Prevention

When it happens

Trigger: `unpack_base_layers` processes a layer whose tar contains an entry path that, after dropping `./` and leading `/`, still contains `..` (or a Windows prefix component), causing `clean_layer_path` to bail.

Common situations: Maliciously crafted or corrupted OCI images; images built by tools that emit non-normalized tar paths; pulling an unvetted base image from an untrusted registry.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/5042d879d22451d6. Report an issue: GitHub.

Appendix: source

Thrown at src/oci/packages.rs:291

    let magic = reader.fill_buf()?;
    if magic.starts_with(&[0x1f, 0x8b]) {
        Ok(LayerCompression::Gzip)
    } else if magic.starts_with(&[0x28, 0xb5, 0x2f, 0xfd]) {
        Ok(LayerCompression::Zstd)
    } else {
        Ok(LayerCompression::Tar)
    }
}

fn clean_layer_path(path: &Path) -> Result<PathBuf> {
    let mut out = PathBuf::new();
    for component in path.components() {
        match component {
            Component::CurDir | Component::RootDir => {}
            Component::Normal(part) => out.push(part),
            Component::ParentDir | Component::Prefix(_) => {
                bail!("invalid OCI layer path {}", path.display())
            }
        }
    }
    Ok(out)
}

fn apply_oci_whiteout(rootfs: &Path, rel: &Path) -> Result<bool> {
    let Some(name) = rel.file_name().and_then(|n| n.to_str()) else {
        return Ok(false);
    };
    let parent = rel.parent().unwrap_or_else(|| Path::new(""));
    if name == ".wh..wh..opq" {
        let dir = rootfs.join(parent);
        if dir.is_dir() {
            for entry in fs::read_dir(&dir)? {
                remove_path(&entry?.path())?;
            }
        }

View on GitHub (pinned to 533346cc37)