hitoshura25/cvefixes huggingface dataset:
CVE-2022-41885 (C++, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `tf.raw_ops.FusedResizeAndPadConv2D` is given a large tensor shape, it overflows. We have patched the issue in GitHub commit d66e1d568275e6a2947de97dca7a102a211e01ce. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-131 \u2014 Incorrect Calculation of Buffer Size
The product does not correctly calculate the size to be used when allocating a buffer, which could lead to a buffer overflow.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/conv_ops_fused_image_transform.cc
tensorflow/core/ops/nn_ops.cc
tensorflow/python/kernel_tests/nn_ops/conv_ops_test.py
Commit message: Fix tensor shape overflow in FusedResizeAndPadConv2D.

Replaced TensorShape constructor by Factory method with status.

PiperOrigin-RevId: 477742686


Vulnerable code:
    TensorShape resized_shape(
        {input.dim_size(0), st.out_height, st.out_width, input.dim_size(3)});
      return CommonFusedConvCalculations(c, true /* has_resize */);
      return CommonFusedConvCalculations(c, false /* has_resize */);

Fixed code:
    TensorShape resized_shape;
    OP_REQUIRES_OK(context, TensorShape::BuildTensorShape(
                                {input.dim_size(0), st.out_height, st.out_width,
                                 input.dim_size(3)},
                                &resized_shape));
      return CommonFusedConvCalculations(c, /*has_resize=*/true);
      return CommonFusedConvCalculations(c, /*has_resize=*/false);
  # Fused resize and pad conv.
  @test_util.run_in_graph_and_eager_modes()
  def testResizeAndPadLargeResize(self):
    with self.assertRaisesRegex((ValueError, errors_impl.InvalidArgumentError),
                                "Encountered overflow"):
      mode = "REFLECT"
      strides = [1, 1, 1, 1]
      padding = "SAME"
      resize_align_corners = False
      tensor = constant_op.constant(
          147, shape=[3, 3, 1, 4], dtype=dtypes.float32)
      size = constant_op.constant([1879048192, 1879048192], dtype=dtypes.int32)
      paddings = constant_op.constant([[0, 0], [0, 0], [0, 0], [0, 0]],
                                      dtype=dtypes.int32)
      kernel = constant_op.constant(
          123, shape=[1, 3, 4, 1], dtype=dtypes.float32)
      self.evaluate(
          gen_nn_ops.fused_resize_and_pad_conv2d(
              input=tensor,
              size=size,
              paddings=paddings,
              filter=kernel,
              mode=mode,
              strides=strides,
              padding=padding,
              resize_align_corners=resize_align_corners))
CVE-2022-41886 (Python, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `tf.raw_ops.ImageProjectiveTransformV2` is given a large output shape, it overflows. We have patched the issue in GitHub commit 8faa6ea692985dbe6ce10e1a3168e0bd60a723ba. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-131 \u2014 Incorrect Calculation of Buffer Size
The product does not correctly calculate the size to be used when allocating a buffer, which could lead to a buffer overflow.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/image/image_ops.cc
tensorflow/python/ops/image_ops_test.py
Commit message: Fix tf.raw_ops.ImageProjectiveTransformV2 vulnerability with large output_shape.

Note: This fix will have to be cherry picked in r2.10, r2.9, and r2.8.
PiperOrigin-RevId: 479125772


Vulnerable code:
      ctx, ctx->allocate_output(0,
                                TensorShape({images_t.dim_size(0), out_height,
                                             out_width, images_t.dim_size(3)}),
                                &output_t));

Fixed code:
  TensorShape output_shape;
      ctx, TensorShape::BuildTensorShape({images_t.dim_size(0), out_height,
                                          out_width, images_t.dim_size(3)},
                                         &output_shape));
  OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output_t));
class ImageProjectiveTransformV2(test_util.TensorFlowTestCase):

  def testShapeTooLarge(self):
    interpolation = "BILINEAR"
    fill_mode = "REFLECT"
    images = constant_op.constant(
        0.184634328, shape=[2, 5, 8, 3], dtype=dtypes.float32)
    transforms = constant_op.constant(
        0.378575385, shape=[2, 8], dtype=dtypes.float32)
    output_shape = constant_op.constant([1879048192, 1879048192],
                                        shape=[2],
                                        dtype=dtypes.int32)
    with self.assertRaisesRegex(errors.InvalidArgumentError,
                                r"Encountered overflow when multiplying"):
      self.evaluate(
          gen_image_ops.ImageProjectiveTransformV2(
              images=images,
              transforms=transforms,
              output_shape=output_shape,
              interpolation=interpolation,
              fill_mode=fill_mode))
