VYPR
High severityNVD Advisory· Published Aug 12, 2021· Updated Aug 4, 2024

Null pointer dereference in `CompressElement` in TensorFlow

CVE-2021-37637

Description

TensorFlow is an end-to-end open source platform for machine learning. It is possible to trigger a null pointer dereference in TensorFlow by passing an invalid input to tf.raw_ops.CompressElement. The implementation was accessing the size of a buffer obtained from the return of a separate function call before validating that said buffer is valid. We have patched the issue in GitHub commit 5dc7f6981fdaf74c8c5be41f393df705841fb7c5. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.3.42.3.4
tensorflowPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflowPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-cpuPyPI
< 2.3.42.3.4
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-gpuPyPI
< 2.3.42.3.4
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.12.5.1

Affected products

1

Patches

1
5dc7f6981fda

Fix accessing possible nullptr in tensorflow::data::CompressElement and UncompressElement which are used in tf.data.service.

https://github.com/tensorflow/tensorflowA. Unique TensorFlowerMay 15, 2021via ghsa
1 file changed · +15 7
  • tensorflow/core/data/compression_utils.cc+15 7 modified
    @@ -29,9 +29,10 @@ Status CompressElement(const std::vector<Tensor>& element,
       int64 total_size = 0;
       for (auto& component : element) {
         if (DataTypeCanUseMemcpy(component.dtype())) {
    -      // Some datatypes can be memcopied, allowing us to save two copies
    -      // (AsProtoTensorContent and SerializeToArray).
    -      total_size += DMAHelper::buffer(&component)->size();
    +      const TensorBuffer* buffer = DMAHelper::buffer(&component);
    +      if (buffer) {
    +        total_size += buffer->size();
    +      }
         } else {
           non_memcpy_components.emplace_back();
           component.AsProtoTensorContent(&non_memcpy_components.back());
    @@ -53,8 +54,10 @@ Status CompressElement(const std::vector<Tensor>& element,
         component.shape().AsProto(metadata->mutable_tensor_shape());
         if (DataTypeCanUseMemcpy(component.dtype())) {
           const TensorBuffer* buffer = DMAHelper::buffer(&component);
    -      memcpy(position, buffer->data(), buffer->size());
    -      metadata->set_tensor_size_bytes(buffer->size());
    +      if (buffer) {
    +        memcpy(position, buffer->data(), buffer->size());
    +        metadata->set_tensor_size_bytes(buffer->size());
    +      }
         } else {
           TensorProto& proto = non_memcpy_components[non_memcpy_component_index++];
           proto.SerializeToArray(position, proto.ByteSizeLong());
    @@ -94,8 +97,13 @@ Status UncompressElement(const CompressedElement& compressed,
         if (DataTypeCanUseMemcpy(metadata.dtype())) {
           out->emplace_back(metadata.dtype(), metadata.tensor_shape());
           TensorBuffer* buffer = DMAHelper::buffer(&out->back());
    -      iov[i].iov_base = buffer->data();
    -      iov[i].iov_len = buffer->size();
    +      if (buffer) {
    +        iov[i].iov_base = buffer->data();
    +        iov[i].iov_len = buffer->size();
    +      } else {
    +        iov[i].iov_base = nullptr;
    +        iov[i].iov_len = 0;
    +      }
         } else {
           // Allocate an empty Tensor. We will fill it out later after
           // uncompressing into the tensor_proto_str.
    

Vulnerability mechanics

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

References

7

News mentions

0

No linked articles in our index yet.