Skip to content

fix: safe PyTorch model loading (weights_only=True)#133

Merged
ruvnet merged 1 commit intomainfrom
fix/pickle-deserialization-safety
Mar 3, 2026
Merged

fix: safe PyTorch model loading (weights_only=True)#133
ruvnet merged 1 commit intomainfrom
fix/pickle-deserialization-safety

Conversation

@ruvnet
Copy link
Owner

@ruvnet ruvnet commented Mar 3, 2026

Summary

  • Replace unsafe torch.load(path) with torch.load(path, map_location=self.device, weights_only=True) in references/wifi_densepose_pytorch.py
  • Prevents pickle deserialization RCE (trailofbits.python.pickles-in-pytorch)
  • Adds map_location for correct CPU/GPU device mapping

This is the correct fix for the vulnerability identified in PR #106 (now closed). That PR introduced a custom RestrictedUnpickler which had several issues (missing import pickle, broken torch.save replacement, ignored map_location, incomplete allowlist). PyTorch's built-in weights_only=True (available since 1.13) is the recommended mitigation — it disables pickle entirely for model loading.

Test plan

  • Verify load_model() works with existing .pth checkpoints
  • Verify malicious pickle payloads are rejected with weights_only=True

🤖 Generated with claude-flow

Replace unsafe `torch.load(path)` with `torch.load(path,
map_location=self.device, weights_only=True)` to prevent
pickle deserialization RCE (trailofbits.python.pickles-in-pytorch).

weights_only=True disables pickle entirely for model loading,
which is the PyTorch-recommended mitigation (available since 1.13).
Also adds map_location for correct CPU/GPU device mapping.

Closes #106

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvnet ruvnet merged commit 26655d3 into main Mar 3, 2026
@ruvnet ruvnet deleted the fix/pickle-deserialization-safety branch March 3, 2026 23:11
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