{"id":"PYSEC-2026-3121","summary":"Out of bounds read in Tensorflow","details":"### Impact \nThe [implementation of shape inference for `ReverseSequence`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/ops/array_ops.cc#L1636-L1671) does not fully validate the value of `batch_dim` and can result in a heap OOB read:\n\n```python\nimport tensorflow as tf\n\n@tf.function\ndef test():\n  y = tf.raw_ops.ReverseSequence(\n    input = ['aaa','bbb'],\n    seq_lengths = [1,1,1],\n    seq_dim = -10,\n    batch_dim = -10 )\n  return y\n    \ntest()\n```\n\nThere is a check to make sure the value of `batch_dim` does not go over the rank of the input, but there is no check for negative values:\n\n```cc\n  const int32_t input_rank = c-\u003eRank(input);\n  if (batch_dim \u003e= input_rank) {\n    return errors::InvalidArgument( \n        \"batch_dim must be \u003c input rank: \", batch_dim, \" vs. \", input_rank);\n  }\n  // ...\n  \n  DimensionHandle batch_dim_dim = c-\u003eDim(input, batch_dim);\n``` \n    \nNegative dimensions are allowed in some cases to mimic Python's negative indexing (i.e., indexing from the end of the array), however if the value is too negative then [the implementation of `Dim`](https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.h#L415-L428) would access elements before the start of an array:\n\n```cc\n  DimensionHandle Dim(ShapeHandle s, int64_t idx) {\n    if (!s.Handle() || s-\u003erank_ == kUnknownRank) {\n      return UnknownDim();\n    }\n    return DimKnownRank(s, idx);\n  } \n·\n  static DimensionHandle DimKnownRank(ShapeHandle s, int64_t idx) {\n    CHECK_NE(s-\u003erank_, kUnknownRank);\n    if (idx \u003c 0) {\n      return s-\u003edims_[s-\u003edims_.size() + idx];\n    }\n    return s-\u003edims_[idx];\n  }\n```\n\n### Patches\nWe have patched the issue in GitHub commit [37c01fb5e25c3d80213060460196406c43d31995](https://github.com/tensorflow/tensorflow/commit/37c01fb5e25c3d80213060460196406c43d31995).\n\nThe fix will be included in TensorFlow 2.8.0. We will also cherrypick this commit on TensorFlow 2.7.1, TensorFlow 2.6.3, and TensorFlow 2.5.3, as these are also affected and still in supported range.\n\n### For more information\nPlease consult [our security guide](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) for more information regarding the security model and how to contact us with issues and questions.\n\n### Attribution\nThis vulnerability has been reported by Yu Tian of Qihoo 360 AIVul Team.","aliases":["BIT-tensorflow-2022-21728","CVE-2022-21728","GHSA-6gmv-pjp9-p8w8","PYSEC-2022-107","PYSEC-2022-52"],"modified":"2026-07-13T16:43:13.231725269Z","published":"2026-07-09T16:49:39.105064Z","references":[{"type":"WEB","url":"https://github.com/tensorflow/tensorflow/security/advisories/GHSA-6gmv-pjp9-p8w8"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-21728"},{"type":"WEB","url":"https://github.com/tensorflow/tensorflow/commit/37c01fb5e25c3d80213060460196406c43d31995"},{"type":"WEB","url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2022-52.yaml"},{"type":"WEB","url":"https://github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2022-107.yaml"},{"type":"WEB","url":"https://github.com/tensorflow/tensorflow"},{"type":"WEB","url":"https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/framework/shape_inference.h#L415-L428"},{"type":"WEB","url":"https://github.com/tensorflow/tensorflow/blob/5100e359aef5c8021f2e71c7b986420b85ce7b3d/tensorflow/core/ops/array_ops.cc#L1636-L1671"},{"type":"PACKAGE","url":"https://pypi.org/project/tensorflow"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-6gmv-pjp9-p8w8"}],"affected":[{"package":{"name":"tensorflow","ecosystem":"PyPI","purl":"pkg:pypi/tensorflow"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"2.5.3"},{"introduced":"2.6.0"},{"fixed":"2.6.3"},{"introduced":"2.7.0"},{"fixed":"2.7.1"}]}],"versions":["0.12.0","0.12.1","1.0.0","1.0.1","1.1.0","1.10.0","1.10.1","1.11.0","1.12.0","1.12.2","1.12.3","1.13.1","1.13.2","1.14.0","1.15.0","1.15.2","1.15.3","1.15.4","1.15.5","1.2.0","1.2.1","1.3.0","1.4.0","1.4.1","1.5.0","1.5.1","1.6.0","1.7.0","1.7.1","1.8.0","1.9.0","2.0.0","2.0.1","2.0.2","2.0.3","2.0.4","2.1.0","2.1.1","2.1.2","2.1.3","2.1.4","2.2.0","2.2.1","2.2.2","2.2.3","2.3.0","2.3.1","2.3.2","2.3.3","2.3.4","2.4.0","2.4.1","2.4.2","2.4.3","2.4.4","2.5.0","2.5.1","2.5.2","2.6.0","2.6.1","2.6.2","2.7.0"],"database_specific":{"source":"https://github.com/pypa/advisory-database/blob/main/vulns/tensorflow/PYSEC-2026-3121.yaml"}}],"schema_version":"1.7.5","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:H"},{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:H/SC:N/SI:N/SA:N"}]}