CVE-2022-41887 (C, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. `tf.keras.losses.poisson` receives a `y_pred` and `y_true` that are passed through `functor::mul` in `BinaryOp`. If the resulting dimensions overflow an `int32`, TensorFlow will crash due to a size mismatch during broadcast assignment. We have patched the issue in GitHub commit c5b30379ba87cbe774b08ac50c1f6d36df4ebb7c. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1 and 2.9.3, as these are also affected and still in supported range. However, we will not cherrypick this commit into TensorFlow 2.8.x, as it depends on Eigen behavior that changed between 2.8 and 2.9.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-131 \u2014 Incorrect Calculation of Buffer Size
The product does not correctly calculate the size to be used when allocating a buffer, which could lead to a buffer overflow.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/cwise_ops_common.h
Commit message: Fix cwise dimension overflow issue again.

If resulting dimensions overflow an int32, we were seeing an overflow and
crash due to size mismatch during broadcast assignment.  The cause is a simple
dimension type mismatch.

Note that actual tests for this are currently impractical, since successful
operations require more than 2^32 elements and OOM on most machines.

PiperOrigin-RevId: 479336566


Vulnerable code:
  inline Eigen::IndexList<int, Eigen::type2index<1>> NByOne(int n) {
    Eigen::IndexList<int, Eigen::type2index<1>> ret;
  inline Eigen::IndexList<Eigen::type2index<1>, int> OneByM(int m) {
    Eigen::IndexList<Eigen::type2index<1>, int> ret;
      const int a = in0.dimension(0);  // in0 is shape [a, b]
      const int b = in0.dimension(1);
      const int c = in1.dimension(0);  // in1 is shape [c, d]
      const int d = in1.dimension(1);

Fixed code:
  inline Eigen::IndexList<Eigen::DenseIndex, Eigen::type2index<1>> NByOne(
      Eigen::DenseIndex n) {
    Eigen::IndexList<Eigen::DenseIndex, Eigen::type2index<1>> ret;
  inline Eigen::IndexList<Eigen::type2index<1>, Eigen::DenseIndex> OneByM(
      Eigen::DenseIndex m) {
    Eigen::IndexList<Eigen::type2index<1>, Eigen::DenseIndex> ret;
      const Eigen::DenseIndex a = in0.dimension(0);  // in0 is shape [a, b]
      const Eigen::DenseIndex b = in0.dimension(1);
      const Eigen::DenseIndex c = in1.dimension(0);  // in1 is shape [c, d]
      const Eigen::DenseIndex d = in1.dimension(1);
CVE-2022-41888 (Other, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When running on GPU, `tf.image.generate_bounding_box_proposals` receives a `scores` input that must be of rank 4 but is not checked. We have patched the issue in GitHub commit cf35502463a88ca7185a99daa7031df60b3c1c98. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/image/generate_box_proposals_op.cu.cc
tensorflow/python/kernel_tests/image_ops/BUILD
tensorflow/python/kernel_tests/image_ops/draw_bounding_box_op_test.py
Commit message: Add rank checks to GenerateBoundingBoxProposals.

PiperOrigin-RevId: 479681553


Vulnerable code:
tf_py_test(

Fixed code:

    OP_REQUIRES(context, scores.dims() == 4,
                errors::InvalidArgument("`scores` must be rank 4 but is rank ",
                                        scores.dims()));
    OP_REQUIRES(
        context, bbox_deltas.dims() == 4,
        errors::InvalidArgument("`bbox_deltas` must be rank 4 but is rank ",
                                bbox_deltas.dims()));
    OP_REQUIRES(
        context, image_info.dims() == 2,
        errors::InvalidArgument("`image_info` must be rank 2 but is rank ",
                                image_info.dims()));
    OP_REQUIRES(context, anchors.dims() == 3,
                errors::InvalidArgument("`anchors` must be rank 3 but is rank ",
                                        anchors.dims()));

cuda_py_test(
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import errors
from tensorflow.python.framework import test_util
  # generate_bound_box_proposals is only available on GPU.
  @test_util.run_gpu_only()
  def testGenerateBoundingBoxProposals(self):
    # Op only exists on GPU.
    with self.cached_session(use_gpu=True):
      with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                  "must be rank 4"):
        scores = constant_op.constant(
            value=[[[[1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0]]]])
        self.evaluate(
            image_ops.generate_bounding_box_proposals(
                scores=scores,
                bbox_deltas=[],
                image_info=[],
                anchors=[],
                pre_nms_topn=1))
CVE-2022-41890 (C, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `BCast::ToShape` is given input larger than an `int32`, it will crash, despite being supposed to handle up to an `int64`. An example can be seen in `tf.experimental.numpy.outer` by passing in large input to the input `b`. We have patched the issue in GitHub commit 8310bf8dd188ff780e7fc53245058215a05bdbe5. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-704 \u2014 Incorrect Type Conversion or Cast
The product does not correctly convert an object, resource, or structure from one type to a different type.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/util/bcast.h
tensorflow/core/util/bcast_test.cc
Commit message: Fix crash caused by large broadcasting error.  There was an int32 overflow.

PiperOrigin-RevId: 475677838


Vulnerable code:
  auto mul_dims = [](int64_t dim1, int64_t dim2) -> int64 {
  int output_dim = -1;

Fixed code:
  auto mul_dims = [](int64_t dim1, int64_t dim2) -> int64_t {
  int64_t output_dim = -1;

  // int32 edge-case:
  EXPECT_EQ(BCast({1, 2147483648}, {1}),
            "[2147483648][1][1][2147483648]"
            "[2147483648]"
            "[1,2147483648]"
            "[0][0,1]");
CVE-2022-41891 (Python, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `tf.raw_ops.TensorListConcat` is given `element_shape=[]`, it results segmentation fault which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit fc33f3dc4c14051a83eec6535b608abe1d355fde. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: NVD-CWE-Other \u2014 Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/list_kernels.h
tensorflow/python/kernel_tests/data_structures/list_ops_test.py
Commit message: Fix tf.raw_ops.TensorListConcat vulnerability (segfault).

Check that the element_shape input is valid.
Add graph/eager unit tests.

Note: This fix will have to be cherry picked in r2.10, r2.9, and r2.8.
PiperOrigin-RevId: 477544091


Vulnerable code:
      element_shape_except_first_dim = PartialTensorShape(
          gtl::ArraySlice<int64_t>(element_shape_.dim_sizes()).subspan(1));

Fixed code:
      auto dim_sizes = element_shape_.dim_sizes();
      OP_REQUIRES(c, !dim_sizes.empty(),
                  errors::InvalidArgument("element_shape must not be empty"));
      element_shape_except_first_dim =
          PartialTensorShape(gtl::ArraySlice<int64_t>(dim_sizes).subspan(1));
  @test_util.run_in_graph_and_eager_modes
  def testConcatWithInvalidElementShape(self):
    l = list_ops.tensor_list_reserve(
        element_dtype=dtypes.float32, element_shape=[], num_elements=0)
    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                r"element_shape must not be empty"):
      self.evaluate(gen_list_ops.tensor_list_concat(
          input_handle=l, element_dtype=dtypes.float32, element_shape=[]))
CVE-2022-41893 (Python, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `tf.raw_ops.TensorListResize` is given a nonscalar value for input `size`, it results `CHECK` fail which can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 888e34b49009a4e734c27ab0c43b0b5102682c56. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
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.TensorListResize vulnerability with non-scalar input.

Check that the size input is valid.
Add graph/eager unit tests. Graph mode was already ok but eager mode was not.

Note: This fix will have to be cherry picked in r2.10, r2.9, and r2.8.
PiperOrigin-RevId: 477002316


Vulnerable code:

Fixed code:
    OP_REQUIRES(c, TensorShapeUtils::IsScalar(c->input(1).shape()),
                errors::InvalidArgument("size must be a scalar"));
  @test_util.run_in_graph_and_eager_modes
  def testResizeWithNonScalarFails(self):
    l = list_ops.tensor_list_from_tensor([3, 4, 5], element_shape=[])
    size = np.zeros([0, 2, 3, 3])
    with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError),
                                r"Shape must be rank 0 but is rank \d+|"
                                r"\w+ must be a scalar"):
      self.evaluate(gen_list_ops.TensorListResize(input_handle=l, size=size))
CVE-2022-41894 (C, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The reference kernel of the `CONV_3D_TRANSPOSE` TensorFlow Lite operator wrongly increments the data_ptr when adding the bias to the result. Instead of `data_ptr += num_channels;` it should be `data_ptr += output_num_channels;` as if the number of input channels is different than the number of output channels, the wrong result will be returned and a buffer overflow will occur if num_channels > output_num_channels. An attacker can craft a model with a specific number of input channels. It is then possible to write specific values through the bias of the layer outside the bounds of the buffer. This attack only works if the reference kernel resolver is used in the interpreter. We have patched the issue in GitHub commit 72c0bdcb25305b0b36842d746cc61d72658d2941. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 8.1)
Weakness: CWE-120 \u2014 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/lite/kernels/internal/reference/conv3d_transpose.h
Commit message: Fix a potential buffer overflow issue in reference kernel of the CONV_3D_TRANSPOSE

PiperOrigin-RevId: 479074072


Vulnerable code:
    const int num_channels = input_shape.Dims(4);
      data_ptr += num_channels;

Fixed code:
      data_ptr += output_num_channels;
CVE-2022-41895 (Python, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `MirrorPadGrad` is given outsize input `paddings`, TensorFlow will give a heap OOB error. We have patched the issue in GitHub commit 717ca98d8c3bba348ff62281fdf38dcb5ea1ec92. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
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/kernels/image/mirror_pad_op.cc
tensorflow/python/kernel_tests/array_ops/array_ops_test.py
Commit message: Adding missing requirement on inputs for MirrorPadGrad op and updating arithmetic to account for int32 padding values.

PiperOrigin-RevId: 480691952


Vulnerable code:
      const Tpaddings before = paddings(d, 0);  // Pad before existing elements.
      const Tpaddings after = paddings(d, 1);   // Pad after existing elements.
      const int64_t out_size = in0.dim_size(d) - (before + after);

Fixed code:
      const int64_t before = paddings(d, 0);  // Pad before existing elements.
      const int64_t after = paddings(d, 1);   // Pad after existing elements.
      const int64_t in_size = in0.dim_size(d);
      const int64_t total_padding = before + after;
      OP_REQUIRES(
          context, total_padding < in_size && total_padding >= 0,
          errors::InvalidArgument(
              "Total paddings must be less than the input dimension size: ",
              total_padding, " was not less than ", in_size));

      const int64_t out_size = in_size - total_padding;
  # b/246325518: Bad shape size. Explicitly testing different execution paths.
  def testInvalidMirrorPadGradEagerMode(self):
    with context.eager_mode():
      with self.assertRaises(Exception):
        gen_array_ops.MirrorPadGrad(
            input=[1], paddings=[[0x77f00000, 0xa000000]], mode="REFLECT")

  # b/246325518: Bad shape size. Explicitly testing different execution paths.
  def testInvalidMirrorPadGradGraphMode(self):
    with context.graph_mode():
      with self.assertRaises(Exception):
        result = gen_array_ops.MirrorPadGrad(
            input=[1], paddings=[[0x77f00000, 0xa000000]], mode="REFLECT")
        self.evaluate(result)
CVE-2022-41897 (Python, published 2022-11-18T22:15Z)
Description: value: TensorFlow is an open source platform for machine learning. If `FractionMaxPoolGrad` is given outsize inputs `row_pooling_sequence` and `col_pooling_sequence`, TensorFlow will crash. We have patched the issue in GitHub commit d71090c3e5ca325bdf4b02eb236cfb3ee823e927. The fix will be included in TensorFlow 2.11. We will also cherrypick this commit on TensorFlow 2.10.1, 2.9.3, and TensorFlow 2.8.4, as these are also affected and still in supported range.
Severity: nan (CVSS v3 base score: 7.5)
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/kernels/fractional_max_pool_op.cc
tensorflow/python/kernel_tests/nn_ops/fractional_max_pool_op_test.py
Commit message: Fix security vulnerability with FractionalMaxPoolGrad

PiperOrigin-RevId: 477500477


Vulnerable code:
      with self.cached_session() as _:

Fixed code:
    OP_REQUIRES(
        context,
        height_seq_tensor.NumElements() * width_seq_tensor.NumElements() <=
            tensor_in.NumElements(),
        errors::InvalidArgument(
            "Pooling region has more elements than the input tensor. "
            "row_pooling_sequence: ",
            height_seq_tensor.DebugString(),
            "col_pooling_sequence: ", width_seq_tensor.DebugString(),
            "orig_input: ", tensor_in.DebugString()));

    //
      with self.cached_session():
  def testOverLargeSeqRaiseErrorForFractionalMaxPoolGrad(self):
    with self.assertRaises(errors.InvalidArgumentError):
      with self.cached_session():
        overlapping = False
        orig_input = [[[[1, 1, 1, 1, 1]]]]
        orig_output = [[[[1, 1, 1]]]]
        out_backprop = [[[[3], [3], [6]]]]
        row_pooling_sequence = [-0x4000000, 1, 1]
        col_pooling_sequence = [-0x4000000, 1, 1]
        t = gen_nn_ops.FractionalMaxPoolGrad(
            orig_input=orig_input,
            orig_output=orig_output,
            out_backprop=out_backprop,
            row_pooling_sequence=row_pooling_sequence,
            col_pooling_sequence=col_pooling_sequence,
            overlapping=overlapping)
        self.evaluate(t)