hitoshura25/cvefixes huggingface dataset:
CVE-2023-25664 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Prior to versions 2.12.0 and 2.11.1, there is a heap buffer overflow in TAvgPoolGrad. A fix is included in TensorFlow 2.12.0 and 2.11.1.

Severity: nan (CVSS v3 base score: 9.8)
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/core/kernels/avgpooling_op.cc
tensorflow/python/kernel_tests/nn_ops/pooling_ops_test.py
Commit message: Add inputs check for AvgPoolGrad

PiperOrigin-RevId: 488975844


Vulnerable code:

Fixed code:
    for (int64_t r = 0; r < out_backprop_rows; ++r) {
      int rindex, rsize;
      OP_REQUIRES_OK(context,
                     GetBroadcastSize(r, in_rows, window_rows, row_stride,
                                      pad_rows, &rindex, &rsize));
      for (int64_t c = 0; c < out_backprop_cols; ++c) {
        int cindex, csize;
        OP_REQUIRES_OK(context,
                       GetBroadcastSize(c, in_cols, window_cols, col_stride,
                                        pad_cols, &cindex, &csize));
      }
    }

  def testAvgPoolGradInvalidStrideRaiseErrorProperly(self):
    with self.assertRaises(errors_impl.InvalidArgumentError):
      with self.cached_session():
        orig_input_shape = [11, 9, 78, 9]
        grad = constant_op.constant(
            0.1, shape=[16, 16, 16, 16], dtype=dtypes.float64)
        t = gen_nn_ops.AvgPoolGrad(
            orig_input_shape=orig_input_shape,
            grad=grad,
            ksize=[1, 40, 128, 1],
            strides=[1, 128, 128, 30],
            padding="SAME",
            data_format="NHWC")
        self.evaluate(t)
CVE-2023-25664 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Prior to versions 2.12.0 and 2.11.1, there is a heap buffer overflow in TAvgPoolGrad. A fix is included in TensorFlow 2.12.0 and 2.11.1.

Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-122 \u2014 Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
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: Add inputs check for AvgPoolGrad

PiperOrigin-RevId: 488975844


Vulnerable code:

Fixed code:
    for (int64_t r = 0; r < out_backprop_rows; ++r) {
      int rindex, rsize;
      OP_REQUIRES_OK(context,
                     GetBroadcastSize(r, in_rows, window_rows, row_stride,
                                      pad_rows, &rindex, &rsize));
      for (int64_t c = 0; c < out_backprop_cols; ++c) {
        int cindex, csize;
        OP_REQUIRES_OK(context,
                       GetBroadcastSize(c, in_cols, window_cols, col_stride,
                                        pad_cols, &cindex, &csize));
      }
    }

  def testAvgPoolGradInvalidStrideRaiseErrorProperly(self):
    with self.assertRaises(errors_impl.InvalidArgumentError):
      with self.cached_session():
        orig_input_shape = [11, 9, 78, 9]
        grad = constant_op.constant(
            0.1, shape=[16, 16, 16, 16], dtype=dtypes.float64)
        t = gen_nn_ops.AvgPoolGrad(
            orig_input_shape=orig_input_shape,
            grad=grad,
            ksize=[1, 40, 128, 1],
            strides=[1, 128, 128, 30],
            padding="SAME",
            data_format="NHWC")
        self.evaluate(t)
