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

Bad alloc in `StringNGrams` caused by integer conversion in TensorFlow

CVE-2021-37646

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions the implementation of tf.raw_ops.StringNGrams is vulnerable to an integer overflow issue caused by converting a signed integer value to an unsigned one and then allocating memory based on this value. The implementation calls reserve on a tstring with a value that sometimes can be negative if user supplies negative ngram_widths. The reserve method calls TF_TString_Reserve which has an unsigned long argument for the size of the buffer. Hence, the implicit conversion transforms the negative value to a large integer. We have patched the issue in GitHub commit c283e542a3f422420cfdb332414543b62fc4e4a5. 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
c283e542a3f4

Disallow negative ngram_widths values in tf.raw_ops.StringNGrams

https://github.com/tensorflow/tensorflowLaura PakJul 27, 2021via ghsa
1 file changed · +6 0
  • tensorflow/core/kernels/string_ngrams_op.cc+6 0 modified
    @@ -53,6 +53,12 @@ class StringNGramsOp : public tensorflow::OpKernel {
       }
     
       void Compute(tensorflow::OpKernelContext* context) override {
    +    for (int ngram_width : ngram_widths_) {
    +      OP_REQUIRES(
    +          context, ngram_width > 0,
    +          errors::InvalidArgument("ngram_widths must contain positive values"));
    +    }
    +
         const tensorflow::Tensor* data;
         OP_REQUIRES_OK(context, context->input("data", &data));
         const auto& input_data = data->flat<tstring>().data();
    

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.