hitoshura25/cvefixes huggingface dataset:
CVE-2022-35994 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `CollectiveGather` receives an scalar input `input`, it gives a `CHECK` fails that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit c1f491817dec39a26be3c574e86a88c30f3c4770. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/collective_ops.cc
tensorflow/python/ops/collective_ops_test.py
Commit message: Fix for check failure in CollectiveGather op.

The fix is required only for Eager mode, graph mode already checked for input shape in shape inference pass.

PiperOrigin-RevId: 460801136


Vulnerable code:

Fixed code:
    OP_REQUIRES_ASYNC(c, output_shape.dims() > 0,
                      errors::InvalidArgument("input should have rank > 0, ",
                                              "recieved ", output_shape.dims()),
                      done);
  @test_util.run_v2_only
  def testCollectiveGatherShapeCheckFailure(self):
    with self.assertRaisesRegex(errors.InvalidArgumentError,
                                'input should have rank > 0'):
      collective_ops.gen_collective_ops.CollectiveGather(
          input=1,
          group_size=1,
          group_key=1,
          instance_key=1,
          shape=(3, 3, 3),
          communication_hint='auto',
          timeout_seconds=0,
          name='')
CVE-2022-35995 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `AudioSummaryV2` receives an input `sample_rate` with more than one element, it gives a `CHECK` fails that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit bf6b45244992e2ee543c258e519489659c99fb7f. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/summary_audio_op.cc
tensorflow/python/summary/summary_test.py
Commit message: Fix tf.raw_ops.AudioSummaryV2 vulnerability with invalid `sample_rate`.

Check that `sample_rate` has the required shape.

PiperOrigin-RevId: 460819553


Vulnerable code:

Fixed code:
      OP_REQUIRES(c,
                  sample_rate_tensor.IsAligned() &&
                      sample_rate_tensor.NumElements() == 1,
                  errors::InvalidArgument(
                      "sample_rate must be rank-0 or contain a single value"));
from tensorflow.python.framework import errors
  def testAudioSummaryWithInvalidSampleRate(self):
    with self.assertRaises(errors.InvalidArgumentError):
      invalid_sample_rate = [22000.0, 22000.0]
      self.evaluate(summary_lib.audio('', [[1.0]], invalid_sample_rate))
CVE-2022-35996 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `Conv2D` is given empty `input` and the `filter` and `padding` sizes are valid, the output is all-zeros. This causes division-by-zero floating point exceptions that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 611d80db29dd7b0cfb755772c69d60ae5bca05f9. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-369 \u2014 Divide By Zero
The product divides a value by zero.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/conv_ops.cc
tensorflow/python/kernel_tests/nn_ops/conv_ops_test.py
Commit message: Fix conv2d crash when input size is empty.

If the input is empty (so convolution is only applied to padding), and if
the filter and padding sizes are still valid, then the output will be
all-zeros.  This previously caused a division-by-zero crash in multiple
kernels.

PiperOrigin-RevId: 463179650


Vulnerable code:

Fixed code:
#include "tensorflow/core/kernels/fill_functor.h"
    // If the input is empty, result can only be due to padding.
    if (input.NumElements() == 0) {
      // Zero-out output and return.
      functor::SetZeroFunctor<Device, T>()(context->eigen_device<Device>(),
                                           output->template flat<T>());

      return;
    }

  @test_util.run_in_graph_and_eager_modes()
  def testConv2dOnlyPaddingReturnsZeros(self):
    self._VerifyValues(
        tensor_in_sizes=[1, 0, 2, 1],
        filter_in_sizes=[1, 1, 1, 1],
        strides=[1, 1],
        padding=[[1, 1], [1, 1]],
        expected=[0, 0, 0, 0, 0, 0, 0, 0])
