The following issues were found

aten/src/ATen/native/Unique.cpp
1 issues
equal - Function does not check the second iterator for over-read conditions
Security

Line: 147 Column: 16 CWE codes: 126
Suggestion: This function is often discouraged by most C++ coding standards in favor of its safer alternatives provided since C++14. Consider using a form of this function that checks the second iterator before potentially overflowing it

              
    ForwardIt result = first;
    while (++first != last) {
      if (!at::equal(*result, *first) && ++result != first) {
          *result = std::move(*first);
      }
      int64_t idx_result = std::distance(begin, result);
      int64_t idx_first = std::distance(begin, first);
      inverse_indices_vec[indices[idx_first]] = idx_result;

            

Reported by FlawFinder.

aten/src/ATen/native/Unfold3d.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

              template <typename T>
void MatCopy(int64_t M, int64_t N, int64_t lda, int64_t ldb, const T* A, T* B) {
  for (int64_t i = 0; i < M; ++i) {
    std::memcpy(B + i * ldb, A + i * lda, N * sizeof(T));
  }
}

template <typename T>
void MatCopy(

            

Reported by FlawFinder.

aten/src/ATen/native/TensorShape.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                      static_cast<void*>(local_dst_offset_bytes + dst_block_size_bytes) <=
        static_cast<void*>(dst_bytes + dst_nbytes));

    memcpy(
        local_dst_offset_bytes, local_src_offset_bytes, dst_block_size_bytes);
  }
  return output;
}


            

Reported by FlawFinder.

aten/src/ATen/native/RowwisePrune.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                  int last_row_kept = 0;
    for (int i = 0; i < mask.numel(); i++) {
      if (mask_data[i]) {
        memcpy(pruned_2d_tensor_data + last_row_kept * num_cols,
              weights_data + i * num_cols,
              num_cols * sizeof (scalar_t));
        compressed_indices_mapping_data[i] = last_row_kept;
        last_row_kept++;
      } else {

            

Reported by FlawFinder.

aten/src/ATen/native/Resize.cpp
1 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                storage->set_nbytes(size_bytes);
  const auto copy_capacity = std::min(size_bytes, old_capacity);
  if (old_data != nullptr && copy_capacity > 0) {
    memcpy(storage->data(), old_data.get(), copy_capacity);
  }
}

// Call the sparse implementation in SparseTensor.cpp directly.
// A dynamic dispatch here is NOT necessary, so I didn't put

            

Reported by FlawFinder.

aten/src/ATen/native/RNN.cpp
1 issues
syntax error
Error

Line: 1998

                            return cell_params_deserializers[type](std::move(state));
            });

TORCH_LIBRARY_FRAGMENT(aten, m) {
  m.def(
      TORCH_SELECTIVE_SCHEMA("aten::quantized_lstm.input(Tensor input, Tensor[] hx, __torch__.torch.classes.rnn.CellParamsBase[] params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional, bool batch_first, *, ScalarType? dtype=None, bool use_dynamic=False) -> (Tensor, Tensor, Tensor)"));
  m.def(
      TORCH_SELECTIVE_SCHEMA("aten::quantized_lstm.data(Tensor data, Tensor batch_sizes, Tensor[] hx, __torch__.torch.classes.rnn.CellParamsBase[] params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional, *, ScalarType? dtype=None, bool use_dynamic=False) -> (Tensor, Tensor, Tensor)"));
  m.def(

            

Reported by Cppcheck.

aten/src/ATen/native/NegateFallback.cpp
1 issues
syntax error
Error

Line: 26

                object.fallback_impl(op, dispatch_keys, stack);
}

TORCH_LIBRARY_IMPL(_, Negative, m) {
  m.fallback(torch::CppFunction::makeFromBoxedFunction<&negationFallback>());
}

TORCH_LIBRARY_IMPL(aten, Negative, m) {
  m.impl("requires_grad_", torch::CppFunction::makeFallthrough());

            

Reported by Cppcheck.

aten/src/ATen/native/DispatchStub.cpp
1 issues
getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 12 Column: 21 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              namespace at { namespace native {

static CPUCapability compute_cpu_capability() {
  auto envar = std::getenv("ATEN_CPU_CAPABILITY");
  if (envar) {
#ifdef HAVE_VSX_CPU_DEFINITION
    if (strcmp(envar, "vsx") == 0) {
      return CPUCapability::VSX;
    }

            

Reported by FlawFinder.

aten/src/ATen/core/type.cpp
1 issues
getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 14 Column: 41 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              namespace c10 {

TypeVerbosity type_verbosity() {
  static const char* c_verbosity = std::getenv("PYTORCH_JIT_TYPE_VERBOSITY");
  static TypeVerbosity verbosity = c_verbosity ?
    static_cast<TypeVerbosity>(c10::stoi(c_verbosity)) : TypeVerbosity::Default;
  return verbosity;
}


            

Reported by FlawFinder.

aten/src/ATen/core/op_registration/op_registration_test.cpp
1 issues
syntax error
Error

Line: 49

                bool* called_;
};

TEST(OperatorRegistrationTest, whenRegisteringWithSchemaBeforeKernelInOptionsObject_thenCanBeCalled) {
  bool called = false;
  auto registrar = c10::RegisterOperators().op(c10::RegisterOperators::options().schema("_test::dummy(Tensor dummy) -> ()").catchAllKernel<MockKernel>(&called));

  auto op = Dispatcher::singleton().findSchema({"_test::dummy", ""});
  ASSERT_TRUE(op.has_value());

            

Reported by Cppcheck.