Language: Python
Label: safe
CWE: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.

Code:
  def testEmptyShapeWithEditDistanceRaisesError(self):
    para = {
        "hypothesis_indices": [[]],
        "hypothesis_values": ["tmp/"],
        "hypothesis_shape": [],
        "truth_indices": [[]],
        "truth_values": [""],
        "truth_shape": [],
        "normalize": False,
    }

    # Check edit distance raw op with empty shape in eager mode.
    with self.assertRaisesRegex(
        (errors.InvalidArgumentError, ValueError),
        (
            r"Input Hypothesis SparseTensors must have rank at least 2, but"
            " hypothesis_shape rank is: 0|Input SparseTensors must have rank "
            "at least 2, but truth_shape rank is: 0"
        ),
    ):
      array_ops.gen_array_ops.EditDistance(**para)

    # Check raw op with tf.function
    @def_function.function
    def TestFunction():
      """Wrapper function for edit distance call."""
      array_ops.gen_array_ops.EditDistance(**para)

    with self.assertRaisesRegex(
        ValueError,
        (
            "Input Hypothesis SparseTensors must have rank at least 2, but"
            " hypothesis_shape rank is: 0"
        ),
    ):
      TestFunction()

    # Check with python wrapper API
    hypothesis_indices = [[]]
    hypothesis_values = [0]
    hypothesis_shape = []
    truth_indices = [[]]
    truth_values = [1]
    truth_shape = []
    expected_output = []  # dummy ignored

    with self.assertRaisesRegex(
        ValueError,
        (
            "Input Hypothesis SparseTensors must have rank at least 2, but"
            " hypothesis_shape rank is: 0"
        ),
    ):
      self._testEditDistance(
          hypothesis=(hypothesis_indices, hypothesis_values, hypothesis_shape),
          truth=(truth_indices, truth_values, truth_shape),
          normalize=False,
          expected_output=expected_output,
      )