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

Division by zero in `ParallelConcat`

CVE-2021-41207

Description

TensorFlow is an open source platform for machine learning. In affected versions the implementation of ParallelConcat misses some input validation and can produce a division by 0. 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.4.42.4.4
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.22.5.2
tensorflow-cpuPyPI
>= 2.6.0, < 2.6.12.6.1
tensorflow-gpuPyPI
< 2.4.42.4.4
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.22.5.2
tensorflow-gpuPyPI
>= 2.6.0, < 2.6.12.6.1

Affected products

1

Patches

4
9de11bdc2cf1

Adding more validation checks to _ParallelConcatUpdate to avoid NPE.

https://github.com/tensorflow/tensorflowRohan JainOct 12, 2021via ghsa
2 files changed · +26 0
  • tensorflow/core/kernels/inplace_ops.cc+9 0 modified
    @@ -72,6 +72,15 @@ class ParallelConcatUpdate : public OpKernel {
     
       void Compute(OpKernelContext* ctx) override {
         auto value = ctx->input(0);
    +    // Value should be at least rank 1. Also the 0th dimension should be
    +    // at least loc_.
    +    OP_REQUIRES(ctx, value.dims() >= 1,
    +                errors::InvalidArgument("value should be at least rank 1."));
    +    OP_REQUIRES(
    +        ctx, value.dim_size(0) > loc_,
    +        errors::InvalidArgument("0th dimension of value = ", value.dim_size(0),
    +                                " is less than loc_=", loc_));
    +
         auto update = ctx->input(1);
     
         OP_REQUIRES(
    
  • tensorflow/python/kernel_tests/array_ops/stack_op_test.py+17 0 modified
    @@ -20,12 +20,16 @@
     
     import numpy as np
     
    +from tensorflow.python import tf2
     from tensorflow.python.eager import context
    +from tensorflow.python.eager import def_function
     from tensorflow.python.framework import constant_op
     from tensorflow.python.framework import dtypes
    +from tensorflow.python.framework import errors
     from tensorflow.python.framework import ops
     from tensorflow.python.framework import test_util
     from tensorflow.python.ops import array_ops
    +from tensorflow.python.ops import gen_array_ops
     from tensorflow.python.ops import gradient_checker_v2
     from tensorflow.python.platform import test
     
    @@ -73,6 +77,19 @@ def testSimpleParallelCPU(self):
                 c = array_ops.parallel_stack(xs)
                 self.assertAllEqual(c, data)
     
    +  def testParallelConcatShapeZero(self):
    +    if not tf2.enabled():
    +      self.skipTest("only fails in TF2")
    +
    +    @def_function.function
    +    def f():
    +      y = gen_array_ops.parallel_concat(values=[["tf"]], shape=0)
    +      return y
    +
    +    with self.assertRaisesRegex(errors.InvalidArgumentError,
    +                                r"0th dimension of value .* is less than"):
    +      f()
    +
       def testSimpleParallelGPU(self):
         # tf.parallel_stack is only supported in graph mode.
         with ops.Graph().as_default():
    
e67caccea811

Adding more validation checks to _ParallelConcatUpdate to avoid NPE.

https://github.com/tensorflow/tensorflowRohan JainOct 12, 2021via ghsa
2 files changed · +26 0
  • tensorflow/core/kernels/inplace_ops.cc+9 0 modified
    @@ -71,6 +71,15 @@ class ParallelConcatUpdate : public OpKernel {
     
       void Compute(OpKernelContext* ctx) override {
         auto value = ctx->input(0);
    +    // Value should be at least rank 1. Also the 0th dimension should be
    +    // at least loc_.
    +    OP_REQUIRES(ctx, value.dims() >= 1,
    +                errors::InvalidArgument("value should be at least rank 1."));
    +    OP_REQUIRES(
    +        ctx, value.dim_size(0) > loc_,
    +        errors::InvalidArgument("0th dimension of value = ", value.dim_size(0),
    +                                " is less than loc_=", loc_));
    +
         auto update = ctx->input(1);
     
         OP_REQUIRES(
    
  • tensorflow/python/kernel_tests/array_ops/stack_op_test.py+17 0 modified
    @@ -20,12 +20,16 @@
     
     import numpy as np
     
    +from tensorflow.python import tf2
    +from tensorflow.python.eager import def_function
     from tensorflow.python.framework import constant_op
     from tensorflow.python.framework import dtypes
    +from tensorflow.python.framework import errors
     from tensorflow.python.framework import errors_impl
     from tensorflow.python.framework import ops
     from tensorflow.python.framework import test_util
     from tensorflow.python.ops import array_ops
    +from tensorflow.python.ops import gen_array_ops
     from tensorflow.python.ops import gradient_checker
     from tensorflow.python.ops import variables
     from tensorflow.python.platform import test
    @@ -76,6 +80,19 @@ def testSimpleParallelCPU(self):
                 c = array_ops.parallel_stack(xs)
                 self.assertAllEqual(c, data)
     
    +  def testParallelConcatShapeZero(self):
    +    if not tf2.enabled():
    +      self.skipTest("only fails in TF2")
    +
    +    @def_function.function
    +    def f():
    +      y = gen_array_ops.parallel_concat(values=[["tf"]], shape=0)
    +      return y
    +
    +    with self.assertRaisesRegex(errors.InvalidArgumentError,
    +                                r"0th dimension of value .* is less than"):
    +      f()
    +
       def testSimpleParallelGPU(self):
         # tf.parallel_stack is only supported in graph mode.
         with ops.Graph().as_default():
    
f2c3931113ea

Adding more validation checks to _ParallelConcatUpdate to avoid NPE.

https://github.com/tensorflow/tensorflowRohan JainOct 12, 2021via ghsa
2 files changed · +26 0
  • tensorflow/core/kernels/inplace_ops.cc+9 0 modified
    @@ -71,6 +71,15 @@ class ParallelConcatUpdate : public OpKernel {
     
       void Compute(OpKernelContext* ctx) override {
         auto value = ctx->input(0);
    +    // Value should be at least rank 1. Also the 0th dimension should be
    +    // at least loc_.
    +    OP_REQUIRES(ctx, value.dims() >= 1,
    +                errors::InvalidArgument("value should be at least rank 1."));
    +    OP_REQUIRES(
    +        ctx, value.dim_size(0) > loc_,
    +        errors::InvalidArgument("0th dimension of value = ", value.dim_size(0),
    +                                " is less than loc_=", loc_));
    +
         auto update = ctx->input(1);
     
         OP_REQUIRES(
    
  • tensorflow/python/kernel_tests/array_ops/stack_op_test.py+17 0 modified
    @@ -16,12 +16,16 @@
     
     import numpy as np
     
    +from tensorflow.python import tf2
     from tensorflow.python.eager import context
    +from tensorflow.python.eager import def_function
     from tensorflow.python.framework import constant_op
     from tensorflow.python.framework import dtypes
    +from tensorflow.python.framework import errors
     from tensorflow.python.framework import ops
     from tensorflow.python.framework import test_util
     from tensorflow.python.ops import array_ops
    +from tensorflow.python.ops import gen_array_ops
     from tensorflow.python.ops import gradient_checker_v2
     from tensorflow.python.platform import test
     
    @@ -69,6 +73,19 @@ def testSimpleParallelCPU(self):
                 c = array_ops.parallel_stack(xs)
                 self.assertAllEqual(c, data)
     
    +  def testParallelConcatShapeZero(self):
    +    if not tf2.enabled():
    +      self.skipTest("only fails in TF2")
    +
    +    @def_function.function
    +    def f():
    +      y = gen_array_ops.parallel_concat(values=[["tf"]], shape=0)
    +      return y
    +
    +    with self.assertRaisesRegex(errors.InvalidArgumentError,
    +                                r"0th dimension of value .* is less than"):
    +      f()
    +
       def testSimpleParallelGPU(self):
         # tf.parallel_stack is only supported in graph mode.
         with ops.Graph().as_default():
    
d11f21bbdfa5

Adding more validation checks to _ParallelConcatUpdate to avoid NPE.

https://github.com/tensorflow/tensorflowRohan JainOct 12, 2021via ghsa
2 files changed · +29 0
  • tensorflow/core/kernels/inplace_ops.cc+9 0 modified
    @@ -71,6 +71,15 @@ class ParallelConcatUpdate : public OpKernel {
     
       void Compute(OpKernelContext* ctx) override {
         auto value = ctx->input(0);
    +    // Value should be at least rank 1. Also the 0th dimension should be
    +    // at least loc_.
    +    OP_REQUIRES(ctx, value.dims() >= 1,
    +                errors::InvalidArgument("value should be at least rank 1."));
    +    OP_REQUIRES(
    +        ctx, value.dim_size(0) > loc_,
    +        errors::InvalidArgument("0th dimension of value = ", value.dim_size(0),
    +                                " is less than loc_=", loc_));
    +
         auto update = ctx->input(1);
     
         OP_REQUIRES(
    
  • tensorflow/python/kernel_tests/stack_op_test.py+20 0 modified
    @@ -20,12 +20,16 @@
     
     import numpy as np
     
    +from tensorflow.python import tf2
    +from tensorflow.python.eager import def_function
     from tensorflow.python.framework import constant_op
     from tensorflow.python.framework import dtypes
    +from tensorflow.python.framework import errors
     from tensorflow.python.framework import errors_impl
     from tensorflow.python.framework import ops
     from tensorflow.python.framework import test_util
     from tensorflow.python.ops import array_ops
    +from tensorflow.python.ops import gen_array_ops
     from tensorflow.python.ops import gradient_checker
     from tensorflow.python.ops import variables
     from tensorflow.python.platform import test
    @@ -75,7 +79,23 @@ def testSimpleParallelCPU(self):
               c = array_ops.parallel_stack(xs)
               self.assertAllEqual(c, data)
     
    +<<<<<<< HEAD:tensorflow/python/kernel_tests/stack_op_test.py
       @test_util.run_deprecated_v1
    +=======
    +  def testParallelConcatShapeZero(self):
    +    if not tf2.enabled():
    +      self.skipTest("only fails in TF2")
    +
    +    @def_function.function
    +    def f():
    +      y = gen_array_ops.parallel_concat(values=[["tf"]], shape=0)
    +      return y
    +
    +    with self.assertRaisesRegex(errors.InvalidArgumentError,
    +                                r"0th dimension of value .* is less than"):
    +      f()
    +
    +>>>>>>> e67caccea81 (Adding more validation checks to _ParallelConcatUpdate to avoid NPE.):tensorflow/python/kernel_tests/array_ops/stack_op_test.py
       def testSimpleParallelGPU(self):
         np.random.seed(7)
         with self.session(use_gpu=True):
    

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

11

News mentions

0

No linked articles in our index yet.