VYPR
High severityNVD Advisory· Published Nov 5, 2021· Updated Aug 4, 2024

Heap OOB read in `tf.ragged.cross`

CVE-2021-41212

Description

TensorFlow is an open source platform for machine learning. In affected versions the shape inference code for tf.ragged.cross can trigger a read outside of bounds of heap allocated array. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
>= 2.6.0, < 2.6.12.6.1
tensorflowPyPI
>= 2.5.0, < 2.5.22.5.2
tensorflowPyPI
< 2.4.42.4.4
tensorflow-cpuPyPI
>= 2.6.0, < 2.6.12.6.1
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.22.5.2
tensorflow-cpuPyPI
< 2.4.42.4.4
tensorflow-gpuPyPI
>= 2.6.0, < 2.6.12.6.1
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.22.5.2
tensorflow-gpuPyPI
< 2.4.42.4.4

Affected products

1

Patches

1
fa6b7782fbb1

Fix null pointer exception in shape inference function when tf.ragged.cross() is called with invalid inputs.

https://github.com/tensorflow/tensorflowEdward LoperSep 30, 2021via ghsa
2 files changed · +40 2
  • tensorflow/core/ops/ragged_array_ops.cc+7 0 modified
    @@ -99,6 +99,13 @@ REGISTER_OP("RaggedCross")
           int dense_start = num_ragged * 2 + num_sparse * 3;
           for (int i = 0; i < dense_types.size(); ++i) {
             ShapeHandle dense_input = c->input(i + dense_start);
    +        int32 rank = c->Rank(dense_input);
    +        if (rank == InferenceContext::kUnknownRank) {
    +          continue;
    +        } else if (rank != 2) {
    +          return errors::InvalidArgument(
    +              "tf.ragged.cross only supports inputs with rank=2");
    +        }
             int64_t batch_size = c->Value(c->Dim(dense_input, 0));
             if (batch_size != InferenceContext::kUnknownDim) {
               ShapeHandle row_splits = c->Vector(batch_size + 1);
    
  • tensorflow/python/ops/ragged/ragged_cross_op_test.py+33 2 modified
    @@ -18,10 +18,12 @@
     
     import numpy as np
     
    +from tensorflow.python.eager import def_function
     from tensorflow.python.framework import dtypes
     from tensorflow.python.framework import errors
     from tensorflow.python.framework import ops
     from tensorflow.python.framework import sparse_tensor
    +from tensorflow.python.framework import tensor_spec
     from tensorflow.python.framework import test_util
     from tensorflow.python.ops import sparse_ops
     from tensorflow.python.ops.ragged import ragged_array_ops
    @@ -358,6 +360,16 @@ def testRaggedCrossLargeBatch(self):
                       dense_const([[2], [3]])],
               exception=(ValueError, errors.InvalidArgumentError),
               message='inputs must all have the same batch dimension size'),
    +      dict(
    +          testcase_name='3DDenseTensor',
    +          inputs=[dense_const([[[1]]])],
    +          exception=(ValueError, errors.InvalidArgumentError),
    +          message='tf.ragged.cross only supports inputs with rank=2'),
    +      dict(
    +          testcase_name='0DDenseTensor',
    +          inputs=[dense_const(1)],
    +          exception=(ValueError, errors.InvalidArgumentError),
    +          message='tf.ragged.cross only supports inputs with rank=2'),
       ])
       def testStaticError(self, inputs, exception=ValueError, message=None):
         with self.assertRaisesRegex(exception, message):
    @@ -368,17 +380,36 @@ def testStaticError(self, inputs, exception=ValueError, message=None):
               testcase_name='3DRaggedTensor',
               inputs=[ragged_const([[[1]]], ragged_rank=1)],
               message='tf.ragged.cross only supports inputs with rank=2'),
    +      dict(
    +          testcase_name='0DDenseTensor',
    +          inputs=[dense_const(1)],
    +          signature=[[tensor_spec.TensorSpec(None, dtypes.int32)]],
    +          exception=(ValueError, errors.InvalidArgumentError),
    +          message='tf.ragged.cross only supports inputs with rank=2'),
    +      dict(
    +          testcase_name='1DDenseTensor',
    +          inputs=[dense_const([1])],
    +          signature=[[tensor_spec.TensorSpec(None, dtypes.int32)]],
    +          exception=(ValueError, errors.InvalidArgumentError),
    +          message='tf.ragged.cross only supports inputs with rank=2'),
           dict(
               testcase_name='3DDenseTensor',
               inputs=[dense_const([[[1]]])],
    +          signature=[[tensor_spec.TensorSpec(None, dtypes.int32)]],
    +          exception=(ValueError, errors.InvalidArgumentError),
               message='tf.ragged.cross only supports inputs with rank=2'),
       ])
       def testRuntimeError(self,
                            inputs,
                            exception=errors.InvalidArgumentError,
    -                       message=None):
    +                       message=None,
    +                       signature=None):
    +    @def_function.function(input_signature=signature)
    +    def fn(x):
    +      return ragged_array_ops.cross(x)
    +
         with self.assertRaisesRegex(exception, message):
    -      self.evaluate(ragged_array_ops.cross(inputs))
    +      self.evaluate(fn(inputs))
     
       def _ragged_to_sparse(self, t):
         if ragged_tensor.is_ragged(t):
    

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

7

News mentions

0

No linked articles in our index yet.