The following issues were found

caffe2/quantization/server/resize_nearest_dnnlowp_op.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 37 Column: 14 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                    const int in_y = std::min((int)(y / height_scale_), (IH - 1));
      for (int x = 0; x < OW; ++x) {
        const int in_x = std::min((int)(x / width_scale_), (IW - 1));
        std::memcpy(
            &Y_data[((n * OH + y) * OW + x) * C],
            &X_data[((n * IH + in_y) * IW + in_x) * C],
            C * sizeof(T));
      }
    }

            

Reported by FlawFinder.

caffe2/quantization/server/resize_nearest_3d_dnnlowp_op.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 43 Column: 16 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                      const int in_y = std::min((int)(y / height_scale_), (IH - 1));
        for (int x = 0; x < OW; ++x) {
          const int in_x = std::min((int)(x / width_scale_), (IW - 1));
          std::memcpy(
              &Y_data[((((n * OF) + t) * OH + y) * OW + x) * C],
              &X_data[((((n * IF) + in_f) * IH + in_y) * IW + in_x) * C],
              C * sizeof(T));
        }
      }

            

Reported by FlawFinder.

test/cpp/tensorexpr/test_graph_opt.cpp
1 issues
syntax error
Error

Line: 33

                bool old_cat_wo_conditionals_;
};

TEST_F(GraphOpt, OptimizeCat) {
#ifdef TORCH_ENABLE_LLVM
  const auto graph_string = R"IR(
    graph(%x : Float(10, strides=[1], device=cpu),
          %y : Float(20, strides=[1], device=cpu),
          %z : Float(30, strides=[1], device=cpu)):

            

Reported by Cppcheck.

caffe2/quantization/server/relu_dnnlowp_op.cc
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 45 Column: 12 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                const int N = X.numel();
  if (in_qparams.zero_point == std::numeric_limits<T>::lowest()) {
    if (Y_data != X_data) {
      std::memcpy(Y_data, X_data, N * sizeof(T));
    }
  } else {
    if (GetCpuId().avx2()) {
      internal::ReluAVX2<T>(N, in_qparams.zero_point, X_data, Y_data);
    } else {

            

Reported by FlawFinder.

caffe2/quantization/server/mmio.h
1 issues
fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 27 Column: 16 CWE codes: 362

                if (dumped_matrix_names.find(name) == dumped_matrix_names.end()) {
    dumped_matrix_names.insert(name);

    FILE* fp = fopen((matrix_name + ".mtx").c_str(), "w");
    if (!fp) {
      return;
    }

    if (is_integral<T>::value) {

            

Reported by FlawFinder.

test/cpp/tensorexpr/test_external_calls.cpp
1 issues
syntax error
Error

Line: 22

              namespace jit {
using namespace torch::jit::tensorexpr;

TEST(ExternalCall, Conv2d_float) {
  KernelScope kernel_scope;

  Placeholder Input("Input", kFloat, {1, 3, 224, 224});
  Placeholder Weight("Weight", kFloat, {16, 3, 3, 3});
  Placeholder Bias("Bias", kFloat, {16});

            

Reported by Cppcheck.

test/cpp/tensorexpr/test_expr.cpp
1 issues
syntax error
Error

Line: 26

              
using SimpleIRExprEval = ExprEval<SimpleIREvaluator>;

TEST(Expr, BasicValueTest) {
  KernelScope kernel_scope;
  ExprHandle a = IntImm::make(2), b = IntImm::make(3);
  ExprHandle c = Add::make(a, b);
  SimpleIRExprEval eval(c);
  ASSERT_EQ(eval.value<int>(), 5);

            

Reported by Cppcheck.

test/cpp/tensorexpr/test_cuda.cpp
1 issues
syntax error
Error

Line: 95

                return 1.0f / (1.0f + expf(-0.0f - x));
}

TEST(Cuda, Sigmoid_CUDA) {
  KernelScope kernel_scope;
  const int num_iter = 3;
  const int block_count = 16;
  const int block_size = 128;
  Dtype dtype = ToDtype<float>();

            

Reported by Cppcheck.

test/cpp/tensorexpr/test_cpp_codegen.cpp
1 issues
syntax error
Error

Line: 15

              
using namespace torch::jit::tensorexpr;

TEST(CppPrinter, AllocateOnStackThenFree) {
  KernelScope kernel_scope;
  std::vector<ExprPtr> dims = {alloc<IntImm>(2), alloc<IntImm>(3)};
  BufPtr buf = alloc<Buf>("x", dims, kInt);
  AllocatePtr alloc_ = alloc<Allocate>(buf);
  FreePtr free_ = alloc<Free>(buf);

            

Reported by Cppcheck.

caffe2/quantization/server/kl_minimization_example.cc
1 issues
atoi - Unless checked, the resulting number can exceed the expected range
Security

Line: 20 Column: 40 CWE codes: 190
Suggestion: If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)

              
  ifstream in(argv[1]);
  ofstream out(argv[2]);
  bool preserve_sparsity = argc >= 4 ? atoi(argv[3]) : false;

  string line;
  while (getline(in, line)) {
    istringstream ist(line);


            

Reported by FlawFinder.