resemble-ai / Resemblyzer

A python package to analyze and compare voices with deep learning
Apache License 2.0
2.79k stars 429 forks source link

Fix unsafe `torch.load` by adding `weights_only=True` #94

Open FlyingFathead opened 2 months ago

FlyingFathead commented 2 months ago

Fix Description: Resemblyzer Unsafe Pickle Loading Mitigation

In version 0.1.4 of Resemblyzer, the use of torch.load() without explicitly setting weights_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 of torch warn about this.

To address this, I modified Resemblyzer's voice_encoder.py to enforce safer loading practices. Specifically, we updated the torch.load() calls to include the parameter weights_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:

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 the weights_only=True load method in my own application.