hitoshura25/cvefixes huggingface dataset:
CVE-2022-35934 (Python, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of tf.reshape op in TensorFlow is vulnerable to a denial of service via CHECK-failure (assertion failure) caused by overflowing the number of elements in a tensor. This issue has been patched in GitHub commit 61f0f9b94df8c0411f0ad0ecc2fec2d3f3c33555. 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/reshape_op.h
tensorflow/python/kernel_tests/array_ops/array_ops_test.py
Commit message: Fix failed check in tf.reshape.

Passing in too many dimensions causes an assertion
failure and a crash. Check input as a precondition and
fail gracefully.

PiperOrigin-RevId: 449893553


Vulnerable code:

Fixed code:
    OP_REQUIRES(
        context, sizes.NumElements() < TensorShape::MaxDimensions(),
        errors::InvalidArgument("too many dimensions: must be < ",
                                TensorShape::MaxDimensions(), ", but received ",
                                sizes.NumElements()));
  def testReshapeWithManyDims(self):
    with self.assertRaisesRegex(errors.InvalidArgumentError,
                                "too many dimensions"):
      self.evaluate(
          array_ops.reshape(
              tensor=[[1]],
              shape=constant_op.constant([1 for i in range(254)],
                                         dtype=dtypes.int64)))
CVE-2022-35935 (C++, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of SobolSampleOp is vulnerable to a denial of service via CHECK-failure (assertion failure) caused by assuming `input(0)`, `input(1)`, and `input(2)` to be scalar. This issue has been patched in GitHub commit c65c67f88ad770662e8f191269a907bf2b94b1bf. 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/sobol_op.cc
Commit message: Fix `CHECK`-fail due to passing invalid tensors in `SobolOp`.

PiperOrigin-RevId: 460794378


Vulnerable code:

Fixed code:
#include "tensorflow/core/framework/tensor_shape.h"
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("dim must be a scalar"));
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("num_results must be a scalar"));
    OP_REQUIRES(context, TensorShapeUtils::IsScalar(context->input(0).shape()),
                errors::InvalidArgument("skip must be a scalar"));
