/

CVE-2026-31250

Severity:

HIGH RISK

(7.3)

Unsafe Deserialization in CosyVoice average_model.py

CVE-2026-31250

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(7.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

CosyVoice's model averaging tool insecurely deserializes PyTorch checkpoint files using torch.load() without enabling the weights_only=True safeguard, allowing arbitrary Python object loading via pickle.

If an attacker can place or replace checkpoint files in a directory that a user later passes to the averaging script, arbitrary code may execute on the user's system during model averaging.

Affected context

This vulnerability appears in CosyVoice installations that rely on the average_model.py script to combine multiple model checkpoints (e.g., epoch_*.pt) into an averaged model.

It is most relevant when checkpoints are sourced from shared directories, downloaded from external sources, or otherwise not strictly controlled.

The risk materializes when users run the averaging tool on directories containing attacker-controlled or unverified PyTorch checkpoint files.

Exploit preconditions

  • Attack surface: Local execution environment where CosyVoice's average_model.py is run.
  • Required access: Ability to introduce or modify PyTorch checkpoint files (e.g., epoch_*.pt) in a directory that a victim will later use as input to the averaging script.
  • Trigger point: Invocation of the model averaging tool, which iterates over and deserializes checkpoint files using torch.load() without weights_only=True.
  • Why exploitation is possible: torch.load() delegates to Python's pickle machinery, and without restricting deserialization to weights only, arbitrary object graphs from untrusted files can be instantiated, enabling execution of attacker-defined code during loading.

Why this happens

The core issue is the use of a general-purpose, pickle-based deserialization API (torch.load) on data that may not be fully trusted, without constraining what can be deserialized.

This maps directly to CWE-502: Deserialization of Untrusted Data, where serialized input is treated as benign state but is actually interpreted as executable object construction instructions.

In this case, the absence of the weights_only=True parameter allows full object deserialization, so attacker-supplied checkpoint files can embed custom objects whose special methods execute code when instantiated during load.

Potential impact

  • Arbitrary code execution in the context of the user running the averaging script.
  • Installation of backdoors or persistence mechanisms on the victim's machine.
  • Unauthorized access to local files, credentials, or environment secrets.
  • Tampering with or poisoning model parameters and outputs, potentially undermining downstream ML workflows.
  • Use of the compromised environment as a stepping stone for broader lateral movement.

General mitigation guidance

Effective mitigation centers on constraining deserialization and reducing trust in external artifacts:

  • Prefer deserialization modes that restrict loaded content to plain tensors or weights, such as enabling security-focused options (e.g., weights_only=True in torch.load) when available.
  • Treat model checkpoints as untrusted input; validate provenance and integrity (e.g., signatures, checksums) before loading them.
  • Separate code and data concerns: design serialization formats that store only numeric weights or structured metadata, avoiding arbitrary object graphs.
  • Run tooling that processes external checkpoints with least-privilege accounts and in isolated environments (e.g., containers or sandboxes) to limit blast radius.
  • Establish policies that discourage automatic or scripted loading of artifacts from uncurated directories or user-uploaded locations.

How teams detect issues like this

Detection typically involves a mix of code analysis and process monitoring:

  • Static analysis: Search for uses of torch.load() (or similar pickle-backed APIs) that operate on variable or user-specified paths, especially where security options like weights_only=True are omitted.
  • Code review: Flag patterns where serialized artifacts come from shared, external, or user-provided locations and are loaded without validation or isolation.
  • Policy enforcement: Introduce linting or CI checks that require explicit security parameters for deserialization functions and discourage direct pickle usage.
  • Runtime monitoring: On high-value systems, monitor for unexpected process spawns or file modifications initiated while loading checkpoints, indicative of malicious payloads being executed.

Sources

SourceLink
github.comgithub.com/FunAudioLLM/CosyVoice
notion.sonotion.so/CVE-2026-31250-35d1e13931888147a9a3e1c5e239a0a7

Frequently asked

questions

Not by default over the network; exploitation typically requires that a victim locally runs the model averaging script on attacker-prepared checkpoint files.

However, if a workflow automatically fetches and averages remote checkpoints (e.g., from file shares or artifact repositories), a remote attacker could leverage that supply chain to deliver malicious files.

The attacker needs the ability to place or modify checkpoint files in a directory that the victim will later pass to average_model.py.

This could be achieved through compromised shared storage, malicious downloads, or tampered archives distributed as pre-trained models.

Adopt deserialization patterns that restrict what can be loaded and treat all model artifacts as untrusted by default.

Concretely, use security-focused options (such as weights_only=True when available), avoid loading arbitrary object graphs, and ensure that only vetted, integrity-checked checkpoints are processed.

Establish a secure artifact-handling policy for ML workflows that:

  • Prohibits direct pickle-based loading of untrusted files.
  • Mandates integrity and provenance checks for external models.
  • Enforces least privilege and isolation for tools that deserialize artifacts.
  • Integrates static checks and code review guidelines to catch unsafe deserialization patterns early in development.
Find out what's already
exploitable in your codebase.