CVE-2022-35997 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `tf.sparse.cross` receives an input `separator` that is not a scalar, it gives a `CHECK` fail that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 83dcb4dbfa094e33db084e97c4d0531a559e0ebf. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/sparse_cross_op.cc
tensorflow/python/kernel_tests/sparse_ops/sparse_cross_op_test.py
Commit message: Fix check failure in SparseCrossV2Op by adding check for scalar value for separator.

PiperOrigin-RevId: 461001180


Vulnerable code:

Fixed code:
#include "tensorflow/core/framework/op_requires.h"
#include "tensorflow/core/platform/errors.h"
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(sep_t->shape()),
                errors::InvalidArgument("Input separator should be a scalar. "
                                        "Received: ",
                                        sep_t->DebugString()));
  def testNonScalarInput(self):
    with self.assertRaisesRegex(errors.InvalidArgumentError,
                                'Input separator should be a scalar.'):
      self.evaluate(sparse_ops.sparse_cross(
          inputs=[],
          name='a',
          separator=constant_op.constant(['a', 'b'], dtype=dtypes.string)))
CVE-2022-35998 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `EmptyTensorList` receives an input `element_shape` with more than one dimension, it gives a `CHECK` fail that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit c8ba76d48567aed347508e0552a257641931024d. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/list_kernels.cc
tensorflow/python/kernel_tests/data_structures/list_ops_test.py
Commit message: Fix tf.raw_ops.EmptyTensorList vulnerability with invalid `element_shape`.

Check that given `element_shape` is valid.
Add graph/eager unit tests. Graph mode was already ok but eager mode was not.

PiperOrigin-RevId: 461906461


Vulnerable code:
#include "tensorflow/core/kernels/concat_lib.h"
#include "tensorflow/core/lib/core/coding.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/util/util.h"

Fixed code:
#include <algorithm>
#include <iterator>
#include <memory>
#include <utility>
  } else if (t.shape().dims() != 1) {
    return errors::InvalidArgument("Shape must be at most rank 1 but is rank ",
                                   t.shape().dims());
  def testEmptyTensorListInvalidShape(self):
    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                r"Shape must be at most rank 1 but is rank 2"):
      t = gen_list_ops.EmptyTensorList(
          element_shape=array_ops.ones(dtype=dtypes.int32, shape=[1, 0]),
          max_num_elements=constant_op.constant(1),
          element_dtype=dtypes.int32)
      self.evaluate(t)
CVE-2022-35999 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `Conv2DBackpropInput` receives empty `out_backprop` inputs (e.g. `[3, 1, 0, 1]`), the current CPU/GPU kernels `CHECK` fail (one with dnnl, the other with cudnn). This can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 27a65a43cf763897fecfa5cdb5cc653fc5dd0346. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/conv_grad_input_ops.h
tensorflow/python/kernel_tests/nn_ops/conv_ops_test.py
Commit message: Fix GPU/CPU Conv2DBackpropInputOp check error.

For empty `out_backprop` inputs (e.g. `[3, 1, 0, 1]`), the current
CPU/GPU kernels fail (one with dnnl, the other with cudnn). Added
a shortcut path to return a zero input.

Note that the XLA test currently fails due to an incorrect result
size bug (b/239598470), so it is currently disabled.

PiperOrigin-RevId: 462217998


Vulnerable code:

