Skip to content

tf.compat.v1.signal.rfft2d and rfft3d lacks input validation leading to crashes #55263

Closed
@kanghj

Description

@kanghj

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): N/A
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.8.0
  • Python version:3.7.12
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: 11.2 (based on a colab notebook)
  • GPU model and memory: Tesla T4, 15109MiB (based on a colab notebook)

Describe the current behavior

The following code snippets lead to crashes when executed:

import numpy as np
import tensorflow as tf

a = np.empty([6, 0])
b = np.array([1, -1])
try:
  tf.compat.v1.signal.rfft2d(input_tensor=a,fft_length=b)
  # on a different machine: Check failed: size >= 0 (-9223372036854775808 vs. 0)
  # Aborted (core dumped)
except:
  pass

print('execution does not reach this line')

and

import numpy as np
import tensorflow as tf

a = np.empty([6, 1, 1])
b = np.array([1, 2, 0])

try:
  tf.compat.v1.signal.irfft3d(input_tensor=a,fft_length=b)
  # on a different machine: failed to initialize batched cufft plan with customized allocator: Failed to make cuFFT batched plan.
  # Aborted (core dumped)
except:
  pass
print('execution does not reach this line')

In either case, the inputs do not quite make sense, and tensorflow should throw.

Describe the expected behavior

Tensorflow should throw exceptions instead of crashing.

Contributing

  • Do you want to contribute a PR? (yes/no):
  • Briefly describe your candidate solution(if contributing):

Standalone code to reproduce the issue

Here is a colab notebook:
https://colab.research.google.com/drive/168jYG6MqnW4jpJdIXFMUBkyiaweA43aP?usp=sharing
Edit: the notebook has to be run with GPU

The code snippets above should also reproduce the issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions