VYPR
Moderate severityNVD Advisory· Published Nov 18, 2022· Updated Apr 23, 2025

Invalid char to bool conversion when printing a tensor in Tensorflow

CVE-2022-41911

Description

TensorFlow is an open source platform for machine learning. When printing a tensor, we get it's data as a const char* array (since that's the underlying storage) and then we typecast it to the element type. However, conversions from char to bool are undefined if the char is not 0 or 1, so sanitizers/fuzzers will crash. The issue has been patched in GitHub commit 1be74370327. The fix will be included in TensorFlow 2.11.0. We will also cherrypick this commit on TensorFlow 2.10.1, TensorFlow 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

TensorFlow tensor printing uses an undefined char-to-bool conversion that can crash sanitizers and fuzzers.

Vulnerability

Overview When TensorFlow prints a tensor, it reads the underlying data as a const char* array and then typecasts it to the element type. For boolean tensors, this involves a conversion from char to bool. If the char value is not exactly 0 or 1, the conversion is undefined behavior, which can cause sanitizers and fuzzers to crash [1].

Exploitation and

Impact An attacker who can control the contents of a boolean tensor (e.g., by feeding crafted model inputs or using a malicious SavedModel) could trigger this undefined behavior during tensor printing. The crash is particularly relevant in testing and fuzzing environments, where sanitizers are commonly used to detect memory and type errors. The vulnerability does not require authentication beyond the ability to run TensorFlow operations that print a tensor [1][3].

Mitigation

The issue was patched in GitHub commit 1be74370327, which introduces a specialized SummarizeArray template that forces all char values to 0 or 1 before conversion [4]. The fix is included in TensorFlow 2.11.0 and has been cherry-picked to versions 2.10.1, 2.9.3, and 2.8.4 [1]. Users are advised to update to the latest patched versions of TensorFlow.

AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.8.42.8.4
tensorflow-cpuPyPI
>= 2.9.0, < 2.9.32.9.3
tensorflow-gpuPyPI
>= 2.10.0, < 2.10.12.10.1
tensorflowPyPI
>= 2.9.0, < 2.9.32.9.3
tensorflowPyPI
>= 2.10.0, < 2.10.12.10.1
tensorflow-cpuPyPI
< 2.8.42.8.4
tensorflow-gpuPyPI
< 2.8.42.8.4
tensorflow-gpuPyPI
>= 2.9.0, < 2.9.32.9.3
tensorflow-cpuPyPI
>= 2.10.0, < 2.10.12.10.1

Affected products

5

Patches

1
1be743703279

Resolve a sanitizer issue with invalid char -> bool conversion.

https://github.com/tensorflow/tensorflowMihai MaruseacOct 19, 2022via ghsa
1 file changed · +27 5
  • tensorflow/core/framework/tensor.cc+27 5 modified
    @@ -29,6 +29,7 @@ limitations under the License.
     
     #include "tensorflow/core/framework/tensor.h"
     
    +#include <memory>
     #include <utility>
     
     #include "absl/strings/escaping.h"
    @@ -1183,12 +1184,10 @@ void PrintOneDimV2(int dim_index, const gtl::InlinedVector<int64, 4>& shape,
     }
     
     template <typename T>
    -string SummarizeArray(int64_t limit, int64_t num_elts,
    -                      const TensorShape& tensor_shape, const char* data,
    -                      const bool print_v2) {
    +string SummarizeArrayInternal(int64_t limit, int64_t num_elts,
    +                              const TensorShape& tensor_shape, const T* array,
    +                              const bool print_v2) {
       string ret;
    -  const T* array = reinterpret_cast<const T*>(data);
    -
       const gtl::InlinedVector<int64_t, 4> shape = tensor_shape.dim_sizes();
       if (shape.empty()) {
         for (int64_t i = 0; i < limit; ++i) {
    @@ -1211,6 +1210,29 @@ string SummarizeArray(int64_t limit, int64_t num_elts,
     
       return ret;
     }
    +
    +template <typename T>
    +string SummarizeArray(int64_t limit, int64_t num_elts,
    +                      const TensorShape& tensor_shape, const char* data,
    +                      const bool print_v2) {
    +  const T* array = reinterpret_cast<const T*>(data);
    +  return SummarizeArrayInternal<T>(limit, num_elts, tensor_shape, array,
    +                                   print_v2);
    +}
    +
    +template <>
    +string SummarizeArray<bool>(int64_t limit, int64_t num_elts,
    +                            const TensorShape& tensor_shape, const char* data,
    +                            const bool print_v2) {
    +  // We first convert all chars to be 0/1 to not get InvalidEnumValue sanitizer
    +  // error
    +  auto mutable_data = std::unique_ptr<char[]>(new char[num_elts]);
    +  for (int64_t i = 0; i < num_elts; ++i)
    +    mutable_data.get()[i] = data[i] ? 1 : 0;
    +  bool* array = reinterpret_cast<bool*>(mutable_data.get());
    +  return SummarizeArrayInternal<bool>(limit, num_elts, tensor_shape, array,
    +                                      print_v2);
    +}
     }  // namespace
     
     string Tensor::SummarizeValue(int64_t max_entries, bool print_v2) const {
    

Vulnerability mechanics

Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.