Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault in torch._C._nn.thnn_conv2d Due to Invalid Padding Argument #121188

Closed
Gwihwan-Go opened this issue Mar 5, 2024 · 4 comments
Closed
Labels
actionable module: crash Problem manifests as a hard crash, as opposed to a RuntimeError module: empty tensor module: error checking Bugs related to incorrect/lacking error checking module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Gwihwan-Go
Copy link
Contributor

Gwihwan-Go commented Mar 5, 2024

🐛 Describe the bug

A segmentation fault occurs when invoking torch._C._nn.thnn_conv2d with an empty list for the padding argument, alongside other parameters that are potentially mismatched or improperly specified.

Error log

Segmentation fault (core dumped)

Minimized Repro

import torch
torch._C._nn.thnn_conv2d(torch.rand([1]), bias=torch.rand([3]), kernel_size=[5], padding=[], stride=[9], weight=torch.rand([9]))

Versions

PyTorch version: 2.3.0.dev20240301+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @malfet

@malfet malfet added module: nn Related to torch.nn module: error checking Bugs related to incorrect/lacking error checking triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: empty tensor labels Mar 5, 2024
@albanD
Copy link
Collaborator

albanD commented Mar 6, 2024

Thanks for the report. We would definitely accept a PR adding the appropriate error checking to avoid the segfault!

@albanD albanD added the module: crash Problem manifests as a hard crash, as opposed to a RuntimeError label Mar 6, 2024
@Martim03
Copy link
Contributor

Martim03 commented Mar 7, 2024

Hi, I managed to replicate the issue and I would be willing to solve it if you don't mind! :)

@albanD
Copy link
Collaborator

albanD commented Mar 7, 2024

Sounds good. Feel free to send a PR and link this issue as fixed in the PR description

@Martim03
Copy link
Contributor

Martim03 commented Mar 9, 2024

Hi again, upon reviewing the code, I've noticed that a Segmentation Fault could also occur if the function is invoked with an invalid kernel_size or stride. Would you like me to include error checking for those cases as well?

ZelboK pushed a commit to ZelboK/pytorch that referenced this issue May 19, 2024
Fixes pytorch#121188
Prevent Segmentation Fault in 'torch._C._nn.thnn_conv2d'

Previously, calling 'torch._C._nn.thnn_conv2d' with invalid arguments for padding, stride, and kernel_size would result in a segmentation fault. This issue has been resolved by implementing argument validation (using Torch Check). Now, when invalid arguments are detected, a runtime error is raised with a debug message detailing the correct format.

Additionally, this commit includes tests to cover the three referenced cases.

Pull Request resolved: pytorch#121906
Approved by: https://github.com/janeyx99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable module: crash Problem manifests as a hard crash, as opposed to a RuntimeError module: empty tensor module: error checking Bugs related to incorrect/lacking error checking module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants