The following issues were found

aten/src/TH/THGeneral.cpp
6 issues
vsnprintf - If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate
Security

Line: 44 Column: 11 CWE codes: 134
Suggestion: Use a constant for the format specification

                /* vasprintf not standard */
  /* vsnprintf: how to handle if does not exists? */
  va_start(args, fmt);
  int n = vsnprintf(msg, 2048, fmt, args);
  va_end(args);

  if(n < 2048) {
    snprintf(msg + n, 2048 - n, " at %s:%d", file, line);
  }

            

Reported by FlawFinder.

vsnprintf - If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate
Security

Line: 63 Column: 3 CWE codes: 134
Suggestion: Use a constant for the format specification

                char msg[1024];
  va_list args;
  va_start(args, fmt);
  vsnprintf(msg, 1024, fmt, args);
  va_end(args);
  _THError(file, line, "Assertion `%s' failed. %s", exp, msg);
}

/* Torch Arg Checking Handling */

            

Reported by FlawFinder.

vsnprintf - If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate
Security

Line: 92 Column: 13 CWE codes: 134
Suggestion: Use a constant for the format specification

                  /* vasprintf not standard */
    /* vsnprintf: how to handle if does not exists? */
    va_start(args, fmt);
    int n = vsnprintf(msg, 2048, fmt, args);
    va_end(args);

    if(n < 2048) {
      snprintf(msg + n, 2048 - n, " at %s:%d", file, line);
    }

            

Reported by FlawFinder.

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

Line: 38 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

              void _THError(const char *file, const int line, const char *fmt, ...)
{
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
  char msg[2048];
  va_list args;

  /* vasprintf not standard */
  /* vsnprintf: how to handle if does not exists? */
  va_start(args, fmt);

            

Reported by FlawFinder.

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

Line: 60 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

              
void _THAssertionFailed(const char *file, const int line, const char *exp, const char *fmt, ...) {
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
  char msg[1024];
  va_list args;
  va_start(args, fmt);
  vsnprintf(msg, 1024, fmt, args);
  va_end(args);
  _THError(file, line, "Assertion `%s' failed. %s", exp, msg);

            

Reported by FlawFinder.

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

Line: 86 Column: 5 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

              {
  if(!condition) {
    // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
    char msg[2048];
    va_list args;

    /* vasprintf not standard */
    /* vsnprintf: how to handle if does not exists? */
    va_start(args, fmt);

            

Reported by FlawFinder.

aten/src/ATen/native/cpu/DistributionTemplates.h
6 issues
random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 29 Column: 50 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                AT_DISPATCH_ALL_TYPES_AND3(at::ScalarType::Bool, at::ScalarType::Half, at::ScalarType::BFloat16, iter.dtype(), "random_from_to_kernel_cpu", [&] {
    std::lock_guard<std::mutex> lock(generator->mutex_);
    cpu_serial_kernel(iter, [range, base, generator]() -> scalar_t {
      uniform_int_from_to_distribution<scalar_t> random(range, base);
      return random(generator);
    });
  });
}


            

Reported by FlawFinder.

random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 30 Column: 14 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                  std::lock_guard<std::mutex> lock(generator->mutex_);
    cpu_serial_kernel(iter, [range, base, generator]() -> scalar_t {
      uniform_int_from_to_distribution<scalar_t> random(range, base);
      return random(generator);
    });
  });
}

// This is the special kernel to handle single specific case:

            

Reported by FlawFinder.

random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 47 Column: 55 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                      std::is_same<scalar_t, float>::value ||
        std::is_same<scalar_t, at::BFloat16>::value) {
      cpu_serial_kernel(iter, [generator]() -> scalar_t {
        uniform_int_full_range_distribution<scalar_t> random;
        return random(generator);
      });
    } else {
      TORCH_CHECK(false, "random_full_64_bits_range_kernel_cpu handles only int64, double, float and bfloat16");
    }

            

Reported by FlawFinder.

random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 48 Column: 16 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                      std::is_same<scalar_t, at::BFloat16>::value) {
      cpu_serial_kernel(iter, [generator]() -> scalar_t {
        uniform_int_full_range_distribution<scalar_t> random;
        return random(generator);
      });
    } else {
      TORCH_CHECK(false, "random_full_64_bits_range_kernel_cpu handles only int64, double, float and bfloat16");
    }
  });

            

Reported by FlawFinder.

