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

Division by 0 in `ResourceGather` in TensorFlow

CVE-2021-37653

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions an attacker can trigger a crash via a floating point exception in tf.raw_ops.ResourceGather. The implementation computes the value of a value, batch_size, and then divides by it without checking that this value is not 0. We have patched the issue in GitHub commit ac117ee8a8ea57b73d34665cdf00ef3303bc0b11. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.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.3.42.3.4
tensorflowPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflowPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-cpuPyPI
< 2.3.42.3.4
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-gpuPyPI
< 2.3.42.3.4
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.12.5.1

Affected products

1

Patches

1
ac117ee8a8ea

Prevent division by 0 in `resource_variable_ops.cc`

https://github.com/tensorflow/tensorflowMihai MaruseacJul 31, 2021via ghsa
1 file changed · +9 2
  • tensorflow/core/kernels/resource_variable_ops.cc+9 2 modified
    @@ -710,7 +710,8 @@ class ResourceGatherOp : public OpKernel {
             copy_functor(c->eigen_device<Device>(), tmp_indices.flat<Index>(),
                          indices.flat<Index>());
     
    -        AddBatchOffsets(&tmp_indices, params);
    +        AddBatchOffsets(c, &tmp_indices, params);
    +        if (!c->status().ok()) return;
             op_indices = &tmp_indices;
           }
     
    @@ -742,11 +743,17 @@ class ResourceGatherOp : public OpKernel {
       // Example: batch_dims = 1, indices = [[0, 1, 2], [0, 1, 2]]
       // If indexing into a params dimension of size 4, then the indices will become
       // [0, 1, 2, 4, 5, 6]
    -  void AddBatchOffsets(Tensor* indices, const Tensor& params) {
    +  void AddBatchOffsets(OpKernelContext* ctx, Tensor* indices,
    +                       const Tensor& params) {
         int64_t batch_size = 1;  // The size of all batch dimensions.
         for (int idx = 0; idx < batch_dims_; ++idx) {
           batch_size *= params.dim_size(idx);
         }
    +    OP_REQUIRES(
    +        ctx, batch_size != 0,
    +        errors::InvalidArgument(
    +            "Inner size of indices would result in batch_size of 0 and a ",
    +            "division by 0 in the implementation. This is illegal"));
     
         auto indices_flat = indices->flat<Index>();
         int64_t const index_inner_size = indices->NumElements() / batch_size;
    

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.