Division by zero in `ParallelConcat`
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.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
tensorflowPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflowPyPI | < 2.4.4 | 2.4.4 |
tensorflow-cpuPyPI | < 2.4.4 | 2.4.4 |
tensorflow-cpuPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflow-cpuPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
tensorflow-gpuPyPI | < 2.4.4 | 2.4.4 |
tensorflow-gpuPyPI | >= 2.5.0, < 2.5.2 | 2.5.2 |
tensorflow-gpuPyPI | >= 2.6.0, < 2.6.1 | 2.6.1 |
Affected products
1- Range: >= 2.6.0, < 2.6.1
Patches
49de11bdc2cf1Adding more validation checks to _ParallelConcatUpdate to avoid NPE.
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():
e67caccea811Adding more validation checks to _ParallelConcatUpdate to avoid NPE.
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():
f2c3931113eaAdding more validation checks to _ParallelConcatUpdate to avoid NPE.
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():
d11f21bbdfa5Adding more validation checks to _ParallelConcatUpdate to avoid NPE.
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- github.com/advisories/GHSA-7v94-64hj-m82hghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-41207ghsaADVISORY
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-616.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-814.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-399.yamlghsaWEB
- github.com/tensorflow/tensorflow/blob/8d72537c6abf5a44103b57b9c2e22c14f5f49698/tensorflow/core/kernels/inplace_ops.ccghsaWEB
- github.com/tensorflow/tensorflow/commit/9de11bdc2cf1284b2f635419bd3e6bbc7643eb2cghsaWEB
- github.com/tensorflow/tensorflow/commit/d11f21bbdfa54f3576ae860fc927bf23c675ebc0ghsaWEB
- github.com/tensorflow/tensorflow/commit/e67caccea81167402c62977b5c521f2a8b261d6aghsaWEB
- github.com/tensorflow/tensorflow/commit/f2c3931113eaafe9ef558faaddd48e00a6606235ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-7v94-64hj-m82hghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.