{"id":"CVE-2021-37646","published":"2021-08-12T21:10:11Z","modified":"2024-08-04T01:23:01Z","title":"Bad alloc in `StringNGrams` caused by integer conversion in TensorFlow","vendor":"tensorflow","product":"tensorflow","tier":"tail","description":{"text":"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](https://github.com/tensorflow/tensorflow/blob/8d72537c6abf5a44103b57b9c2e22c14f5f49698/tensorflow/core/kernels/string_ngrams_op.cc#L184) 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.","provenance":"source","from":"CVE.org"},"cvss":{"score":5.5,"severity":"MEDIUM","version":"3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00152,"percentile":0.04441,"provenance":"source"},"cwes":[{"id":"CWE-681","name":"Incorrect Conversion between Numeric Types"}],"references":[{"url":"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-h6jh-7gv5-28vg","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5","tags":["x_refsource_MISC"]}],"priority":{"score":4.7,"factors":[{"name":"EPSS percentile","points":0.89},{"name":"CVSS severity","points":3.85}]},"vendorSlug":"tensorflow","affectedVersions":[{"vendor":"tensorflow","product":"tensorflow","versions":[">= 2.5.0, < 2.5.1",">= 2.4.0, < 2.4.3","< 2.3.4"]}],"affected":[{"ecosystem":"PyPI","package":"tensorflow","vulnerableRanges":["<2.3.4",">=2.4.0, <2.4.3",">=2.5.0, <2.5.1",">=2.3.0, <2.3.4"],"patched":["2.3.4","2.4.3","2.5.1"],"from":["GHSA-h6jh-7gv5-28vg","PYSEC-2021-268"],"provenance":"source"},{"ecosystem":"PyPI","package":"tensorflow-cpu","vulnerableRanges":["<2.3.4",">=2.4.0, <2.4.3",">=2.5.0, <2.5.1",">=2.3.0, <2.3.4"],"patched":["2.3.4","2.4.3","2.5.1"],"from":["GHSA-h6jh-7gv5-28vg","PYSEC-2021-559"],"provenance":"source"},{"ecosystem":"PyPI","package":"tensorflow-gpu","vulnerableRanges":["<2.3.4",">=2.4.0, <2.4.3",">=2.5.0, <2.5.1",">=2.3.0, <2.3.4"],"patched":["2.3.4","2.4.3","2.5.1"],"from":["GHSA-h6jh-7gv5-28vg","PYSEC-2021-757"],"provenance":"source"}],"summary":{"text":"An integer conversion flaw in the StringNGrams operation (tf.raw_ops.StringNGrams) of TensorFlow's string_ngrams kernel causes a signed value to be implicitly converted to an unsigned one before memory is allocated, so negative ngram_widths produce an oversized allocation request. An attacker with local access and low privileges who can supply negative ngram_widths to the operation can crash the process through memory exhaustion, with no user interaction or configuration changes required.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T22:20:38Z"},"euvd":{"id":"EUVD-2021-0372","exploited":false,"provenance":"source"},"lineage":{"familyId":"fam-tensorflow-cve-2020-15205","parents":[{"from":"CVE-2020-15205","to":"CVE-2021-37646","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/0462de5b544ed4731aa2fb23946ac22c01856b80","https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5"],"basis":"shared function","functions":["StringNGramsOp"]}]},{"from":"CVE-2021-29541","to":"CVE-2021-37646","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b","https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5"],"basis":"shared function","functions":["StringNGramsOp"]}]},{"from":"CVE-2021-29542","to":"CVE-2021-37646","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/ba424dd8f16f7110eea526a8086f1a155f14f22b","https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5"],"basis":"shared function","functions":["StringNGramsOp"]}]}],"children":[{"from":"CVE-2021-37646","to":"CVE-2022-21733","relation":"related","confidence":"medium","kind":"lineage","evidence":[{"kind":"same-code","provenance":"machine","files":["tensorflow/core/kernels/string_ngrams_op.cc"],"commits":["https://github.com/tensorflow/tensorflow/commit/c283e542a3f422420cfdb332414543b62fc4e4a5","https://github.com/tensorflow/tensorflow/commit/f68fdab93fb7f4ddb4eb438c8fe052753c9413e8"],"basis":"shared function","functions":["StringNGramsOp"]}]}]}}