CVE-2024-31580: Torch PyTorch Heap Buffer Overflow Vulnerability Vulnerability

HIGH
Advisory Identifier: GHSA-5pcm-hx3q-hm94
CVSS 7.5
CWE-122
Published
Advisory Summary

CVE-2024-31580 is a HIGH (CVSS 7.5) pytorch heap buffer overflow vulnerability vulnerability (CWE-122: Heap-based Buffer Overflow) affecting Torch libraries in the PyPI ecosystem. The issue involves pytorch heap buffer overflow vulnerability. Remediation is available by upgrading affected packages to version 2.2.0.

CVE-2024-31580 at a Glance

CVE Identifier CVE-2024-31580
GHSA Identifier GHSA-5pcm-hx3q-hm94
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-122: Heap-based Buffer Overflow
Affected Product Torch
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2024-31580

To remediate this vulnerability, upgrade all affected Torch dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

torch fixed: 2.2.0
pip install torch>=2.2.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show torch

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-31580, inspect your installed packages using pip:

pip show torch

Analyze the terminal output to locate any version of Torch in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.2.0), your application is affected.

Note: The pip show torch command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-122: Heap-based Buffer Overflow, where a heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). In Torch, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

PyTorch before v2.2.0 was discovered to contain a heap buffer overflow vulnerability in the component /runtime/vararg_functions.cpp. This vulnerability allows attackers to cause a Denial of Service (DoS) via a crafted input.

CVE-2024-31580 Affected Torch Versions

1 component(s)
Fixed Versions:
2.2.0
Product / Package Ecosystem Affected Versions Fixed Version
torch
PyPI
< 2.2.0
2.2.0

References

Frequently Asked Questions

What is CVE-2024-31580?
CVE-2024-31580 is a security vulnerability in Torch involving PyTorch heap buffer overflow vulnerability under CWE-122: Heap-based Buffer Overflow.
Which Torch versions are affected?
Affected versions include releases prior to 2.2.0 across affected packages: torch.
What version fixes CVE-2024-31580?
Upgrading to 2.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is torch affected?
Yes, torch is affected in releases prior to 2.2.0. Upgrade your dependency to 2.2.0 or later.
What is the CVSS score of CVE-2024-31580?
CVE-2024-31580 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2024-31580?
CVE-2024-31580 is classified under CWE-122: Heap-based Buffer Overflow (A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().).
How can I check PyPI dependencies for CVE-2024-31580?
Run the dependency tree command: 'pip show torch'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5pcm-hx3q-hm94",
  "modified" : "2025-06-11T13:39:30Z",
  "published" : "2024-04-17T21:30:48Z",
  "aliases" : [ "CVE-2024-31580" ],
  "summary" : "PyTorch heap buffer overflow vulnerability",
  "details" : "PyTorch before v2.2.0 was discovered to contain a heap buffer overflow vulnerability in the component /runtime/vararg_functions.cpp. This vulnerability allows attackers to cause a Denial of Service (DoS) via a crafted input.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "torch"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-31580"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pytorch/pytorch/commit/b5c3a17c2c207ebefcb85043f0cf94be9b2fef81"
  }, {
    "type" : "WEB",
    "url" : "https://gist.github.com/1047524396/038c78f2f007345e6f497698ace2aa3d"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/torch/PYSEC-2024-252.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pytorch/pytorch"
  }, {
    "type" : "WEB",
    "url" : "https://security.snyk.io/vuln/SNYK-PYTHON-TORCH-6649934"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-122" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-25T10:11:23Z",
    "nvd_published_at" : "2024-04-17T19:15:07Z"
  }
}