The following issues were found

caffe2/contrib/playground/compute_loss.py
3 issues
__init__ method from base class 'Meter' is not called
Error

Line: 11 Column: 5

              

class ComputeLoss(Meter.Meter):
    def __init__(self, opts=None, blob_name=''):
        self.blob_name = blob_name
        self.opts = opts
        self.iter = 0
        self.value = 0


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import caffe2.contrib.playground.meter as Meter
from caffe2.python import workspace



            

Reported by Pylint.

Missing class docstring
Error

Line: 10 Column: 1

              from caffe2.python import workspace


class ComputeLoss(Meter.Meter):
    def __init__(self, opts=None, blob_name=''):
        self.blob_name = blob_name
        self.opts = opts
        self.iter = 0
        self.value = 0

            

Reported by Pylint.

caffe2/python/ideep_test_util.py
3 issues
Unable to import 'hypothesis.strategies'
Error

Line: 14 Column: 1

              


import hypothesis.strategies as st

from caffe2.proto import caffe2_pb2
from caffe2.python import hypothesis_test_util as hu

cpu_do = hu.cpu_do

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              device_options = hu.device_options + ([ideep_do])


def device_checker_device_options():
    return st.just(device_options)


def gradient_checker_device_option():
    return st.sampled_from(device_options)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

                  return st.just(device_options)


def gradient_checker_device_option():
    return st.sampled_from(device_options)


