Security advisory
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` (i.e., `std::vector>`(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.
- Products
- Not specified
- Affected versions
- Not specified
- Fixed versions
- Not specified
- CVEs
- CVE-2021-29521
- Confirmed fixed CVEs
- Not specified
- Updated in this feed
- 31 Oct 2026, 12:43 UTC · Revision 1
Source evidence
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` (i.e., `std::vector>`(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.
osv:CVE-2021-29521
Complete source record
{
"id": "c1f7784c43586fa9932339f40c434616a492db1eef171296e8da242c7e96a435",
"url": "https://osv.dev/vulnerability/CVE-2021-29521",
"method": "structured",
"payload": {
"kind": "advisory",
"title": "CVE-2021-29521",
"summary": "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` (i.e., `std::vector>`(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.",
"evidence": "osv:CVE-2021-29521",
"products": [],
"severity": "medium",
"structured": {
"id": "CVE-2021-29521",
"aliases": [
"BIT-tensorflow-2021-29521",
"CVE-2021-29521",
"GHSA-hr84-fqvp-48mm",
"PYSEC-2021-158",
"PYSEC-2021-449",
"PYSEC-2021-647"
],
"metrics": [
{
"type": "CVSS_V3",
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H"
}
],
"affected": [
{
"ranges": [
{
"repo": "https://github.com/tensorflow/tensorflow",
"type": "GIT",
"events": [
{
"introduced": "b36436b087bd8e8701ef51718179037cccdfc26e"
},
{
"fixed": "3929ffacfbef7c431e8397920d040aaf47acff19"
},
{
"introduced": "582c8d236cb079023657287c318ff26adb239002"
},
{
"fixed": "1923123d32ea41d92b70a27a3f6ecf0763b56f6c"
},
{
"fixed": "c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5"
}
],
"database_specific": {
"extracted_events": [
{
"cpe": "cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:*",
"range": [
{
"introduced": "2.3.0"
},
{
"fixed": "2.3.3"
}
],
"source": "CPE_RANGE"
},
{
"cpe": "cpe:2.3:a:google:tensorflow:*:*:*:*:*:*:*:*",
"range": [
{
"introduced": "2.4.0"
},
{
"fixed": "2.4.2"
}
],
"source": "CPE_RANGE"
},
{
"range": [
{
"fixed": "c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5"
}
],
"source": "REFERENCES_COMMIT"
}
]
}
}
],
"versions": [
"v2.3.2",
"v2.4.1",
"v2.4.0",
"v2.3.1",
"v2.3.0"
],
"database_specific": {
"source": "https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2021-29521.json",
"vanir_signatures": [
{
"id": "CVE-2021-29521-f54e40af",
"digest": {
"threshold": 0.9,
"line_hashes": [
"313716304609630462537964321808569552996",
"294046419860844613296446090524561231385",
"199803823294206664962489038162650178464",
"325396247946547538862276611245534536283",
"52002578415741612972900352450237940675"
]
},
"source": "https://github.com/tensorflow/tensorflow/commit/c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5",
"target": {
"file": "tensorflow/core/kernels/count_ops.cc"
},
"deprecated": false,
"signature_type": "Line",
"signature_version": "v1"
}
],
"vanir_signatures_modified": "2026-10-20T14:20:37Z"
}
}
],
"modified": "2026-10-20T14:20:37.550215575Z",
"provider": "osv",
"references": [
"https://github.com/tensorflow/tensorflow/commit/c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5",
"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-hr84-fqvp-48mm"
],
"provider_metadata": {}
},
"related_cves": [
{
"value": "CVE-2021-29521",
"evidence": "/id"
}
],
"security_relevant": true,
"severity_evidence": "/severity/0/score"
},
"source_id": "core-osv",
"document_id": 388826,
"published_at": "2021-05-14T20:15:11.567+00:00"
}