PyTorch LossCTC.cpp torch.nn.functional.ctc_loss denial of service
Description
A vulnerability, which was classified as problematic, was found in PyTorch 2.6.0. Affected is the function torch.nn.functional.ctc_loss of the file aten/src/ATen/native/LossCTC.cpp. The manipulation leads to denial of service. An attack has to be approached locally. The exploit has been disclosed to the public and may be used. The real existence of this vulnerability is still doubted at the moment. The name of the patch is 46fc5d8e360127361211cb237d5f9eef0223e567. It is recommended to apply a patch to fix this issue. The security policy of the project warns to use unknown models which might establish malicious effects.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
torchPyPI | < 2.8.0 | 2.8.0 |
Affected products
1Patches
246fc5d8e3601Add check for ctc_loss targets param (#150981)
3 files changed · +11 −0
aten/src/ATen/native/cuda/LossCTC.cu+1 −0 modified@@ -219,6 +219,7 @@ ctc_loss_log_alpha_gpu_kernel(scalar_t* __restrict__ log_alpha_data, // backward. The dispatch function will only return the loss. template<typename scalar_t, ScalarType target_scalar_type> std::tuple<Tensor, Tensor> ctc_loss_gpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) { + TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty"); // log_probs: input_len x batch_size x num_labels // targets [int64]: batch_size x target_length OR sum(target_lengths) CheckedFrom c = "ctc_loss_gpu";
aten/src/ATen/native/LossCTC.cpp+1 −0 modified@@ -126,6 +126,7 @@ std::tuple<Tensor, Tensor, size_t, std::vector<int64_t>> ctc_loss_allocate_outpu // the alphas from the user by only returning the loss. template<typename scalar_t, ScalarType target_scalar_type> std::tuple<Tensor, Tensor> ctc_loss_cpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) { + TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty"); // log_probs: input_len x batch_size x num_labels // targets [int64]: batch_size x target_length OR sum(target_lengths) constexpr scalar_t neginf = -std::numeric_limits<scalar_t>::infinity();
test/test_nn.py+9 −0 modified@@ -11532,6 +11532,15 @@ def test_ctc_loss_cudnn_tensor(self, device): grad_cudnn, = torch.autograd.grad(loss_cudnn, log_probs, grad_out) self.assertEqual(grad_cudnn, grad_native, atol=1e-4, rtol=0) + @expectedFailureMPS + def test_ctc_loss_error(self, device): + log_probs = torch.rand(0, 0, 4, device=device) + targets = torch.tensor([], device=device, dtype=torch.long) + input_lengths = torch.tensor([], device=device, dtype=torch.long) + target_lengths = torch.tensor([], device=device, dtype=torch.long) + with self.assertRaisesRegex(RuntimeError, "log_probs tensor must not be empty"): + F.ctc_loss(log_probs, targets, input_lengths, target_lengths, reduction='none') + @expectedFailureMPS # RuntimeError: LSTM with projections is not currently supported with MPS. @dtypesIfCUDA(torch.half, torch.float, torch.double) @dtypes(torch.float)
01f226bfb8f2Add check for ctc_loss targets param (#150981)
3 files changed · +11 −0
aten/src/ATen/native/cuda/LossCTC.cu+1 −0 modified@@ -219,6 +219,7 @@ ctc_loss_log_alpha_gpu_kernel(scalar_t* __restrict__ log_alpha_data, // backward. The dispatch function will only return the loss. template<typename scalar_t, ScalarType target_scalar_type> std::tuple<Tensor, Tensor> ctc_loss_gpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) { + TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty"); // log_probs: input_len x batch_size x num_labels // targets [int64]: batch_size x target_length OR sum(target_lengths) CheckedFrom c = "ctc_loss_gpu";
aten/src/ATen/native/LossCTC.cpp+1 −0 modified@@ -126,6 +126,7 @@ std::tuple<Tensor, Tensor, size_t, std::vector<int64_t>> ctc_loss_allocate_outpu // the alphas from the user by only returning the loss. template<typename scalar_t, ScalarType target_scalar_type> std::tuple<Tensor, Tensor> ctc_loss_cpu_template(const Tensor& log_probs, const Tensor& targets, IntArrayRef input_lengths, IntArrayRef target_lengths, int64_t BLANK) { + TORCH_CHECK(log_probs.numel() > 0, "log_probs tensor must not be empty"); // log_probs: input_len x batch_size x num_labels // targets [int64]: batch_size x target_length OR sum(target_lengths) constexpr scalar_t neginf = -std::numeric_limits<scalar_t>::infinity();
test/test_nn.py+9 −0 modified@@ -11532,6 +11532,15 @@ def test_ctc_loss_cudnn_tensor(self, device): grad_cudnn, = torch.autograd.grad(loss_cudnn, log_probs, grad_out) self.assertEqual(grad_cudnn, grad_native, atol=1e-4, rtol=0) + @expectedFailureMPS + def test_ctc_loss_error(self, device): + log_probs = torch.rand(0, 0, 4, device=device) + targets = torch.tensor([], device=device, dtype=torch.long) + input_lengths = torch.tensor([], device=device, dtype=torch.long) + target_lengths = torch.tensor([], device=device, dtype=torch.long) + with self.assertRaisesRegex(RuntimeError, "log_probs tensor must not be empty"): + F.ctc_loss(log_probs, targets, input_lengths, target_lengths, reduction='none') + @expectedFailureMPS # RuntimeError: LSTM with projections is not currently supported with MPS. @dtypesIfCUDA(torch.half, torch.float, torch.double) @dtypes(torch.float)
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
10- github.com/timocafe/tewart-pytorch/commit/46fc5d8e360127361211cb237d5f9eef0223e567ghsapatchWEB
- github.com/pytorch/pytorch/issues/150835mitreexploitissue-tracking
- github.com/advisories/GHSA-887c-mr87-cxwpghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2025-3730ghsaADVISORY
- vuldb.comghsathird-party-advisoryWEB
- github.com/pytorch/pytorch/commit/01f226bfb8f2c343f5c614a6bbf685d91160f3afghsaWEB
- github.com/pytorch/pytorch/issues/150835ghsaissue-trackingWEB
- github.com/pytorch/pytorch/pull/150981ghsaissue-trackingWEB
- vuldb.comghsasignaturepermissions-requiredWEB
- vuldb.comghsavdb-entrytechnical-descriptionWEB
News mentions
0No linked articles in our index yet.