Fixed code:
#include "tensorflow/core/kernels/fill_functor.h"
    // If shapes are valid but `out_backprop` is empty, in_backprop should be
    // set to all zeros.  Otherwise, cudnn/dnnl fail with an empty input.
    if (out_backprop.NumElements() == 0) {
      functor::SetZeroFunctor<Device, T> set_zero;
      set_zero(context->eigen_device<Device>(),
               in_backprop->template flat<T>());
      return;
    }

    // If shapes are valid but `out_backprop` is empty, in_backprop should be
    // set to all zeros.  Otherwise, cudnn/dnnl fail with an empty input.
    if (out_backprop.NumElements() == 0) {
      functor::SetZeroFunctor<Device, T> set_zero;
      set_zero(context->eigen_device<Device>(),
               in_backprop->template flat<T>());
      return;
    }

  @test_util.run_in_graph_and_eager_modes
  @test_util.disable_xla("b/239598470")
  def testConv2DBackpropInputDegenerateBackpropInput(self):
    input_sizes = [3, 1, 1, 2]
    expected_output = np.zeros(input_sizes).flatten()
    for (data_format, use_gpu) in GetTestConfigs():
      self._RunAndVerifyBackpropInput(
          input_sizes=input_sizes,
          filter_sizes=[1, 3, 2, 3],
          output_sizes=[3, 1, 0, 3],
          strides=[1, 2],
          padding="VALID",
          expected=expected_output,
          data_format=data_format,
          use_gpu=use_gpu,
          err=1e-5)
CVE-2022-36000 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `mlir::tfg::ConvertGenericFunctionToFunctionDef` is given empty function attributes, it gives a null dereference. We have patched the issue in GitHub commit aed36912609fc07229b4d0a7b44f3f48efc00fd0. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-476 \u2014 NULL Pointer Dereference
The product dereferences a pointer that it expects to be valid but is NULL.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/linalg/linalg_ops_common.cc
tensorflow/python/kernel_tests/linalg/eig_op_test.py
Commit message: Check correct input/output scalar types for LinearAlgebraOp.

If calling the `tf.raw_ops` versions, it's possible to provide bad output scalar
types (e.g. for `Eig`), causing a failing check when trying to actually compute
outputs.  Here we add an appropriate input validation check.

NOTE: no test is added because it's impossible to trigger these using the
official public API.
PiperOrigin-RevId: 461637318


Vulnerable code:

Fixed code:
#include <initializer_list>
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/platform/errors.h"
    OP_REQUIRES(
        context, in.dtype() == DataTypeToEnum<InputScalar>::v(),
        errors::InvalidArgument("Invalid input dtype ", in.dtype(), " vs ",
                                DataTypeToEnum<InputScalar>::v()));
    OP_REQUIRES(
        context, out->dtype() == DataTypeToEnum<OutputScalar>::v(),
        errors::InvalidArgument("Invalid output dtype ", out->dtype(), " vs ",
                                DataTypeToEnum<OutputScalar>::v()));

from tensorflow.python.framework import errors
from tensorflow.python.ops import gen_linalg_ops
  def testMismatchedDtypes(self):
    tensor = constant_op.constant([[0, 1], [2, 3]], dtype=dtypes_lib.float32)
    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                "Invalid output dtype"):
      self.evaluate(
          gen_linalg_ops.eig(
              input=tensor,
              Tout=dtypes_lib.complex128,  # Expected dtype: complex64.
              compute_v=True))
CVE-2022-36001 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `DrawBoundingBoxes` receives an input `boxes` that is not of dtype `float`, it gives a `CHECK` fail that can trigger a denial of service attack. We have patched the issue in GitHub commit da0d65cdc1270038e72157ba35bf74b85d9bda11. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/image/draw_bounding_box_op.cc
tensorflow/python/kernel_tests/image_ops/draw_bounding_box_op_test.py
Commit message: Fix dtype bug in draw bounding boxes.

Boxes always needs to be type `float`.

PiperOrigin-RevId: 461800676


Vulnerable code:
      const auto tboxes = boxes.tensor<T, 3>();
  def _testDrawBoundingBoxColorCycling(self, img, colors=None):
      image = image_ops_impl.convert_image_dtype(image, dtypes.float32)