CVE-2022-35941 (Python, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The `AvgPoolOp` function takes an argument `ksize` that must be positive but is not checked. A negative `ksize` can trigger a `CHECK` failure and crash the program. We have patched the issue in GitHub commit 3a6ac52664c6c095aa2b114e742b0aa17fdce78f. 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 to 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/avgpooling_op.cc
tensorflow/python/kernel_tests/nn_ops/pooling_ops_test.py
Commit message: Fix security vulnerability with AvgPoolGrad

PiperOrigin-RevId: 461724457


Vulnerable code:
      output_shape.AddDim(shape_vec(i));
      output_shape.AddDim(shape_vec(i));
      output_shape.AddDim(shape_vec(i));

Fixed code:
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
  def testAvgPoolGradInvalidInputShapeRaiseError(self):
    with self.assertRaises((ValueError, errors_impl.InvalidArgumentError)):
      with self.cached_session():
        orig_input_shape = constant_op.constant(
            -536870912, shape=[4], dtype=dtypes.int32)
        grad = constant_op.constant(
            .0890338004362538, shape=[1, 5, 7, 1], dtype=dtypes.float64)
        t = gen_nn_ops.AvgPoolGrad(
            orig_input_shape=orig_input_shape,
            grad=grad,
            ksize=[1, 2, 2, 1],
            strides=[1, 2, 2, 1],
            padding="VALID",
            data_format="NHWC")
        self.evaluate(t)
CVE-2022-35959 (Other, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of `AvgPool3DGradOp` does not fully validate the input `orig_input_shape`. This results in an overflow that results in a `CHECK` failure which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 9178ac9d6389bdc54638ab913ea0e419234d14eb. 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/compiler/tf2xla/BUILD
tensorflow/compiler/tf2xla/xla_op_kernel.cc
tensorflow/core/kernels/pooling_ops_3d.cc
tensorflow/python/kernel_tests/nn_ops/BUILD
tensorflow/python/kernel_tests/nn_ops/pooling_ops_3d_test.py
Commit message: Fix security vulnerability with AvgPool3DGrad.

PiperOrigin-RevId: 461244371


Vulnerable code:
      output_shape.AddDim(shape_vec(i));
    with self.cached_session(use_gpu=use_gpu) as sess:

Fixed code:
        "//tensorflow/core/util:overflow",
#include "tensorflow/core/util/overflow.h"

  int64_t num_elements = 1;
  for (auto i = dims.begin(); i != dims.end(); ++i) {
    num_elements = MultiplyWithoutOverflow(num_elements, *i);
    if (num_elements < 0)
      return errors::InvalidArgument(
          "The total elements specified by orig_input_shape is too large.",
          "Encountered overflow after multiplying", *i,
          ", result: ", num_elements);
  }
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
        "//tensorflow/python:dtypes",
from tensorflow.python.framework import dtypes
    with self.cached_session(use_gpu=use_gpu):
  def testMaxPool3dGrad(self):
    with self.assertRaises(
        (errors.ResourceExhaustedError, errors.InvalidArgumentError)):
      with self.cached_session():
        orig_input_shape = constant_op.constant(
            1879048192, shape=[5], dtype=dtypes.int32)
        grad = constant_op.constant(
            1, shape=[1, 3, 2, 4, 2], dtype=dtypes.float32)
        t = gen_nn_ops.AvgPool3DGrad(
            orig_input_shape=orig_input_shape,
            grad=grad,
            ksize=[1, 1, 1, 1, 1],
            strides=[1, 1, 1, 1, 1],
            padding="SAME",
            data_format="NDHWC")
        self.evaluate(t)
CVE-2022-35960 (Python, published 2022-09-16T20:15Z)
Description: value: TensorFlow is an open source platform for machine learning. In `core/kernels/list_kernels.cc's TensorListReserve`, `num_elements` is assumed to be a tensor of size 1. When a `num_elements` of more than 1 element is provided, then `tf.raw_ops.TensorListReserve` fails the `CHECK_EQ` in `CheckIsAlignedAndSingleElement`. We have patched the issue in GitHub commit b5f6fbfba76576202b72119897561e3bd4f179c7. 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: Re-enable testTensorListReserveWithNonScalarNumElements to work with mlir as well.

PiperOrigin-RevId: 466460987


Vulnerable code:

Fixed code:
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/platform/errors.h"
    OP_REQUIRES(
        c, TensorShapeUtils::IsScalar(c->input(1).shape()),
        errors::InvalidArgument(
            "The num_elements to reserve must be a tensor size 1, but got ",
            c->input(1).shape()));
  def testTensorListReserveWithNonScalarNumElements(self):
    # list_kernels.cc in tf/core/kernels raises InvalidArgumentError, and
    # tf_ops_n_z.cc in tf/compiler/mlir/tf/ir raises UnknownError.
    with self.assertRaises((errors.InvalidArgumentError, errors.UnknownError)):
      l = list_ops.tensor_list_reserve(
          element_dtype=dtypes.float32,
          element_shape=[2, 3],
          num_elements=constant_op.constant([1, 1]))
      self.evaluate(l)
CVE-2022-35965 (Python, published 2022-09-16T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `LowerBound` or `UpperBound` is given an empty`sorted_inputs` input, it results in a `nullptr` dereference, leading to a segfault that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit bce3717eaef4f769019fd18e990464ca4a2efeea. 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/searchsorted_op.cc
tensorflow/python/kernel_tests/array_ops/array_ops_test.py
Commit message: Fix empty inputs for Upper/LowerBound.

For upper/lower-bound searches via `tf.searchsorted`, if the sorted input is empty,
the previous code resulted in a `nullptr` dereference.  For emtpy inputs, any
sorted search should return a value of 0, meaning that a value would be inserted
into the first slot of the array.

PiperOrigin-RevId: 460971165


Vulnerable code:

Fixed code:
#include "tensorflow/core/kernels/fill_functor.h"

    // For empty inputs, all values will be placed at the zeroth position.
    if (sorted_inputs.size() == 0) {
      functor::SetZeroFunctor<Device, OutType> set_zero;
      set_zero(ctx->eigen_device<Device>(), output);
      return;
    }


    // For empty inputs, all values will be placed at the zeroth position.
    if (sorted_inputs.size() == 0) {
      functor::SetZeroFunctor<Device, OutType> set_zero;
      set_zero(ctx->eigen_device<Device>(), output);
      return;
    }

  def testZeroInputSize(self):
    dtype = dtypes.int32
    for side in ("left", "right"):
      with self.subTest(side=side):
        self.assertAllEqual(
            array_ops.searchsorted(
                array_ops.ones([2, 0]),
                array_ops.ones([2, 3]),
                side=side,
                out_type=dtype), array_ops.zeros([2, 3], dtype))
CVE-2022-35968 (Python, published 2022-09-16T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of `AvgPoolGrad` does not fully validate the input `orig_input_shape`. This results in a `CHECK` failure which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 3a6ac52664c6c095aa2b114e742b0aa17fdce78f. 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/avgpooling_op.cc
tensorflow/python/kernel_tests/nn_ops/pooling_ops_test.py
Commit message: Fix security vulnerability with AvgPoolGrad

PiperOrigin-RevId: 461724457


Vulnerable code:
      output_shape.AddDim(shape_vec(i));
      output_shape.AddDim(shape_vec(i));
      output_shape.AddDim(shape_vec(i));

Fixed code:
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
      OP_REQUIRES_OK(context, output_shape.AddDimWithStatus(shape_vec(i)));
  def testAvgPoolGradInvalidInputShapeRaiseError(self):
    with self.assertRaises((ValueError, errors_impl.InvalidArgumentError)):
      with self.cached_session():
        orig_input_shape = constant_op.constant(
            -536870912, shape=[4], dtype=dtypes.int32)
        grad = constant_op.constant(
            .0890338004362538, shape=[1, 5, 7, 1], dtype=dtypes.float64)
        t = gen_nn_ops.AvgPoolGrad(
            orig_input_shape=orig_input_shape,
            grad=grad,
            ksize=[1, 2, 2, 1],
            strides=[1, 2, 2, 1],
            padding="VALID",
            data_format="NHWC")
        self.evaluate(t)
CVE-2022-35969 (Python, published 2022-09-16T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The implementation of `Conv2DBackpropInput` requires `input_sizes` to be 4-dimensional. Otherwise, it gives a `CHECK` failure which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 50156d547b9a1da0144d7babe665cf690305b33c. 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: Add security vulnerability test for raw_ops.Conv2DBackpropInput

PiperOrigin-RevId: 463395218


Vulnerable code:
      with self.cached_session(use_gpu=use_gpu) as sess:
      with self.cached_session(use_gpu=use_gpu) as sess:
    with self.cached_session() as sess:
    with self.cached_session(use_gpu=False) as sess:

Fixed code:
    OP_REQUIRES(
        context, out_backprop.dims() == 4,
        errors::InvalidArgument("input_sizes must be 4-dimensional, got: ",
                                out_backprop.dims()));

    OP_REQUIRES(
        context, out_backprop.dims() == 4,
        errors::InvalidArgument("input_sizes must be 4-dimensional, got: ",
                                out_backprop.dims()));
from tensorflow.python.ops import gen_nn_ops
      with self.cached_session(use_gpu=use_gpu):
      with self.cached_session(use_gpu=use_gpu):
  def testConv2DBackpropInputInvalidOutBackpropRaiseError(self):
    with self.assertRaises((ValueError, errors_impl.InvalidArgumentError)):
      with self.cached_session():
        input_sizes = constant_op.constant([65534, 65534],
                                           shape=[2],
                                           dtype=dtypes.int32)
        filters = constant_op.constant(
            0.159749106, shape=[3, 3, 2, 2], dtype=dtypes.float32)
        out_backprop = constant_op.constant(0, shape=[], dtype=dtypes.float32)
        t = gen_nn_ops.conv2d_backprop_input(
            input_sizes=input_sizes,
            filter=filters,
            out_backprop=out_backprop,
            strides=[1, 1, 1, 1],
            padding="SAME",
            use_cudnn_on_gpu=True,
            explicit_paddings=[],
            data_format="NHWC",
            dilations=[1, 1, 1, 1])
        self.evaluate(t)

    with self.cached_session():
    with self.cached_session(use_gpu=False):
CVE-2022-35974 (C++, published 2022-09-16T21:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `QuantizeDownAndShrinkRange` is given nonscalar inputs for `input_min` or `input_max`, it results in a segfault that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 73ad1815ebcfeb7c051f9c2f7ab5024380ca8613. 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: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/quantize_down_and_shrink_range.cc
tensorflow/core/kernels/quantize_down_and_shrink_range_op_test.cc
tensorflow/python/kernel_tests/quantization_ops/quantization_ops_test.py
Commit message: Add IsScalar (rank == 0) check to input_min/max tensors for QuantizeDownAndShrinkRangeOp.

PiperOrigin-RevId: 462401306


Vulnerable code:
    const float input_min_float = ctx->input(1).flat<float>()(0);
    const float input_max_float = ctx->input(2).flat<float>()(0);
  AddInputFromArray<float>(TensorShape({1}), {-256.0f});
  AddInputFromArray<float>(TensorShape({1}), {256.0f});

Fixed code:
    const Tensor& input_min = ctx->input(1);
    const Tensor& input_max = ctx->input(2);

    OP_REQUIRES(
        ctx, TensorShapeUtils::IsScalar(input_min.shape()),
        errors::InvalidArgument("`input_min` must be rank 0 but is rank ",
                                input_min.dims()));
    OP_REQUIRES(
        ctx, TensorShapeUtils::IsScalar(input_max.shape()),
        errors::InvalidArgument("`input_max` must be rank 0 but is rank ",
                                input_max.dims()));

    const float input_min_float = input_min.scalar<float>()();
    const float input_max_float = input_max.scalar<float>()();
  AddInputFromArray<float>(TensorShape({}), {-256.0f});
  AddInputFromArray<float>(TensorShape({}), {256.0f});
class QuantizeDownAndShrinkRangeOpTest(test_util.TensorFlowTestCase):

  @test_util.run_in_graph_and_eager_modes
  def test_invalid_inputs(self):
    inputs = constant_op.constant(
        np.int32(0), shape=[3, 3, 3, 3], dtype=dtypes.qint32)

    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                "must be rank 0"):
      self.evaluate(
          math_ops.quantize_down_and_shrink_range(input=inputs,
                                                  input_min=[],
                                                  input_max=4.0,
                                                  out_type=dtypes.quint8))
CVE-2022-35982 (Other, published 2022-09-16T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `SparseBincount` is given inputs for `indices`, `values`, and `dense_shape` that do not make a valid sparse tensor, it results in a segfault that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 40adbe4dd15b582b0210dfbf40c243a62f5119fa. 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: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/BUILD
tensorflow/core/kernels/bincount_op.cc
tensorflow/python/kernel_tests/math_ops/bincount_op_test.py
Commit message: Add sparse tensor validation to SparseBincountOp.

Addresses a security issue.

PiperOrigin-RevId: 460573866


Vulnerable code:
    const auto values = ctx->input(1).flat<Tidx>();
                           ctx, values, weights, out, size));
                     ctx, values, weights, out, size));
        const Tidx bin = values(i);
    inp_indices = np.random.randint(0, num_rows, (n_elems,))
    inp_indices = np.random.randint(0, num_rows, (n_elems,))
    inp_indices = np.random.randint(0, num_rows, (n_elems,))
    inp_indices = np.random.randint(0, num_rows, (n_elems,))

Fixed code:
        ":sparse_utils",
    ":sparse_utils",
        "sparse_utils.h",
        "sparse_utils.cc",
#include "tensorflow/core/kernels/sparse_utils.h"
    const Tensor& values = ctx->input(1);
    const auto values_flat = values.flat<Tidx>();
    OP_REQUIRES_OK(
        ctx, sparse_utils::ValidateSparseTensor<int64_t>(
                 indices, values, dense_shape, /*validate_indices=*/true));
                           ctx, values_flat, weights, out, size));
                     ctx, values_flat, weights, out, size));
        const Tidx bin = values_flat(i);
    inp_indices = np.random.randint(0, num_rows, (n_elems, 1))
    inp_indices = np.random.randint(0, num_rows, (n_elems, 1))
    inp_indices = np.random.randint(0, num_rows, (n_elems, 1))
    inp_indices = np.random.randint(0, num_rows, (n_elems, 1))
  def test_sparse_bincount_input_validation(self):
    np.random.seed(42)
    num_rows = 128
    size = 1000
    n_elems = 4096
    inp_indices = np.random.randint(0, num_rows, (n_elems, 1))
    inp_vals = np.random.randint(0, size, (n_elems,))

    # Insert negative index.
    inp_indices[10, 0] = -2

    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                "out of bounds"):
      self.evaluate(
          gen_math_ops.sparse_bincount(
              indices=inp_indices,
              values=inp_vals,
              dense_shape=[num_rows],
              size=size,
              weights=[]))