Skip to content

fix: refuse untrusted globals when loading model checkpoints (v0.47.2) - #316

Merged
beveradb merged 1 commit into
mainfrom
feat/sess-20261029-0202-fix-unsafe-torch-load
Oct 29, 2026
Merged

beveradb merged 1 commit into
mainfrom
feat/sess-20261029-0202-fix-unsafe-torch-load

Conversation

@beveradb

Copy link
Copy Markdown
Collaborator

Summary

  • Demucs package files (.th) were loaded with torch.load(weights_only=False). They're pickles that store the model class, so a crafted file could run code at load time. They now load through a restricted unpickler that only resolves the globals real Demucs v4 packages use.
  • VR, MDXC, RoFormer and MDX mixer loads now pass weights_only=True explicitly. Before this they were only safe by default on torch >= 2.6, and our range allows 2.3. The RoFormer legacy fallback that retried without weights_only is removed.
  • Version bump to 0.47.2.

Verification

  • All 7 published Demucs v4 checkpoints (htdemucs, htdemucs_ft x4, htdemucs_6s, hdemucs_mmi) load and build their models through the new path, with packages identical to the old unsafe load (kwargs, class, every tensor).
  • A .th carrying an os.system payload is refused and the payload never runs.
  • New tests/unit/test_demucs_safe_load.py; updated mocks in test_directml.py and test_model_reuse.py. Unit suite: 560 passed. The 2 test_mps_native_fp16 failures also happen on main.
  • Local CodeRabbit review: no findings.

@coderabbitai ignore

🤖 Generated with Claude Code

https://claude.ai/code/session_012RYLVTA9CYSnmncNv3GRHJ

Demucs package files are pickles that store the model class, and were
loaded with torch.load(weights_only=False), so a crafted .th file could
run code at load time. Load them through a restricted unpickler that
only resolves the globals real Demucs v4 packages use (verified
byte-identical against all 7 published checkpoints).

Pass weights_only=True explicitly on the VR, MDXC, RoFormer and MDX
mixer loads, which were only safe by default on torch >= 2.6, and drop
the RoFormer legacy fallback that retried without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012RYLVTA9CYSnmncNv3GRHJ
@beveradb
beveradb merged commit 6d7d3fd into main Oct 29, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant