Fix unsafe torch.load
by adding weights_only=True
#94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Description: Resemblyzer Unsafe Pickle Loading Mitigation
In version 0.1.4 of Resemblyzer, the use of
torch.load()
without explicitly settingweights_only=True
can expose users to potential risks when loading pickled files. Pickle files can execute arbitrary code during deserialization, leading to security vulnerabilities, and current versions oftorch
warn about this.To address this, I modified Resemblyzer's
voice_encoder.py
to enforce safer loading practices. Specifically, we updated thetorch.load()
calls to include the parameterweights_only=True
, ensuring that only model weights are loaded without executing untrusted code.This modification secures the file loading process and mitigates the risks associated with untrusted data deserialization. The change was made directly in the codebase without using external scripts to patch the system.
Details of the Change:
voice_encoder.py
weights_only=True
to alltorch.load()
calls that previously lacked this parameter.FYI: Since the currently implemented
torch.load()
method is considered unsafe, I've been using an automated code patching script for my whisper-transcriber-telegram-bot when it comes to loading Resemblyzer-related stuff. Should someone need to patch their v0.1.4, the script I made is here. I haven't experienced any bugs or glitches when using theweights_only=True
load method in my own application.