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

Division by zero in TensorFlow Lite division operations

CVE-2021-37683

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions the implementation of division in TFLite is vulnerable to a division by 0 error. There is no check that the divisor tensor does not contain zero elements. We have patched the issue in GitHub commit 1e206baedf8bef0334cca3eb92bab134ef525a28. 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
1e206baedf8b

Prevent a division by 0 in division ops.

https://github.com/tensorflow/tensorflowMihai MaruseacJul 16, 2021via ghsa
1 file changed · +16 1
  • tensorflow/lite/kernels/div.cc+16 1 modified
    @@ -216,9 +216,23 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
       TF_LITE_ENSURE_OK(context,
                         GetOutputSafe(context, node, kOutputTensor, &output));
     
    -  if (output->type == kTfLiteFloat32 || output->type == kTfLiteInt32) {
    +  // TODO(b/193904910): This can written with C++ templates
    +#define TF_LITE_CHECK_DIV_NON_ZERO(data_type)                       \
    +  const auto* input2_data = GetTensorData<data_type>(input2);       \
    +  const size_t input2_elements = input2->bytes / sizeof(data_type); \
    +  for (size_t i = 0; i < input2_elements; i++) {                    \
    +    TF_LITE_ENSURE(context, input2_data[i] != 0);                   \
    +  }
    +
    +  if (output->type == kTfLiteFloat32) {
    +    // Div by zero seems ok in this case, just like in TF case infinities are
    +    // returned. So we don't do a check at this point.
    +    EvalDiv<kernel_type>(context, node, params, data, input1, input2, output);
    +  } else if (output->type == kTfLiteInt32) {
    +    TF_LITE_CHECK_DIV_NON_ZERO(int32_t);
         EvalDiv<kernel_type>(context, node, params, data, input1, input2, output);
       } else if (output->type == kTfLiteUInt8) {
    +    TF_LITE_CHECK_DIV_NON_ZERO(uint8_t);
         TF_LITE_ENSURE_OK(
             context, EvalQuantized<kernel_type>(context, node, params, data, input1,
                                                 input2, output));
    @@ -229,6 +243,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
             output->type);
         return kTfLiteError;
       }
    +#undef TF_LITE_CHECK_DIV_NON_ZERO
     
       return kTfLiteOk;
     }
    

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

8

News mentions

0

No linked articles in our index yet.