unslothai/unsloth · critical · RuntimeError

The pinned source archive expands too large

Error message

The pinned source archive expands too large

What it means

Raised by _BoundedArchiveReader.read when cumulative uncompressed bytes fed to tarfile exceed _ARCHIVE_MAX_TAR_BYTES. The reader wraps the gzip stream and only ever exposes limit+1 bytes, so a gzip bomb is detected as soon as the decompressed stream crosses the cap rather than after decompressing gigabytes.

Source

Thrown at studio/backend/utils/third_party_source.py:626

        or parts[0] != _archive_root_name(spec)
    ):
        raise RuntimeError(f"Invalid path in the pinned {spec.name} source archive")
    return parts


class _BoundedArchiveReader:
    def __init__(self, handle, limit: int):
        self._handle = handle
        self._limit = limit
        self._read = 0

    def read(self, size: int = -1) -> bytes:
        remaining = self._limit - self._read
        requested = remaining + 1 if size < 0 else min(size, remaining + 1)
        data = self._handle.read(requested)
        self._read += len(data)
        if self._read > self._limit:
            raise RuntimeError("The pinned source archive expands too large")
        return data


def _install_archive_source(destination: Path, spec: PinnedSource) -> None:
    if spec.archive_url is None or spec.source_tree_digest is None:
        raise RuntimeError(f"The pinned {spec.name} source archive is not configured")
    workspace = Path(tempfile.mkdtemp(prefix = ".archive-", dir = destination.parent))
    archive = workspace / "source.tar.gz"
    staging = workspace / "source"
    staging.mkdir()
    try:
        _download_archive(spec.archive_url, archive, spec)
        member_count = 0
        uncompressed_bytes = 0
        extracted = set()
        try:
            with archive.open("rb") as compressed:
                with gzip.GzipFile(fileobj = compressed, mode = "rb") as decompressed:

View on GitHub (pinned to 203007d190)

Solutions

  1. Verify the artifact out-of-band: gzip -dc source.tar.gz | wc -c and compare with _ARCHIVE_MAX_TAR_BYTES; check its SHA-256 against spec.source_tree_digest
  2. If the pin digest matches and the tree is legitimately that large, raise _ARCHIVE_MAX_TAR_BYTES (and _ARCHIVE_MAX_UNCOMPRESSED_BYTES) in your build
  3. If the digest does not match, the URL serves tampered content — repin to the canonical source and treat as a security incident
  4. Prefer slim source tarballs over bundles that include history or binaries
Defensive patterns

Strategy: validation

Validate before calling

import gzip
uncompressed = 0
with gzip.open("source.tar.gz", "rb") as f:
    while True:
        chunk = f.read(1024 * 1024)
        if not chunk:
            break
        uncompressed += len(chunk)
        if uncompressed > _ARCHIVE_MAX_TAR_BYTES:
            raise SystemExit("decompressed tar stream exceeds cap")

Try / catch

try:
    ensure_pinned_source(spec)
except RuntimeError as e:
    if "expands too large" in str(e):
        # verify digest; if pin is authentic and tree is legitimately big, adjust cap in your build

Prevention

When it happens

Trigger: The downloaded .tar.gz decompresses to more than _ARCHIVE_MAX_TAR_BYTES: a genuine gzip bomb (highly compressible filler) or a legitimately huge source tree exceeding the built-in uncompressed budget.

Common situations: Malicious archive substitution at the URL (defense triggers, install aborts); a dependency that vendored enormous generated files/test data so its source tree exceeds the cap; mis-pinned archive containing a full git history bundle.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/3c0a5da3f89313e9. Report an issue: GitHub.