random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 71 Column: 42 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                std::lock_guard<std::mutex> lock(generator->mutex_);
  AT_DISPATCH_ALL_TYPES_AND3(at::ScalarType::Half, at::ScalarType::BFloat16, at::ScalarType::Bool, iter.dtype(), "random_kernel_cpu", [&] {
    cpu_serial_kernel(iter, [generator]() -> scalar_t {
      uniform_int_distribution<scalar_t> random;
      return random(generator);
    });
  });
}


            

Reported by FlawFinder.

random - This function is not sufficiently random for security-related functions such as key and nonce creation
Security

Line: 72 Column: 14 CWE codes: 327
Suggestion: Use a more secure technique for acquiring random values

                AT_DISPATCH_ALL_TYPES_AND3(at::ScalarType::Half, at::ScalarType::BFloat16, at::ScalarType::Bool, iter.dtype(), "random_kernel_cpu", [&] {
    cpu_serial_kernel(iter, [generator]() -> scalar_t {
      uniform_int_distribution<scalar_t> random;
      return random(generator);
    });
  });
}

template<typename RNG>

            

Reported by FlawFinder.

caffe2/python/layer_model_instantiator.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              ## @package layer_model_instantiator
# Module caffe2.python.layer_model_instantiator





from caffe2.python import core, schema
from caffe2.python.layers.layers import InstantiationContext

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                  return [l for l in layers if not include_tags.isdisjoint(l.tags)]


def shrink_output_schema(net, out_schema):
    if len(out_schema.field_names()) <= 1:
        return out_schema
    exists = [net.BlobIsDefined(blob) for blob in out_schema.field_blobs()]
    return schema.from_column_list(
        [

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 44 Column: 1

                  )


def generate_predict_net(model, include_tags=None):
    predict_net = core.Net('predict_net')

    for layer in _filter_layers(model.layers, include_tags):
        if Tags.EXCLUDE_FROM_PREDICTION not in layer.tags:
            layer.add_operators(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 60 Column: 1

                  return predict_net


def generate_eval_net(model, include_tags=None):
    eval_net = core.Net('eval_net')

    for layer in _filter_layers(model.layers, include_tags):
        if Tags.EXCLUDE_FROM_EVAL not in layer.tags:
            layer.add_operators(eval_net, context=InstantiationContext.EVAL)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 93 Column: 1

                  return train_init_net, train_net


def generate_training_nets_forward_only(model, include_tags=None):
    train_init_net, train_net = _generate_training_net_only(model, include_tags)
    return train_init_net, train_net


def generate_training_nets(model, include_tags=None):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 98 Column: 1

                  return train_init_net, train_net


def generate_training_nets(model, include_tags=None):
    train_init_net, train_net = _generate_training_net_only(model, include_tags)

    model.apply_regularizers_on_loss(train_net, train_init_net)
    if not model.has_loss():
        return train_init_net, train_net

            

Reported by Pylint.

benchmarks/operator_benchmark/benchmark_test_generator.py
6 issues
Unable to import 'benchmark_core'
Error

Line: 1 Column: 1

              from benchmark_core import _register_test
from benchmark_pytorch import create_pytorch_op_test_case


def generate_pt_test(configs, pt_bench_op):
    """ This function creates PyTorch op test based on the given operator
    """
    _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False)


            

Reported by Pylint.

Unable to import 'benchmark_pytorch'
Error

Line: 2 Column: 1

              from benchmark_core import _register_test
from benchmark_pytorch import create_pytorch_op_test_case


def generate_pt_test(configs, pt_bench_op):
    """ This function creates PyTorch op test based on the given operator
    """
    _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from benchmark_core import _register_test
from benchmark_pytorch import create_pytorch_op_test_case


def generate_pt_test(configs, pt_bench_op):
    """ This function creates PyTorch op test based on the given operator
    """
    _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False)


            

Reported by Pylint.

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