CVE-2023-25666 (C++, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Prior to versions 2.12.0 and 2.11.1, there is a floating point exception in AudioSpectrogram. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-697 \u2014 Incorrect Comparison
The product compares two entities in a security-relevant context, but the comparison is incorrect, which may lead to resultant weaknesses.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/kernels/BUILD
tensorflow/core/kernels/spectrogram_op_test.cc
tensorflow/core/ops/audio_ops.cc
Commit message: Fix audio spectrogram FPE.

Do input validation in shape function.

PiperOrigin-RevId: 503481241


Vulnerable code:

Fixed code:
        "//tensorflow/core/platform:status_matchers",
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/tsl/lib/core/status_test_util.h"
#include "tensorflow/tsl/platform/errors.h"
#include "tensorflow/tsl/platform/status_matchers.h"
TEST(SpectrogramOpTest, InvalidWindowSize) {
  Scope root = Scope::NewRootScope();
  const int audio_size = 8;
  const int channel_size = 2;
  Tensor audio_tensor(DT_FLOAT, TensorShape({audio_size, channel_size}));
  test::FillValues<float>(
      &audio_tensor, {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
                      -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f});
  Output audio_const_op = Const(root.WithOpName("audio_const_op"),
                                Input::Initializer(audio_tensor));
  AudioSpectrogram spectrogram_op =
      AudioSpectrogram(root.WithOpName("spectrogram_op"), audio_const_op,
                       /*window_size=*/1, /*stride=*/1);
  EXPECT_THAT(root.status(),
              tsl::testing::StatusIs(tsl::error::Code::INVALID_ARGUMENT,
                                     ::testing::ContainsRegex("window size")));
}

TEST(SpectrogramOpTest, InvalidStride) {
  Scope root = Scope::NewRootScope();
  const int audio_size = 8;
  const int channel_size = 2;
  Tensor audio_tensor(DT_FLOAT, TensorShape({audio_size, channel_size}));
  test::FillValues<float>(
      &audio_tensor, {-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
                      -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f});
  Output audio_const_op = Const(root.WithOpName("audio_const_op"),
                                Input::Initializer(audio_tensor));
  AudioSpectrogram spectrogram_op =
      AudioSpectrogram(root.WithOpName("spectrogram_op"), audio_const_op,
                       /*window_size=*/2, /*stride=*/0);
  EXPECT_THAT(root.status(),
              tsl::testing::StatusIs(tsl::error::Code::INVALID_ARGUMENT,
                                     ::testing::ContainsRegex("stride")));
}

#include "tensorflow/core/platform/errors.h"
  if (window_size <= 1) {
    return errors::InvalidArgument("window size must be > 1, got ",
                                   window_size);
  }

  if (stride <= 0) {
    return errors::InvalidArgument("stride must be strictly positive, got ",
                                   stride);
  }
CVE-2023-25667 (C++, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Prior to versions 2.12.0 and 2.11.1, integer overflow occurs when `2^31 <= num_frames * height * width * channels < 2^32`, for example Full HD screencast of at least 346 frames. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

Severity: nan (CVSS v3 base score: 7.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/image/decode_image_op.cc
tensorflow/core/lib/gif/gif_io.cc
tensorflow/core/lib/gif/gif_io_test.cc
tensorflow/core/lib/gif/testdata/BUILD
Commit message: Fix integer overflow for multiframe gifs.


Vulnerable code:
    int buffer_size = 0;
          buffer_size = num_frames * height * width * channels;
  for (int k = 0; k < target_num_frames; k++) {
      for (int i = 0; i < height; ++i) {
        for (int j = 0; j < width; ++j) {
        for (int i = 0; i < height; ++i) {
          for (int j = 0; j < width; ++j) {
    for (int i = imgTop; i < imgBottom; ++i) {
      for (int j = imgLeft; j < imgRight; ++j) {
        return new uint8[frame_cnt * height * width * channels];
       {testdata_path + "squares.gif", 2, 16, 16, 3}});

Fixed code:
    ptrdiff_t buffer_size = 0;
          buffer_size = ptrdiff_t(num_frames) * height * width * channels;
  for (ptrdiff_t k = 0; k < target_num_frames; k++) {
      for (ptrdiff_t i = 0; i < height; ++i) {
        for (ptrdiff_t j = 0; j < width; ++j) {
        for (ptrdiff_t i = 0; i < height; ++i) {
          for (ptrdiff_t j = 0; j < width; ++j) {
    for (ptrdiff_t i = imgTop; i < imgBottom; ++i) {
      for (ptrdiff_t j = imgLeft; j < imgRight; ++j) {
        return new uint8[ptrdiff_t(frame_cnt) * height * width * channels];
       {testdata_path + "squares.gif", 2, 16, 16, 3},
       {testdata_path + "3g_multiframe.gif", 519, 1920, 1080, 3}});
        "3g_multiframe.gif",
CVE-2023-25670 (Unknown, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Versions prior to 2.12.0 and 2.11.1 have a null point error in QuantizedMatMulWithBiasAndDequantize with MKL enabled. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

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:
Commit message: Merge pull request #59437 from Intel-tensorflow:amin/fix-qmatmul

PiperOrigin-RevId: 504745468


Vulnerable code:

Fixed code:
CVE-2023-25671 (Other, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. There is out-of-bounds access due to mismatched integer type sizes. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-787 \u2014 Out-of-bounds Write
The product writes data past the end, or before the beginning, of the intended buffer.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/ir/importexport/BUILD
tensorflow/core/ir/importexport/tfg-translate.cc
Commit message: tfg-translate needs to call InitMlir

PiperOrigin-RevId: 504566500


Vulnerable code:

Fixed code:
        "//tensorflow/compiler/mlir:init_mlir",
#include "tensorflow/compiler/mlir/init_mlir.h"
  tensorflow::InitMlir y(&argc, &argv);
CVE-2023-25671 (Other, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. There is out-of-bounds access due to mismatched integer type sizes. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-787 \u2014 Out-of-bounds Write
The product writes data past the end, or before the beginning, of the intended buffer.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/ir/importexport/functiondef_import.cc
tensorflow/core/ir/importexport/tests/graphdef_to_mlir/invalid_generic_function_named_edge_index.pbtxt
Commit message: [tfg] Fix out-of-bounds access due to mismatched integer type sizes in ValueMap::Manager::GetValueOrCreatePlaceholder

PiperOrigin-RevId: 497419488


Vulnerable code:
  Value GetValueOrCreatePlaceholder(StringRef full_name) {
    int output_num = 0;
                                        10, value))
          output_num = value;
      state.operands.push_back(
          value_manager.GetValueOrCreatePlaceholder(input));
    ret_vals[position->second] =
        value_manager.GetValueOrCreatePlaceholder(ret_val.second);
    Value result = value_manager.GetValueOrCreatePlaceholder(
        (Twine("^") + ret_val.second).str());

Fixed code:
  tensorflow::StatusOr<Value> GetValueOrCreatePlaceholder(StringRef full_name) {
    size_t output_num = 0;
                                        10, value)) {
          if (LLVM_LIKELY(
                  value <=
                  std::numeric_limits<llvm::SmallVectorSizeType<Value>>::max() -
                      1))
            output_num = value;
          else
            return InvalidArgument("Output index ", value,
                                   " is invalid (too large)");
        }
      TF_ASSIGN_OR_RETURN(Value value,
                          value_manager.GetValueOrCreatePlaceholder(input));
      state.operands.push_back(value);
    TF_ASSIGN_OR_RETURN(
        ret_vals[position->second],
        value_manager.GetValueOrCreatePlaceholder(ret_val.second));
    TF_ASSIGN_OR_RETURN(Value result, value_manager.GetValueOrCreatePlaceholder(
                                          (Twine("^") + ret_val.second).str()));
# RUN: not tfg-translate -graphdef-to-mlir %s 2>&1 | FileCheck %s

# CHECK: Output index 18446744073709551615 is invalid (too large)

library {
  function {
    signature {
      name: "foo"
      attr {
        name: "T"
        type: "type"
      }
    }
    node_def {
      name: "two"
      op: "Const"
      attr {
        key: "dtype"
        value {
          type: DT_INT64
        }
      }
      attr {
        key: "value"
        value {
          tensor {
            dtype: DT_INT64
            tensor_shape {}
            int64_val: 2
          }
        }
      }
    }
    node_def {
      name: "a"
      op: "Cast"
      input: "two:output:18446744073709551615"
      attr {
        key: "DstT"
        value {
          placeholder: "T"
        }
      }
      attr {
        key: "SrcT"
        value {
          type: DT_INT64
        }
      }
    }
  }
}
CVE-2023-25672 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. The function `tf.raw_ops.LookupTableImportV2` cannot handle scalars in the `values` parameter and gives an NPE. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

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/ops/lookup_ops.cc
tensorflow/python/kernel_tests/data_structures/lookup_ops_test.py
Commit message: Fixes shape inference of LookupTableImportV2 to handle scalar values.

PiperOrigin-RevId: 506126405


Vulnerable code:
      TF_RETURN_IF_ERROR(
          c->Merge(c->Dim(keys, 0), c->Dim(c->input(2), 0), &unused));

Fixed code:
      ShapeHandle values;
      TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(2), 1, &values));
      TF_RETURN_IF_ERROR(c->Merge(c->Dim(keys, 0), c->Dim(values, 0), &unused));
from tensorflow.python.ops import gen_lookup_ops
  def testImportShapeInference(self, is_anonymous):
    v = variables.Variable(1)

    @def_function.function(jit_compile=True)
    def foo():
      return gen_lookup_ops.lookup_table_import_v2(
          table_handle=v.handle, keys=[1.1, 2.2], values=1
      )

    with self.assertRaisesRegex(
        ValueError, r"Shape must be at least rank 1 but is rank 0"
    ):
      foo()
CVE-2023-25673 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source platform for machine learning. Versions prior to 2.12.0 and 2.11.1 have a Floating Point Exception in TensorListSplit with XLA. A fix is included in TensorFlow version 2.12.0 and version 2.11.1.

Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-697 \u2014 Incorrect Comparison
The product compares two entities in a security-relevant context, but the comparison is incorrect, which may lead to resultant weaknesses.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/compiler/tests/tensor_list_ops_test.py
tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc
Commit message: [Tensorflow] Fix security vulnerability with TensorListSplitOp

PiperOrigin-RevId: 506441188


Vulnerable code:

Fixed code:
  def testInvalidSplitLength(self):
    with self.session(), self.test_scope():
      tensor_list_split = list_ops.tensor_list_split(
          tensor=[1], element_shape=[-1], lengths=[0]
      )
      with self.assertRaisesRegex(
          errors.UnimplementedError, "All lengths must be positive"
      ):
        self.evaluate(tensor_list_split)


    OP_REQUIRES(ctx, length,
                errors::Unimplemented("All lengths must be positive"));
CVE-2023-25674 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source machine learning platform. Versions prior to 2.12.0 and 2.11.1 have a null pointer error in RandomShuffle with XLA enabled. A fix is included in TensorFlow 2.12.0 and 2.11.1.
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/compiler/tests/tensor_list_ops_test.py
tensorflow/compiler/tf2xla/kernels/tensor_list_ops.cc
Commit message: [Tensorflow] Fix security vulnerability with TensorListSplitOp

PiperOrigin-RevId: 506441188


Vulnerable code:

Fixed code:
  def testInvalidSplitLength(self):
    with self.session(), self.test_scope():
      tensor_list_split = list_ops.tensor_list_split(
          tensor=[1], element_shape=[-1], lengths=[0]
      )
      with self.assertRaisesRegex(
          errors.UnimplementedError, "All lengths must be positive"
      ):
        self.evaluate(tensor_list_split)


    OP_REQUIRES(ctx, length,
                errors::Unimplemented("All lengths must be positive"));
CVE-2023-25675 (Other, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source machine learning platform. When running versions prior to 2.12.0 and 2.11.1 with XLA, `tf.raw_ops.Bincount` segfaults when given a parameter `weights` that is neither the same shape as parameter `arr` nor a length-0 tensor. A fix is included in TensorFlow 2.12.0 and 2.11.1.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-697 \u2014 Incorrect Comparison
The product compares two entities in a security-relevant context, but the comparison is incorrect, which may lead to resultant weaknesses.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/compiler/tests/BUILD
tensorflow/compiler/tests/bincount_op_test.py
tensorflow/compiler/tf2xla/kernels/bincount_op.cc
Commit message: [Tensorflow] Fix security vulnerability with DenseBincountOp

PiperOrigin-RevId: 506514542


Vulnerable code:
    auto size = input_shape.dimensions(0);
    if (!size) {
      output = xla::Broadcast(zero, {output_size});
      ctx->SetOutput(0, output);
      return;
    }


Fixed code:

tf_xla_py_test(
    name = "bincount_op_test",
    size = "small",
    srcs = ["bincount_op_test.py"],
    enable_mlir_bridge = False,
    python_version = "PY3",
    shard_count = 10,
    tags = [
        "no_pip",  # TODO(b/149738646): fix pip install so these tests run on kokoro pip
    ],
    deps = [
        ":xla_test",
        "//tensorflow/python:platform_test",
    ],
)
# Copyright 2023 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for bincount using the XLA JIT."""
from tensorflow.compiler.tests import xla_test
from tensorflow.python.framework import errors
from tensorflow.python.ops import gen_math_ops
from tensorflow.python.platform import googletest


class BincountTest(xla_test.XLATestCase):

  def testInputRank0(self):
    with self.session():
      with self.test_scope():
        bincount = gen_math_ops.bincount(arr=6, size=804, weights=[52, 351])

      with self.assertRaisesRegex(
          errors.InvalidArgumentError,
          (
              "`weights` must be the same shape as `arr` or a length-0"
              " `Tensor`, in which case it acts as all weights equal to 1."
          ),
      ):
        self.evaluate(bincount)


if __name__ == "__main__":
  googletest.main()

    auto size = input_shape.dimensions(0);

    if (!size) {
      output = xla::Broadcast(zero, {output_size});
      ctx->SetOutput(0, output);
      return;
    }
CVE-2023-25676 (Python, published 2023-03-25T00:15Z)
Description: value: TensorFlow is an open source machine learning platform. When running versions prior to 2.12.0 and 2.11.1 with XLA, `tf.raw_ops.ParallelConcat` segfaults with a nullptr dereference when given a parameter `shape` with rank that is not greater than zero. A fix is available in TensorFlow 2.12.0 and 2.11.1.
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/inplace_ops.cc
tensorflow/core/ops/array_ops.cc
tensorflow/python/kernel_tests/array_ops/stack_op_test.py
tensorflow/python/ops/array_ops_test.py
Commit message: Check for unexpected scalars in the shape argument to ParallelConcat.

PiperOrigin-RevId: 504901518


Vulnerable code:
                                " is less than loc_=", loc_));
    with self.assertRaisesRegex(errors.InvalidArgumentError,
                                r"0th dimension of value .* is less than"):

Fixed code:
                                " must be greater than loc_ = ", loc_));
#include <vector>
        if (c->Rank(c->input(i)) < 1) {
          return errors::InvalidArgument(
              "The rank of all input shapes must be greater than 0, "
              "but input ",
              i, " had rank ", c->Rank(c->input(i)), ".");
        }
    with self.assertRaisesRegex(
        errors.InvalidArgumentError, r"0th dimension .* must be greater than"
    ):
from tensorflow.python.framework import test_util
  @test_util.run_in_graph_and_eager_modes
  def testParallelConcatFailsWithRankZeroShape(self):
    op = array_ops.ParallelConcat
    para = {"shape": 0, "values": [1]}

    def func():
      y = op(**para)
      return y

    with self.assertRaisesRegex(
        Exception, "(rank|dimension) of .* must be greater than .* 0"
    ):
      func()