fix: use weights_only=True with explicit safe globals for torch.load
Replaces weights_only=False with weights_only=True and an explicit add_safe_globals allowlist ([argparse.Namespace, PosixPath]) in both JoyVASA export scripts. This is the sanctioned PyTorch mitigation for the trailofbits pickles-in-pytorch semgrep pattern: only the known-safe non-default classes are allowlisted; all others are rejected by the restricted unpickler. Checkpoint format, SHA-256 pins, and all downstream payload accesses are unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b2b3851f85
commit
03f1cbb2c2
2 files changed
+9
-7
No files matched your search
@@ -6,7 +6,7 @@ import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pickle
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PosixPath
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
@@ -32,7 +32,8 @@ def main() -> None:
|
||||
if sha256(args.template) != EXPECTED_TEMPLATE_SHA256:
|
||||
raise RuntimeError("Unexpected JoyVASA motion template")
|
||||
|
||||
payload = torch.load(args.checkpoint, map_location="cpu", weights_only=False)
|
||||
torch.serialization.add_safe_globals([argparse.Namespace, PosixPath])
|
||||
payload = torch.load(args.checkpoint, map_location="cpu", weights_only=True)
|
||||
# The pinned 3.6KB pickle was audited before use and contains only a dict,
|
||||
# NumPy ndarray reconstruction, ndarray, and dtype globals.
|
||||
with args.template.open("rb") as handle:
|
||||
|
||||
Reference in new issue
Block a user