Fixed code:
      const auto tboxes = boxes.tensor<float, 3>();
  def _testDrawBoundingBoxColorCycling(self,
                                       img,
                                       dtype=dtypes.float32,
                                       colors=None):
      dtype: image dtype (float, half).
      colors: color table.
      image = image_ops_impl.convert_image_dtype(image, dtype)
  def testDrawBoundingBoxHalf(self):
    """Test if RGBA color cycling works correctly with provided colors."""
    image = np.zeros([10, 10, 4], "float32")
    colors = np.asarray([[0.5, 0, 0.5, 1], [0.5, 0.5, 0, 1], [0.5, 0, 0, 1],
                         [0, 0, 0.5, 1]])
    self._testDrawBoundingBoxColorCycling(
        image, dtype=dtypes.half, colors=colors)
CVE-2022-36002 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `Unbatch` receives a nonscalar input `id`, it gives a `CHECK` fail that can trigger a denial of service attack. We have patched the issue in GitHub commit 4419d10d576adefa36b0e0a9425d2569f7c0189f. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/batch_kernels.cc
tensorflow/python/ops/batch_ops_test.py
Commit message: Fix check failure in Unbatch Op kernel by checking whether input argument is a scalar before trying to extract value.

PiperOrigin-RevId: 461660186


Vulnerable code:

Fixed code:
#include "tensorflow/core/framework/tensor_shape.h"
    if (!TensorShapeUtils::IsScalar(context->input(2).shape())) {
      return errors::InvalidArgument(
          "Input id should be scalar; "
          "Got: ",
          context->input(2).DebugString(), ".");
    }
  def testUnbatchInvalidIdArg(self):
    """Tests that unbatch work together."""
    if context.executing_eagerly():
      batched_tensor = constant_op.constant(
          value=np.random.random(size=(3, 3, 1)), dtype=dtypes.float64)
      batched_index = constant_op.constant(
          value=np.random.randint(0, 100, size=(3, 3, 1)), dtype=dtypes.int64)
      arg_id = constant_op.constant(
          value=np.random.randint(0, 100, size=(3, 3, 1)), dtype=dtypes.int64)

      with self.assertRaisesRegex(errors.InvalidArgumentError,
                                  "Input id should be scalar;"):
        batch_ops.unbatch(
            batched_tensor=batched_tensor,
            batch_index=batched_index,
            id=arg_id,
            timeout_micros=50,
            container="",
            shared_name="")
CVE-2022-36003 (Python, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `RandomPoissonV2` receives large input shape and rates, it gives a `CHECK` fail that can trigger a denial of service attack. We have patched the issue in GitHub commit 552bfced6ce4809db5f3ca305f60ff80dd40c5a3. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
Severity: nan (CVSS v3 base score: 7.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/core/kernels/random_op.cc
tensorflow/core/kernels/random_poisson_op.cc
tensorflow/python/kernel_tests/random/random_gamma_test.py
tensorflow/python/kernel_tests/random/random_poisson_test.py
Commit message: Fix size check for large input shape and rates.

To address a check failure for exceedingly large output shapes, we need to
`AppendShapeWithStatus`.

PiperOrigin-RevId: 462885894


Vulnerable code:
    samples_shape.AppendShape(alpha_t.shape());
    samples_shape.AppendShape(rate_t.shape());

Fixed code:
    OP_REQUIRES_OK(ctx, samples_shape.AppendShapeWithStatus(alpha_t.shape()));
    OP_REQUIRES_OK(ctx, samples_shape.AppendShapeWithStatus(rate_t.shape()));
from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import errors
  def testSizeTooLarge(self):
    # Grappler asserts on size overflow, so this error is only caught when
    # running eagerly.
    if context.executing_eagerly():
      with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                  "overflow"):
        rate = constant_op.constant(1.0, shape=(4, 4, 4, 4, 4))
        self.evaluate(
            random_ops.random_gamma(
                shape=[46902, 51188, 34063, 59195], alpha=rate))
from tensorflow.python.framework import errors
  def testSizeTooLarge(self):
    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                "overflow"):
      rate = constant_op.constant(1.0, shape=(4, 4, 4, 4, 4))
      self.evaluate(
          random_ops.random_poisson(
              shape=[46902, 51188, 34063, 59195], lam=rate))