-
-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sphinx_pyscript
- Loading branch information
Showing
9 changed files
with
74 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
------------------ | ||
B614: pytorch_load | ||
------------------ | ||
|
||
.. automodule:: bandit.plugins.pytorch_load |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import torch | ||
import torchvision.models as models | ||
|
||
# Example of saving a model | ||
model = models.resnet18(pretrained=True) | ||
torch.save(model.state_dict(), 'model_weights.pth') | ||
|
||
# Example of loading the model weights in an insecure way (should trigger B614) | ||
loaded_model = models.resnet18() | ||
loaded_model.load_state_dict(torch.load('model_weights.pth')) | ||
|
||
# Example of loading with weights_only=True (should NOT trigger B614) | ||
safe_model = models.resnet18() | ||
safe_model.load_state_dict(torch.load('model_weights.pth', weights_only=True)) | ||
|
||
# Example of loading with weights_only=False (should trigger B614) | ||
unsafe_model = models.resnet18() | ||
unsafe_model.load_state_dict(torch.load('model_weights.pth', weights_only=False)) | ||
|
||
# Example of loading with map_location but no weights_only (should trigger B614) | ||
cpu_model = models.resnet18() | ||
cpu_model.load_state_dict(torch.load('model_weights.pth', map_location='cpu')) | ||
|
||
# Example of loading with both map_location and weights_only=True (should NOT trigger B614) | ||
safe_cpu_model = models.resnet18() | ||
safe_cpu_model.load_state_dict(torch.load('model_weights.pth', map_location='cpu', weights_only=True)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters