CVE-2021-29581: Segfault in CTCBeamSearchDecoder in TensorFlow
Summary
CVE-2021-29581: Segfault in CTCBeamSearchDecoder. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29581 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
TensorFlow is an open-source machine learning framework widely used for various applications. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. The CTCBeamSearchDecoder is a component in TensorFlow that performs beam search decoding for Connectionist Temporal Classification (CTC) models. It is used for tasks such as speech recognition and handwriting recognition.
Vulnerability Detail
The CTCBeamSearchDecoder in TensorFlow is vulnerable to a segmentation fault caused by a lack of validation in the tf.raw_ops.CTCBeamSearchDecoder function. This vulnerability allows an attacker to trigger a denial of service (DoS) attack by providing an empty input tensor, which leads to the function attempting to read data from a null buffer. This can result in a segmentation fault and crash the application. The impact of this vulnerability is limited to DoS attacks and does not allow for arbitrary code execution or data exfiltration.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow==2.21.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.1.42.1.4pip install --upgrade "tensorflow==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow==2.4.2"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a workaround, users can add input validation to their code before calling the CTCBeamSearchDecoder function. This can be done by checking if the input tensor is empty and handling this case appropriately to avoid triggering the vulnerability. Here is an example of how to add input validation:
import tensorflow as tf
inputs = tf.constant([], shape=[18, 8, 0], dtype=tf.float32)
sequence_length = tf.constant([11, -43, -92, 11, -89, -83, -35, -100], shape=[8], dtype=tf.int32)
beam_width = 10
top_paths = 3
merge_repeated = True
if inputs.shape[2] == 0:
# Handle empty input tensor
print('Input tensor is empty')
else:
tf.raw_ops.CTCBeamSearchDecoder(
inputs=inputs, sequence_length=sequence_length, beam_width=beam_width,
top_paths=top_paths, merge_repeated=merge_repeated)
Conclusion
The vulnerability in the CTCBeamSearchDecoder component of TensorFlow allows for a denial of service attack through a segmentation fault. It has been patched in TensorFlow versions 2.5.0, 2.4.2, 2.3.3, 2.2.3, and 2.1.4. Users are advised to upgrade to one of these patched versions to mitigate the risk. If immediate upgrading is not possible, adding input validation to the code can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The vulnerability allows an attacker to trigger a denial of service (DoS) attack by providing an empty input tensor, which leads to a segmentation fault and crashes the application. However, it does not allow for arbitrary code execution or data exfiltration.
The vulnerability affects TensorFlow versions 2.1.4 and earlier, 2.2.3 and earlier, 2.3.3 and earlier, and 2.4.2 and earlier. Users of these versions should upgrade to the patched versions mentioned in the 'How to Fix' section.
Yes, users can add input validation to their code to check if the input tensor is empty before calling the vulnerable function. This can help avoid triggering the vulnerability. Refer to the 'Workaround' section for an example.
Yes, the vulnerability has been patched in TensorFlow versions 2.5.0, 2.4.2, 2.3.3, 2.2.3, and 2.1.4. Users should update their TensorFlow installation to one of these patched versions to address the vulnerability.
For more information, please refer to the TensorFlow security guide at https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md. If you have further questions or need assistance, you can contact the TensorFlow team.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.