Line: 38 Column: 9

                              ...
        op_bench.generate_pt_tests_from_op_list(unary_ops_list, unary_ops_configs, UnaryOpBenchmark)
    """
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False, op)

def generate_pt_gradient_tests_from_op_list(ops_list, configs, pt_bench_op):
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, True, op)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 41 Column: 1

                  for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False, op)

def generate_pt_gradient_tests_from_op_list(ops_list, configs, pt_bench_op):
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, True, op)

            

Reported by Pylint.

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

Line: 42 Column: 9

                      _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False, op)

def generate_pt_gradient_tests_from_op_list(ops_list, configs, pt_bench_op):
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, True, op)

            

Reported by Pylint.

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

Line: 58 Column: 31 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

                if (dtype == kFloat) {
    ASSERT_TRUE(exp.to(dtype).allclose(out_tensor));
  } else {
    ASSERT_TRUE(exp.to(dtype).equal(out_tensor));
  }
}

/*
  template function for running binary operator test

            

Reported by FlawFinder.

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

Line: 119 Column: 28 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

                auto a_tensor = tensor({a});
  auto b_tensor = tensor({b});

  ASSERT_TRUE(tensor({~a}).equal(~a_tensor));
  ASSERT_TRUE(tensor({a | b}).equal(a_tensor | b_tensor));
  ASSERT_TRUE(tensor({a & b}).equal(a_tensor & b_tensor));
  ASSERT_TRUE(tensor({a ^ b}).equal(a_tensor ^ b_tensor));
}


            

Reported by FlawFinder.

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

Line: 120 Column: 31 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

                auto b_tensor = tensor({b});

  ASSERT_TRUE(tensor({~a}).equal(~a_tensor));
  ASSERT_TRUE(tensor({a | b}).equal(a_tensor | b_tensor));
  ASSERT_TRUE(tensor({a & b}).equal(a_tensor & b_tensor));
  ASSERT_TRUE(tensor({a ^ b}).equal(a_tensor ^ b_tensor));
}

TEST_F(atest, logical_and_operators) {

            

Reported by FlawFinder.

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

Line: 121 Column: 31 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

              
  ASSERT_TRUE(tensor({~a}).equal(~a_tensor));
  ASSERT_TRUE(tensor({a | b}).equal(a_tensor | b_tensor));
  ASSERT_TRUE(tensor({a & b}).equal(a_tensor & b_tensor));
  ASSERT_TRUE(tensor({a ^ b}).equal(a_tensor ^ b_tensor));
}

TEST_F(atest, logical_and_operators) {
  auto exp_tensor = tensor({0, 1, 0, 1, 0});

            

Reported by FlawFinder.

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

Line: 122 Column: 31 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

                ASSERT_TRUE(tensor({~a}).equal(~a_tensor));
  ASSERT_TRUE(tensor({a | b}).equal(a_tensor | b_tensor));
  ASSERT_TRUE(tensor({a & b}).equal(a_tensor & b_tensor));
  ASSERT_TRUE(tensor({a ^ b}).equal(a_tensor ^ b_tensor));
}

TEST_F(atest, logical_and_operators) {
  auto exp_tensor = tensor({0, 1, 0, 1, 0});
  run_binary_ops_test(

            

Reported by FlawFinder.

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

Line: 246 Column: 19 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

                  }
  }

  ASSERT_TRUE(foo.equal(4 * ones({12, 6}, kByte)));

  trace();

  // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
  float data[] = {1, 2, 3, 4, 5, 6};

            

Reported by FlawFinder.

c10/test/util/string_view_test.cpp
6 issues
syntax error
Error

Line: 74

              
namespace test_string_constructor {
void test_conversion_is_implicit(string_view a) {}
TEST(StringViewTest, testStringConstructor) {
  std::string empty;
  EXPECT_EQ(0, string_view(empty).size());
  std::string hello_str = "hello";
  string_view hello_sv = hello_str;
  EXPECT_EQ(5, hello_sv.size());

            

Reported by Cppcheck.

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

Line: 330 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

              TEST(StringViewTest, whenCopyingFullStringView_thenDestinationHasCorrectData) {
  string_view data = "hello";
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays)
  char result[5];
  size_t num_copied = data.copy(result, 5);
  EXPECT_EQ(5, num_copied);
  EXPECT_TRUE(string_equal("hello", result, 5));
}


            

Reported by FlawFinder.

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

Line: 339 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

              TEST(StringViewTest, whenCopyingSubstr_thenDestinationHasCorrectData) {
  string_view data = "hello";
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
  char result[2];
  size_t num_copied = data.copy(result, 2, 2);
  EXPECT_EQ(2, num_copied);
  EXPECT_TRUE(string_equal("ll", result, 2));
}


            

Reported by FlawFinder.

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

Line: 348 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

              TEST(StringViewTest, whenCopyingTooMuch_thenJustCopiesLess) {
  string_view data = "hello";
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays)
  char result[100];
  size_t num_copied = data.copy(result, 100, 2);
  EXPECT_EQ(3, num_copied);
  EXPECT_TRUE(string_equal("llo", result, 3));
}


            

Reported by FlawFinder.

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

Line: 357 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

              TEST(StringViewTest, whenCopyingJustAtRange_thenDoesntCrash) {
  string_view data = "hello";
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
  char result[1];
  size_t num_copied = data.copy(result, 2, 5);
  EXPECT_EQ(0, num_copied);
}

TEST(StringViewTest, whenCopyingOutOfRange_thenThrows) {

            

Reported by FlawFinder.

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

Line: 365 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

              TEST(StringViewTest, whenCopyingOutOfRange_thenThrows) {
  string_view data = "hello";
  // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
  char result[2];
  expectThrows<std::out_of_range>(
      // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays)
      [&] { data.copy(result, 2, 6); },
      "basic_string_view::copy: out of range. Index: 6, size: 5");
}

            

Reported by FlawFinder.

benchmarks/overrides_benchmark/pyspybench.py
6 issues
Unable to import 'torch'
Error

Line: 1 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

Unused SubWithTorchFunction imported from common
Error

Line: 3 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

Unused WithTorchFunction imported from common
Error

Line: 3 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

Unused SubTensor imported from common
Error

Line: 3 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

standard import "import argparse" should be placed before "import torch"
Error

Line: 2 Column: 1

              import torch
import argparse
from common import SubTensor, WithTorchFunction, SubWithTorchFunction  # noqa: F401

Tensor = torch.tensor

NUM_REPEATS = 1000000

if __name__ == "__main__":

            

Reported by Pylint.

caffe2/python/layers/margin_rank_loss.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              ## @package random_neg_rank_loss
# Module caffe2.python.layers.random_neg_rank_loss





from caffe2.python import schema, core
from caffe2.python.layers.layers import (

            

Reported by Pylint.

Missing class docstring
Error

Line: 18 Column: 1

              import numpy as np


class MarginRankLoss(ModelLayer):

    def __init__(self, model, input_record, name='margin_rank_loss',
                 margin=0.1, average_loss=False, **kwargs):
        super(MarginRankLoss, self).__init__(model, name, input_record, **kwargs)
        assert margin >= 0, ('For hinge loss, margin should be no less than 0')

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 20 Column: 5

              
class MarginRankLoss(ModelLayer):

    def __init__(self, model, input_record, name='margin_rank_loss',
                 margin=0.1, average_loss=False, **kwargs):
        super(MarginRankLoss, self).__init__(model, name, input_record, **kwargs)
        assert margin >= 0, ('For hinge loss, margin should be no less than 0')
        self._margin = margin
        self._average_loss = average_loss

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 22 Column: 9

              
    def __init__(self, model, input_record, name='margin_rank_loss',
                 margin=0.1, average_loss=False, **kwargs):
        super(MarginRankLoss, self).__init__(model, name, input_record, **kwargs)
        assert margin >= 0, ('For hinge loss, margin should be no less than 0')
        self._margin = margin
        self._average_loss = average_loss
        assert schema.is_schema_subset(
            schema.Struct(

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 23
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  def __init__(self, model, input_record, name='margin_rank_loss',
                 margin=0.1, average_loss=False, **kwargs):
        super(MarginRankLoss, self).__init__(model, name, input_record, **kwargs)
        assert margin >= 0, ('For hinge loss, margin should be no less than 0')
        self._margin = margin
        self._average_loss = average_loss
        assert schema.is_schema_subset(
            schema.Struct(
                ('pos_prediction', schema.Scalar()),

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 26
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      assert margin >= 0, ('For hinge loss, margin should be no less than 0')
        self._margin = margin
        self._average_loss = average_loss
        assert schema.is_schema_subset(
            schema.Struct(
                ('pos_prediction', schema.Scalar()),
                ('neg_prediction', schema.List(np.float32)),
            ),
            input_record

            

Reported by Bandit.

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

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

                auto expected = in.add(1);                                                    \
  auto iter = TensorIterator::unary_op(out, in);                                \
  at::native::cpu_serial_kernel(iter, [=](ctype a) -> ctype { return a + 1; }); \
  ASSERT_ANY_THROW(out.equal(expected));                                        \
}

#define NO_OUTPUT_UNARY_TEST_ITER_FOR_TYPE(ctype,name)                         \
TEST(TensorIteratorTest, SerialLoopUnaryNoOutput_##name) {                     \
  auto in = random_tensor_for_type(k##name);                                   \

            

Reported by FlawFinder.

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

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

                auto expected = in1.add(in2);                                                          \
  auto iter = TensorIterator::binary_op(out, in1, in2);                                  \
  at::native::cpu_serial_kernel(iter, [=](ctype a, ctype b) -> ctype { return a + b; }); \
  ASSERT_ANY_THROW(out.equal(expected));                                                 \
}

#define NO_OUTPUT_BINARY_TEST_ITER_FOR_TYPE(ctype,name)                          \
TEST(TensorIteratorTest, SerialLoopBinaryNoOutput_##name) {                      \
  auto in1 = random_tensor_for_type(k##name);                                    \

            

Reported by FlawFinder.

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

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

                    .add_owned_input(in3)                                                                                 \
      .build();                                                                                       \
  at::native::cpu_serial_kernel(iter, [=](ctype a, ctype b, ctype c) -> ctype { return a + b + c; }); \
  ASSERT_ANY_THROW(out.equal(expected));                                                              \
}

#define NO_OUTPUT_POINTWISE_TEST_ITER_FOR_TYPE(ctype,name)                                \
TEST(TensorIteratorTest, SerialLoopPoinwiseNoOutput_##name) {                             \
  auto in1 = random_tensor_for_type(k##name);                                             \

            

Reported by FlawFinder.

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

Line: 147 Column: 19 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

                auto expected = diff.clamp_min(0).to(kBool);                                             \
  auto iter = TensorIterator::comparison_op(out, in1, in2);                                \
  at::native::cpu_serial_kernel(iter, [=](ctype a, ctype b) -> bool { return a < b; });    \
  EXPECT_TRUE(out.equal(expected));                                                        \
}

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables,hicpp-avoid-goto,cppcoreguidelines-avoid-goto)
AT_FORALL_SCALAR_TYPES(UNARY_TEST_ITER_FOR_TYPE)
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables,hicpp-avoid-goto,cppcoreguidelines-avoid-goto)

            

Reported by FlawFinder.

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

Line: 239 Column: 20 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

                  ctype mul = a * b;                                                                              \
    return std::tuple<ctype, ctype>(add, mul);                                                      \
  });                                                                                               \
  EXPECT_TRUE(out1.equal(expected1));                                                               \
  EXPECT_TRUE(out2.equal(expected2));                                                               \
}
AT_FORALL_SCALAR_TYPES(MULTIPLE_OUTPUTS_TEST_ITER_FOR_TYPE)

            

Reported by FlawFinder.

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

Line: 240 Column: 20 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

                  return std::tuple<ctype, ctype>(add, mul);                                                      \
  });                                                                                               \
  EXPECT_TRUE(out1.equal(expected1));                                                               \
  EXPECT_TRUE(out2.equal(expected2));                                                               \
}
AT_FORALL_SCALAR_TYPES(MULTIPLE_OUTPUTS_TEST_ITER_FOR_TYPE)

            

Reported by FlawFinder.

benchmarks/distributed/rpc/parameter_server/data/DummyData.py
6 issues
Unable to import 'torch'
Error

Line: 5 Column: 1

              
import numpy as np

import torch
from torch.utils.data import Dataset


class DummyData(Dataset):


            

Reported by Pylint.

Unable to import 'torch.utils.data'
Error

Line: 6 Column: 1

              import numpy as np

import torch
from torch.utils.data import Dataset


class DummyData(Dataset):

    def __init__(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import random

import numpy as np

import torch
from torch.utils.data import Dataset


class DummyData(Dataset):

            

Reported by Pylint.

Module name "DummyData" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              import random

import numpy as np

import torch
from torch.utils.data import Dataset


class DummyData(Dataset):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from torch.utils.data import Dataset


class DummyData(Dataset):

    def __init__(
        self,
        max_val: int,
        sample_count: int,

            

Reported by Pylint.

Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Security blacklist

Line: 40
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b311-random

                          elements = elements[:index_count]
            data = [
                [
                    elements[random.randint(0, index_count - 1)]
                    for _ in range(self.input_dim)
                ]
                for _ in range(self.input_samples)
            ]
            return torch.from_numpy(np.array(data))

            

Reported by Bandit.