{"record":{"id":"239f8c7d5318cbb4","repo":"unslothai/unsloth","slug":"the-pinned-spec-name-source-archive-failed-integ","errorCode":null,"errorMessage":"The pinned {spec.name} source archive failed integrity validation","messagePattern":"The pinned (.+?) source archive failed integrity validation","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"studio/backend/utils/third_party_source.py","lineNumber":694,"sourceCode":"                                raise RuntimeError(\n                                    f\"The pinned {spec.name} archive contains an unreadable file\"\n                                )\n                            destination_file = staging.joinpath(*parts[1:])\n                            destination_file.parent.mkdir(parents = True, exist_ok = True)\n                            remaining = member.size\n                            with source_file, destination_file.open(\"wb\") as handle:\n                                while remaining:\n                                    chunk = source_file.read(min(1024 * 1024, remaining))\n                                    if not chunk:\n                                        raise RuntimeError(\n                                            f\"The pinned {spec.name} archive ended unexpectedly\"\n                                        )\n                                    handle.write(chunk)\n                                    remaining -= len(chunk)\n        except (tarfile.TarError, EOFError, OSError) as error:\n            raise RuntimeError(f\"The pinned {spec.name} source archive is invalid\") from error\n        if _sealed_source_manifest(staging, spec) is None:\n            raise RuntimeError(f\"The pinned {spec.name} source archive failed integrity validation\")\n        _replace_owned_directory(staging, destination)\n    finally:\n        _remove_owned_path(workspace)\n\n\ndef _valid_runtime(\n    runtime: Path,\n    spec: PinnedSource,\n    checkout: Path | None = None,\n) -> bool:\n    if runtime.is_symlink() or not runtime.is_dir():\n        return False\n    try:\n        required_files = _configured_package_paths(\n            spec.required_files,\n            spec,\n            kind = \"required\",\n        )","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/third_party_source.py#L676-L712","documentation":"After extraction completes, _sealed_source_manifest(staging, spec) recomputes the extracted tree's digest manifest and compares it against spec.source_tree_digest; returning None means mismatch. This is the trust anchor of the whole pipeline: even if every structural check passed, the bytes on disk must hash exactly to the pinned value, so a tampered archive can never be installed.","triggerScenarios":"The extracted staging tree's computed manifest differs from the pinned source_tree_digest — archive content was modified relative to the pin (revised files at the same URL, repacked archive, or a genuinely wrong digest in the spec).","commonSituations":"Upstream force-pushed the tagged revision or the host regenerates tarballs (mtime/normalization differences change the tree digest); pinning a digest computed from a different export format than archive_url serves; typo'd digest; supply-chain substitution at the mirror.","solutions":["Recompute the tree digest from the freshly downloaded canonical archive and update source_tree_digest in the pin (and runtime_tree_digest together, per the paired-digest rule)","Ensure the digest was derived using the same normalization the library applies in _sealed_source_manifest (path set + file content hashes) — reuse the library's helper rather than a naive tarball hash","Pin immutable URLs (codeload for an exact SHA) so content can never drift","If the digest was correct and still fails, suspect local tampering or disk corruption — audit the host"],"exampleFix":"# before: digest from ad-hoc script\nsource_tree_digest = sha256_of_tarball_bytes  # wrong basis\n\n# after: digest from the library's own manifest over the extracted tree\nfrom studio.backend.utils import third_party_source as tps\nsource_tree_digest = tps.tree_digest_of(staging_dir)  # same normalization as validation","handlingStrategy":"validation","validationCode":"# validate before installing: extract to a temp dir and re-run the library's own manifest\nimport tempfile\nfrom studio.backend.utils.third_party_source import _sealed_source_manifest\nwith tempfile.TemporaryDirectory() as td:\n    extract(spec.archive_url, td)  # your trusted extraction\n    assert _sealed_source_manifest(Path(td), spec) is not None, \"digest mismatch — fix pin\"","typeGuard":null,"tryCatchPattern":"try:\n    ensure_pinned_source(spec)\nexcept RuntimeError as e:\n    if \"failed integrity validation\" in str(e):\n        # do NOT bypass; recompute digest from the canonical artifact and update the pin","preventionTips":["Derive source_tree_digest using the library's own manifest code over a freshly downloaded canonical artifact, so normalization always matches","Pin immutable per-commit URLs so upstream content drift is impossible"],"tags":["security","integrity","digest","pinned-source","supply-chain"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}