Skip to content

fix: use weights_only=True in torch.load to prevent arbitrary code execution#12

Open
theeldruin wants to merge 1 commit into
google-deepmind:mainfrom
theeldruin:fix/torch-load-weights-only
Open

fix: use weights_only=True in torch.load to prevent arbitrary code execution#12
theeldruin wants to merge 1 commit into
google-deepmind:mainfrom
theeldruin:fix/torch-load-weights-only

Conversation

@theeldruin

Copy link
Copy Markdown

Summary

`examples/sampling_pytorch.py:70` calls `torch.load(path_checkpoint)` without `weights_only=True`. PyTorch's default behavior uses pickle for deserialization, meaning a crafted `.pt` file can execute arbitrary code when loaded.

Change

```python

Before

params = torch.load(path_checkpoint)

After

params = torch.load(path_checkpoint, weights_only=True)
```

`weights_only=True` restricts deserialization to tensor types only, blocking `reduce` payloads entirely. It has been available since PyTorch 1.13 and is the recommended approach in PyTorch's own security guidance.

This was reported to Google via Bug Hunter and confirmed as a valid vulnerability.

@google-cla

google-cla Bot commented Jul 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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