hitoshura25/cvefixes huggingface dataset:
CVE-2021-41197 (Python, published 2021-11-05T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions TensorFlow allows tensor to have a large number of dimensions and each dimension can be as large as desired. However, the total number of elements in a tensor must fit within an `int64_t`. If an overflow occurs, `MultiplyWithoutOverflow` would return a negative result. In the majority of TensorFlow codebase this then results in a `CHECK`-failure. Newer constructs exist which return a `Status` instead of crashing the binary. This is similar to CVE-2021-29584. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/python/ops/image_ops_test.py
Commit message: Merge pull request #51717 from yongtang:46890-tf.image.pad_to_bounding_box

PiperOrigin-RevId: 398351034
Change-Id: Ia11abe3ab57683ca2efea786fd095338d0c8c3b7


Vulnerable code:

Fixed code:
   def testInvalidInput(self):
     # Test case for GitHub issue 46890.
+    if test_util.is_xla_enabled():
+      # TODO(b/200850176): test fails with XLA.
+      return
     with self.session():
       with self.assertRaises(errors_impl.InternalError):
         v = image_ops.pad_to_bounding_box(
             image=np.ones((1, 1, 1)),
             target_height=5191549470,
             target_width=5191549470,
+            offset_height=1,
+            offset_width=1)
         self.evaluate(v)
CVE-2021-41198 (Python, published 2021-11-05T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions if `tf.tile` is called with a large input argument then the TensorFlow process will crash due to a `CHECK`-failure caused by an overflow. The number of elements in the output tensor is too much for the `int64_t` type and the overflow is detected via a `CHECK` statement. This aborts the process. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/tile_ops.cc
tensorflow/python/kernel_tests/shape_ops_test.py
Commit message: Merge pull request #51138 from yongtang:46911-tile

PiperOrigin-RevId: 397891537
Change-Id: I9b12304000e80dd87e6d4a42614ab10383a967b0


Vulnerable code:
       output_shape.AddDim(input.dim_size(i) * multiples_array[i]);

Fixed code:
+      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(
+                                  input.dim_size(i) * multiples_array[i]));
   def testLargeTensor(self):
     # Test case for GItHub issue 46911.
+    if test_util.is_xla_enabled():
+      # The following test fails with XLA enabled.
+      return
     with self.assertRaises(errors_impl.InternalError):
       with self.cached_session():
         tiled = array_ops.tile(
             np.ones((1, 1, 1)), [100000000, 100000000, 100000000])
+        self.evaluate(tiled)
CVE-2021-41199 (Python, published 2021-11-05T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions if `tf.image.resize` is called with a large input argument then the TensorFlow process will crash due to a `CHECK`-failure caused by an overflow. The number of elements in the output tensor is too much for the `int64_t` type and the overflow is detected via a `CHECK` statement. This aborts the process. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/util/image_resizer_state.h
tensorflow/python/ops/image_ops_test.py
Commit message: Merge pull request #51497 from yongtang:46914-image.resize

PiperOrigin-RevId: 391409572
Change-Id: I027c4901c9717ae7ee8266e5f57baba950b3e1e3


Vulnerable code:
     OP_REQUIRES_OK(
         context,
         context->allocate_output(
             0, TensorShape({batch_size, out_height, out_width, channels}),
             &output));

Fixed code:
 
     TensorShape shape;
     // Guard against shape overflow
     OP_REQUIRES_OK(context, shape.AddDimWithStatus(batch_size));
     OP_REQUIRES_OK(context, shape.AddDimWithStatus(out_height));
     OP_REQUIRES_OK(context, shape.AddDimWithStatus(out_width));
     OP_REQUIRES_OK(context, shape.AddDimWithStatus(channels));
 
+    OP_REQUIRES_OK(context, context->allocate_output(0, shape, &output));
   def testLargeDim(self):
     with self.session():
       with self.assertRaises(errors.InternalError):
         x = np.ones((5, 1, 1, 2))
+        v = image_ops.resize_images_v2(x, [1610637938, 1610637938],
+                                       image_ops.ResizeMethod.BILINEAR)
         _ = self.evaluate(v)
CVE-2021-41200 (Python, published 2021-11-05T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions if `tf.summary.create_file_writer` is called with non-scalar arguments code crashes due to a `CHECK`-fail. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-617 \u2014 Reachable Assertion
The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/python/summary/writer/writer_test.py
Commit message: Merge pull request #51715 from yongtang:46909-tf.summary.create_file_writer

PiperOrigin-RevId: 394109960
Change-Id: I444e59a7f90acd6487832d74b677093403c8a083


Vulnerable code:

Fixed code:
   def testSummaryFileWritersInvalidInput(self):
     # Test case for GitHub issue 46909
     logdir = self.get_temp_dir()
     with session.Session() as sess:
       with self.assertRaises(errors_impl.InvalidArgumentError):
         writer = summary_ops_v2.create_file_writer(
             logdir=logdir, flush_millis=[1, 2])
         sess.run(writer.init())
         sess.run(writer.flush())
CVE-2021-41201 (C, published 2021-11-05T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affeced versions during execution, `EinsumHelper::ParseEquation()` is supposed to set the flags in `input_has_ellipsis` vector and `*output_has_ellipsis` boolean to indicate whether there is ellipsis in the corresponding inputs and output. However, the code only changes these flags to `true` and never assigns `false`. This results in unitialized variable access if callers assume that `EinsumHelper::ParseEquation()` always sets these flags. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: MEDIUM (CVSS v3 base score: 7.8)
Weakness: CWE-824 \u2014 Access of Uninitialized Pointer
The product accesses or uses a pointer that has not been initialized.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/linalg/einsum_op_impl.h
Commit message: Fix EinsumHelper::ParseEquation to avoid uninitialized accesses.

EinsumHelper::ParseEquation is supposed to return true or false in
input_has_ellipsis and output_has_ellipsis to indicate whether there is
ellipsis in the inputs and output. Previously, when there is no ellipsis in the
inputs or output, the routine doesn't assign false to the variables. This
change initializes the two variables with false to fix the problem.
PiperOrigin-RevId: 391772004
Change-Id: I17b6c88aadef4131470378e48cced054bf252e86


Vulnerable code:

Fixed code:
      input_has_ellipsis->at(i) = false;
    *output_has_ellipsis = false;
CVE-2021-41202 (C++, published 2021-11-05T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions while calculating the size of the output within the `tf.range` kernel, there is a conditional statement of type `int64 = condition ? int64 : double`. Due to C++ implicit conversion rules, both branches of the condition will be cast to `double` and the result would be truncated before the assignment. This result in overflows. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-681 \u2014 Incorrect Conversion between Numeric Types
When converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/sequence_ops.cc
Commit message: Merge pull request #51711 from yongtang:46899-tf.range

PiperOrigin-RevId: 393844345
Change-Id: I2a72193d4416b8b009bc0b21489a42061f164203


Vulnerable code:
-    OP_REQUIRES_OK(context,
                    context->allocate_output(0, TensorShape({size}), &out));

Fixed code:
     TensorShape shape;
     OP_REQUIRES_OK(context, shape.AddDimWithStatus(size));
+    OP_REQUIRES_OK(context, context->allocate_output(0, shape, &out));
CVE-2021-41202 (C++, published 2021-11-05T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions while calculating the size of the output within the `tf.range` kernel, there is a conditional statement of type `int64 = condition ? int64 : double`. Due to C++ implicit conversion rules, both branches of the condition will be cast to `double` and the result would be truncated before the assignment. This result in overflows. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-681 \u2014 Incorrect Conversion between Numeric Types
When converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/sequence_ops.cc
Commit message: Merge pull request #51359 from yongtang:46913-range-overflow

PiperOrigin-RevId: 391529518
Change-Id: Ie3db4ae6d3c0f3dc88404e1dbdc22f7d03cbeb3b


Vulnerable code:
     int64_t size = (std::is_integral<T>::value
                         ? ((std::abs(limit - start) + std::abs(delta) - 1) /
                            std::abs(delta))
                         : std::ceil(std::abs((limit - start) / delta)));

Fixed code:
     int64_t size = 0;
     if (std::is_integral<T>::value) {
       size = static_cast<int64>(
+          (std::abs(limit - start) + std::abs(delta) - 1) / std::abs(delta));
     } else {
+      size = static_cast<int64>(std::ceil(std::abs((limit - start) / delta)));
     }
CVE-2021-41203 (C++, published 2021-11-05T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions an attacker can trigger undefined behavior, integer overflows, segfaults and `CHECK`-fail crashes if they can change saved checkpoints from outside of TensorFlow. This is because the checkpoints loading infrastructure is missing validation for invalid file formats. The fixes will be included in TensorFlow 2.7.0. We will also cherrypick these commits on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: MEDIUM (CVSS v3 base score: 7.8)
Weakness: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/util/tensor_slice_reader.cc
tensorflow/core/util/tensor_slice_reader_test.cc
Commit message: Use BuildTensorShapeBase when parsing unverified TensorShapes during checkpoint loading.

This avoids crashing when the TensorShape has negative dimensions.

PiperOrigin-RevId: 392769882
Change-Id: Id1f7ae7fcf8142193556af47abfda81b13d3cce4


Vulnerable code:
    TensorShape ssm_shape(ssm.shape());

Fixed code:
    TensorShape ssm_shape;
    status_ = TensorShape::BuildTensorShapeBase(ssm.shape(), &ssm_shape);
    if (!status_.ok()) return;
#include "tensorflow/core/framework/tensor_shape.pb.h"
TEST(TensorSliceReaderTest, NegativeTensorShapeDimension) {
  const string fname =
      io::JoinPath(testing::TmpDir(), "negative_dim_checkpoint");
  TensorSliceWriter writer(fname, CreateTableTensorSliceBuilder);
  const int32 data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  TF_CHECK_OK(writer.Add("test", TensorShape({4, 5}),
                         TensorSlice::ParseOrDie("0,2:-"), data));
  TF_CHECK_OK(writer.Finish());

  MutateSavedTensorSlices(fname, [](SavedTensorSlices sts) {
    if (sts.has_meta()) {
      for (auto& tensor : *sts.mutable_meta()->mutable_tensor()) {
        for (auto& dim : *tensor.mutable_shape()->mutable_dim()) {
          dim.set_size(-dim.size());
        }
      }
    }
    return sts.SerializeAsString();
  });

  TensorSliceReader reader(fname, OpenTableTensorSliceReader);
  // The negative dimension should cause loading to fail.
  EXPECT_FALSE(reader.status().ok());
}
CVE-2021-41204 (C++, published 2021-11-05T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions during TensorFlow's Grappler optimizer phase, constant folding might attempt to deep copy a resource tensor. This results in a segfault, as these tensors are supposed to not change. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 5.5)
Weakness: CWE-824 \u2014 Access of Uninitialized Pointer
The product accesses or uses a pointer that has not been initialized.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/common_runtime/constant_folding.cc
Commit message: Don't constant-fold DT_RESOURCE constants.

PiperOrigin-RevId: 391803952
Change-Id: I0ea3ec31d3e7dfda0f03b4027a237f08d00a3091


Vulnerable code:
    return true;

Fixed code:
#include "tensorflow/core/framework/types.pb.h"
    // Skip constant folding resources as they cannot be deep copied.
    return n->output_type(0) != DT_RESOURCE;
CVE-2021-41205 (C++, published 2021-11-05T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions the shape inference functions for the `QuantizeAndDequantizeV*` operations can trigger a read outside of bounds of heap allocated array. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: LOW (CVSS v3 base score: 7.1)
Weakness: CWE-125 \u2014 Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/ops/array_ops.cc
tensorflow/core/ops/array_ops_test.cc
Commit message: Address QuantizeAndDequantizeV* heap oob. Added additional checks for the 'axis' attribute.

PiperOrigin-RevId: 402446942
Change-Id: Id2f6b82e4e740d0550329be02621c46466b5a5b9


Vulnerable code:
      if (axis != -1) {
      if (axis != -1) {
      if (axis != -1) {
      if (axis != -1) {

Fixed code:
      if (axis < -1) {
        return errors::InvalidArgument("axis should be at least -1, got ",
                                       axis);
      } else if (axis != -1) {
      if (axis < -1) {
        return errors::InvalidArgument("axis should be at least -1, got ",
                                       axis);
      } else if (axis != -1) {
      if (axis < -1) {
        return errors::InvalidArgument("axis should be at least -1, got ",
                                       axis);
      } else if (axis != -1) {
      if (axis < -1) {
        return errors::InvalidArgument("axis should be at least -1, got ",
                                       axis);
      } else if (axis != -1) {
  (*op.node_def.mutable_attr())["axis"].set_i(-2);
  INFER_ERROR("axis should be at least -1, got -2", op, "?;?;?");
CVE-2021-41206 (Python, published 2021-11-05T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions several TensorFlow operations are missing validation for the shapes of the tensor arguments involved in the call. Depending on the API, this can result in undefined behavior and segfault or `CHECK`-fail related crashes but in some scenarios writes and reads from heap populated arrays are also possible. We have discovered these issues internally via tooling while working on improving/testing GPU op determinism. As such, we don't have reproducers and there will be multiple fixes for these issues. These fixes will be included in TensorFlow 2.7.0. We will also cherrypick these commits on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: MEDIUM (CVSS v3 base score: 7.8)
Weakness: CWE-354 \u2014 Improper Validation of Integrity Check Value
The product does not validate or incorrectly validates the integrity check values or "checksums" of a message. This may prevent it from detecting if the data has been modified or corrupted in transmission.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/linalg/matrix_solve_op.cc
tensorflow/python/kernel_tests/matrix_solve_op_test.py
Commit message: Fix crash in MatrixSolve when inputs have different batch dimensions.

Before, the process would crash or certain elements would be silently ignored. Now an InvalidArgument is raised.

PiperOrigin-RevId: 384844020
Change-Id: Iba44417e383bdd0e1abc4012bfca83b2377dd335


Vulnerable code:
        errors::InvalidArgument("Input matrices must be squares, got",
                          "same number of rows, got",

Fixed code:
        errors::InvalidArgument("Input matrices must be squares, got ",
                          "same number of rows, got ",
    for (int dim = 0; dim < ndims - 2; dim++) {
      OP_REQUIRES_ASYNC(
          context, input.dim_size(dim) == rhs.dim_size(dim),
          errors::InvalidArgument(
              "All input tensors must have the same outer dimensions."),
          done);
    }
    # The matrix and right-hand side should have the same batch dimensions
    matrix = np.random.normal(size=(2, 6, 2, 2))
    rhs = np.random.normal(size=(2, 3, 2, 2))
    with self.assertRaises((ValueError, errors_impl.InvalidArgumentError)):
      self.evaluate(linalg_ops.matrix_solve(matrix, rhs))
CVE-2021-41206 (C++, published 2021-11-05T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In affected versions several TensorFlow operations are missing validation for the shapes of the tensor arguments involved in the call. Depending on the API, this can result in undefined behavior and segfault or `CHECK`-fail related crashes but in some scenarios writes and reads from heap populated arrays are also possible. We have discovered these issues internally via tooling while working on improving/testing GPU op determinism. As such, we don't have reproducers and there will be multiple fixes for these issues. These fixes will be included in TensorFlow 2.7.0. We will also cherrypick these commits on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
Severity: MEDIUM (CVSS v3 base score: 7.8)
Weakness: CWE-354 \u2014 Improper Validation of Integrity Check Value
The product does not validate or incorrectly validates the integrity check values or "checksums" of a message. This may prevent it from detecting if the data has been modified or corrupted in transmission.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/conv_ops.cc
Commit message: Fix segfault on OOM in Conv2D.

PiperOrigin-RevId: 404655317
Change-Id: I33588dbd3f5d0fef980e3c908bf5515a9ee09ce7


Vulnerable code:
    Tensor input_shuffled(input.dtype(), TensorShape(post_shuffle(input)));
    Tensor filter_shuffled(filter.dtype(), TensorShape(post_shuffle(filter)));
    Tensor output_shuffled(output->dtype(), TensorShape(post_shuffle(*output)));

Fixed code:
    Tensor input_shuffled;
    OP_REQUIRES_OK(
        ctx, ctx->allocate_temp(input.dtype(), TensorShape(post_shuffle(input)),
                                &input_shuffled));
    Tensor filter_shuffled;
    OP_REQUIRES_OK(ctx, ctx->allocate_temp(filter.dtype(),
                                           TensorShape(post_shuffle(filter)),
                                           &filter_shuffled));
    Tensor output_shuffled;
    OP_REQUIRES_OK(ctx, ctx->allocate_temp(output->dtype(),
                                           TensorShape(post_shuffle(*output)),
                                           &output_shuffled));