gcs = dict(
    gc=gradient_checker_device_option(),

            

Reported by Pylint.

c10/util/Backtrace.cpp
3 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 122 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              const int max_name_len = 256;
std::string get_module_base_name(void* addr) {
  HMODULE h_module;
  char module[max_name_len];
  strcpy(module, "");
  GetModuleHandleEx(
      GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
          GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
      (LPCTSTR)addr,

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 270 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

                DWORD disp;
  std::unique_ptr<IMAGEHLP_LINE64> line;

  char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
  PSYMBOL_INFO p_symbol = (PSYMBOL_INFO)buffer;

  std::unique_ptr<void*[]> back_trace(new void*[maximum_number_of_frames]);
  bool with_symbol = false;
  bool with_line = false;

            

Reported by FlawFinder.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 123 Column: 3 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

              std::string get_module_base_name(void* addr) {
  HMODULE h_module;
  char module[max_name_len];
  strcpy(module, "");
  GetModuleHandleEx(
      GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
          GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
      (LPCTSTR)addr,
      &h_module);

            

Reported by FlawFinder.

.github/scripts/parse_ref.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import os
import re


def main() -> None:
    ref = os.environ['GITHUB_REF']
    m = re.match(r'^refs/(\w+)/(.*)$', ref)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              import re


def main() -> None:
    ref = os.environ['GITHUB_REF']
    m = re.match(r'^refs/(\w+)/(.*)$', ref)
    if m:
        category, stripped = m.groups()
        if category == 'heads':

            

Reported by Pylint.

Variable name "m" doesn't conform to snake_case naming style
Error

Line: 9 Column: 5

              
def main() -> None:
    ref = os.environ['GITHUB_REF']
    m = re.match(r'^refs/(\w+)/(.*)$', ref)
    if m:
        category, stripped = m.groups()
        if category == 'heads':
            print(f'::set-output name=branch::{stripped}')
        elif category == 'pull':

            

Reported by Pylint.

caffe2/python/convert_test.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import workspace
import unittest

class TestOperator(unittest.TestCase):

            

Reported by Pylint.

standard import "import unittest" should be placed before "from caffe2.python import workspace"
Error

Line: 7 Column: 1

              

from caffe2.python import workspace
import unittest

class TestOperator(unittest.TestCase):
    def setUp(self):
        workspace.ResetWorkspace()


            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from caffe2.python import workspace
import unittest

class TestOperator(unittest.TestCase):
    def setUp(self):
        workspace.ResetWorkspace()

if __name__ == '__main__':
    unittest.main()

            

Reported by Pylint.

c10/util/order_preserving_flat_hash_map.h
3 issues
equal - Function does not check the second iterator for over-read conditions
Security

Line: 272 Column: 48 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : EntryAlloc(alloc), Hasher(hash), Equal(equal) {
    rehash(bucket_count);
  }
  sherwood_v3_table(size_type bucket_count, const ArgumentAlloc& alloc)
      : sherwood_v3_table(
            bucket_count,

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 295 Column: 47 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : sherwood_v3_table(bucket_count, hash, equal, alloc) {
    insert(first, last);
  }
  template <typename It>
  sherwood_v3_table(
      It first,

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 331 Column: 47 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : sherwood_v3_table(bucket_count, hash, equal, alloc) {
    if (bucket_count == 0)
      rehash(il.size());
    insert(il.begin(), il.end());
  }
  sherwood_v3_table(

            

Reported by FlawFinder.

aten/src/ATen/native/vulkan/ops/Convolution.cpp
3 issues
syntax error
Error

Line: 499

              
#ifdef USE_VULKAN_API

TORCH_LIBRARY_IMPL(aten, Vulkan, m) {
  m.impl("convolution_overrideable", convolution);
}

#endif /* USE_VULKAN_API */


            

Reported by Cppcheck.

memcpy - Does not check for buffer overflows when copying to destination
Security

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

                                                  dst_oh * dst_kw_sz;

    for (int64_t src_ih = 0; src_ih < src_filter[Layout::Filter::height]; ++src_ih) {
      memcpy(
          dst_weight_c_ptr + src_ih * src_kw_sz,
          src_weight_oc_ptr + src_ih * src_kw_sz,
          sizeof(float) * src_kw_sz);
    }
  }

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

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

              
      for (int64_t src_ih = 0; src_ih < src_kh_sz; ++src_ih) {
        for (int64_t src_iw = 0; src_iw < src_kw_sz; ++src_iw) {
          memcpy(
              dst_weight_c_ptr + (dst_oh * src_kh_sz + src_ih) * dst_kw_sz +
                dst_ic4 * src_kw_sz * 4 + src_iw * 4 + src_ic % 4,
              src_weight_oc_ptr + src_ic * src_kernel_sz + src_ih * src_kw_sz + src_iw,
              sizeof(float));
        }

            

Reported by FlawFinder.

aten/src/ATen/test/cuda_dlconvertor_test.cpp
3 issues
equal - Function does not check the second iterator for over-read conditions
Security

Line: 24 Column: 17 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

              
  Tensor b = fromDLPack(dlMTensor);

  ASSERT_TRUE(a.equal(b));
}

TEST(TestDlconvertor, TestDlconvertorNoStridesCUDA) {
  manual_seed(123);


            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 36 Column: 17 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

              
  Tensor b = fromDLPack(dlMTensor);

  ASSERT_TRUE(a.equal(b));
}

TEST(TestDlconvertor, TestDlconvertorCUDAHIP) {
  if (!at::cuda::is_available())
    return;

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 55 Column: 17 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

              
  Tensor b = fromDLPack(dlMTensor);

  ASSERT_TRUE(a.equal(b));
}

            

Reported by FlawFinder.

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

Line: 45 Column: 11 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

              }

TORCH_IMPL_FUNC(pow_Tensor_Scalar_out) (const Tensor& base, const Scalar& exp, const Tensor& out) {
  if (exp.equal(0.0)) {
    out.fill_(1);
  } else if (exp.equal(1.0)) {
    out.copy_(base);
  } else {
    pow_tensor_scalar_stub(device_type(), *this, exp);

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 47 Column: 18 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

              TORCH_IMPL_FUNC(pow_Tensor_Scalar_out) (const Tensor& base, const Scalar& exp, const Tensor& out) {
  if (exp.equal(0.0)) {
    out.fill_(1);
  } else if (exp.equal(1.0)) {
    out.copy_(base);
  } else {
    pow_tensor_scalar_stub(device_type(), *this, exp);
  }
}

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 55 Column: 12 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

              }

TORCH_IMPL_FUNC(pow_Scalar_out) (const Scalar& base, const Tensor& exp, const Tensor& out) {
  if (base.equal(1.0)) {
    out.fill_(1);
  } else {
    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
    at::pow_out(const_cast<Tensor&>(out), wrapped_scalar_tensor(base, exp.device()), exp); // redispatch!
  }

            

Reported by FlawFinder.

c10/util/flat_hash_map.h
3 issues
equal - Function does not check the second iterator for over-read conditions
Security

Line: 266 Column: 48 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : EntryAlloc(alloc), Hasher(hash), Equal(equal) {
    rehash(bucket_count);
  }
  sherwood_v3_table(size_type bucket_count, const ArgumentAlloc& alloc)
      : sherwood_v3_table(
            bucket_count,

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 289 Column: 47 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : sherwood_v3_table(bucket_count, hash, equal, alloc) {
    insert(first, last);
  }
  template <typename It>
  sherwood_v3_table(
      It first,

            

Reported by FlawFinder.

equal - Function does not check the second iterator for over-read conditions
Security

Line: 325 Column: 47 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

                    const ArgumentHash& hash = ArgumentHash(),
      const ArgumentEqual& equal = ArgumentEqual(),
      const ArgumentAlloc& alloc = ArgumentAlloc())
      : sherwood_v3_table(bucket_count, hash, equal, alloc) {
    if (bucket_count == 0)
      rehash(il.size());
    insert(il.begin(), il.end());
  }
  sherwood_v3_table(

            

Reported by FlawFinder.