The following issues were found

.circleci/codegen_validation/normalize_yaml_fragment.py
4 issues
Unable to import 'cimodel.lib.miniyaml'
Error

Line: 10 Column: 1

              # Need to import modules that lie on an upward-relative path
sys.path.append(os.path.join(sys.path[0], '..'))

import cimodel.lib.miniyaml as miniyaml


def regurgitate(depth, use_pyyaml_formatter=False):
    data = yaml.safe_load(sys.stdin)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import os
import sys
import yaml

# Need to import modules that lie on an upward-relative path
sys.path.append(os.path.join(sys.path[0], '..'))


            

Reported by Pylint.

Import "import cimodel.lib.miniyaml as miniyaml" should be placed at the top of the module
Error

Line: 10 Column: 1

              # Need to import modules that lie on an upward-relative path
sys.path.append(os.path.join(sys.path[0], '..'))

import cimodel.lib.miniyaml as miniyaml


def regurgitate(depth, use_pyyaml_formatter=False):
    data = yaml.safe_load(sys.stdin)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              import cimodel.lib.miniyaml as miniyaml


def regurgitate(depth, use_pyyaml_formatter=False):
    data = yaml.safe_load(sys.stdin)

    if use_pyyaml_formatter:
        output = yaml.dump(data, sort_keys=True)
        sys.stdout.write(output)

            

Reported by Pylint.

android/test_app/make_assets.py
4 issues
Unable to import 'torch'
Error

Line: 1 Column: 1

              import torch
import torchvision

print(torch.version.__version__)

resnet18 = torchvision.models.resnet18(pretrained=True)
resnet18.eval()
resnet18_traced = torch.jit.trace(resnet18, torch.rand(1, 3, 224, 224)).save("app/src/main/assets/resnet18.pt")


            

Reported by Pylint.

Unable to import 'torchvision'
Error

Line: 2 Column: 1

              import torch
import torchvision

print(torch.version.__version__)

resnet18 = torchvision.models.resnet18(pretrained=True)
resnet18.eval()
resnet18_traced = torch.jit.trace(resnet18, torch.rand(1, 3, 224, 224)).save("app/src/main/assets/resnet18.pt")


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import torch
import torchvision

print(torch.version.__version__)

resnet18 = torchvision.models.resnet18(pretrained=True)
resnet18.eval()
resnet18_traced = torch.jit.trace(resnet18, torch.rand(1, 3, 224, 224)).save("app/src/main/assets/resnet18.pt")


            

Reported by Pylint.

Line too long (111/100)
Error

Line: 8 Column: 1

              
resnet18 = torchvision.models.resnet18(pretrained=True)
resnet18.eval()
resnet18_traced = torch.jit.trace(resnet18, torch.rand(1, 3, 224, 224)).save("app/src/main/assets/resnet18.pt")

resnet50 = torchvision.models.resnet50(pretrained=True)
resnet50.eval()
torch.jit.trace(resnet50, torch.rand(1, 3, 224, 224)).save("app/src/main/assets/resnet50.pt")


            

Reported by Pylint.

caffe2/contrib/tensorrt/tensorrt_tranformer.cc
4 issues
Uninitialized variable: data
Error

Line: 56 CWE codes: 908

                const auto len = cpu_tensor.size();
  if (cpu_tensor.template IsType<float>()) {
    t->set_data_type(::ONNX_NAMESPACE::TensorProto::FLOAT);
    const float* data = cpu_tensor.template data<float>();
    for (auto i = 0; i < len; ++i) {
      t->add_float_data(*data++);
    }
  } else if (cpu_tensor.template IsType<int64_t>()) {
    t->set_data_type(::ONNX_NAMESPACE::TensorProto::INT64);

            

Reported by Cppcheck.

Uninitialized variable: data
Error

Line: 62 CWE codes: 908

                  }
  } else if (cpu_tensor.template IsType<int64_t>()) {
    t->set_data_type(::ONNX_NAMESPACE::TensorProto::INT64);
    const int64_t* data = cpu_tensor.template data<int64_t>();
    for (auto i = 0; i < len; ++i) {
      t->add_int64_data(*data++);
    }
  } else if (cpu_tensor.template IsType<int32_t>()) {
    t->set_data_type(::ONNX_NAMESPACE::TensorProto::INT32);

            

Reported by Cppcheck.

Uninitialized variable: data
Error

Line: 68 CWE codes: 908

                  }
  } else if (cpu_tensor.template IsType<int32_t>()) {
    t->set_data_type(::ONNX_NAMESPACE::TensorProto::INT32);
    const int32_t* data = cpu_tensor.template data<int32_t>();
    for (auto i = 0; i < len; ++i) {
      t->add_int32_data(*data++);
    }
  } else {
    CAFFE_THROW(

            

Reported by Cppcheck.

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

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

                      tf.set_data_type(::ONNX_NAMESPACE::TensorProto::FLOAT);
        std::vector<int64_t> v;
        v.resize(t.raw_data().size() / sizeof(int64_t));
        memcpy(v.data(), t.raw_data().data(), t.raw_data().size());
        std::vector<float> vf;
        for (auto i : v) {
          vf.push_back(static_cast<float>(i));
        }
        tf.mutable_raw_data()->assign(

            

Reported by FlawFinder.

caffe2/python/layers/build_index.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              




import numpy as np

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

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 26 Column: 9

                      name='map_to_range',
        **kwargs
    ):
        super(MapToRange, self).__init__(model, name, input_record, **kwargs)

        assert max_index > 0
        assert isinstance(input_record, schema.Scalar)

        self.max_index = max_index

            

Reported by Pylint.

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

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

                  ):
        super(MapToRange, self).__init__(model, name, input_record, **kwargs)

        assert max_index > 0
        assert isinstance(input_record, schema.Scalar)

        self.max_index = max_index

        self.handler = self.create_param(

            

Reported by Bandit.

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

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

                      super(MapToRange, self).__init__(model, name, input_record, **kwargs)

        assert max_index > 0
        assert isinstance(input_record, schema.Scalar)

        self.max_index = max_index

        self.handler = self.create_param(
            param_name='handler',

            

Reported by Bandit.

caffe2/core/blob_test.cc
4 issues
syntax error
Error

Line: 108

                EXPECT_FALSE(blob.IsType<int>());
}

TEST(BlobTest, BlobUninitialized) {
  Blob blob;
  // NOLINTNEXTLINE(hicpp-avoid-goto,cppcoreguidelines-avoid-goto)
  ASSERT_THROW(blob.Get<int>(), EnforceNotMet);
}


            

Reported by Cppcheck.

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

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

                qtensor->SetBias(-1.337);
  qtensor->Resize(std::vector<int>{2, 3});
  // "Randomly" set bits.
  srand(0);
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 5; ++j) {
      // NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.rand)
      qtensor->SetBitAtIndex(j, i, rand() % 2);
    }

            

Reported by FlawFinder.

tmpnam - Temporary file race condition
Security

Line: 910 Column: 35 CWE codes: 377

                    ? FLAGS_caffe2_test_big_tensor_size / d1
      : static_cast<int64_t>(std::numeric_limits<int>::max()) + 1;
  int64_t size = d1 * d2;
  string db_source = (string)std::tmpnam(nullptr);
  VLOG(1) << "db_source: " << db_source;

  {
    VLOG(1) << "Test begin";
    Blob blob;

            

Reported by FlawFinder.

tmpnam - Temporary file race condition
Security

Line: 1031 Column: 35 CWE codes: 377

                  DummyTypeDeserializer);

TEST(ContentChunks, Serialization) {
  string db_source = (string)std::tmpnam(nullptr);
  VLOG(1) << "db_source: " << db_source;

  {
    VLOG(1) << "Test begin";
    Blob blob;

            

Reported by FlawFinder.

.circleci/cimodel/data/simple/util/docker_constants.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              AWS_DOCKER_HOST = "308535385114.dkr.ecr.us-east-1.amazonaws.com"

def gen_docker_image(container_type):
    return (
        "/".join([AWS_DOCKER_HOST, "pytorch", container_type]),
        f"docker-{container_type}",
    )

def gen_docker_image_requires(image_name):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 3 Column: 1

              AWS_DOCKER_HOST = "308535385114.dkr.ecr.us-east-1.amazonaws.com"

def gen_docker_image(container_type):
    return (
        "/".join([AWS_DOCKER_HOST, "pytorch", container_type]),
        f"docker-{container_type}",
    )

def gen_docker_image_requires(image_name):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

                      f"docker-{container_type}",
    )

def gen_docker_image_requires(image_name):
    return [f"docker-{image_name}"]


DOCKER_IMAGE_BASIC, DOCKER_REQUIREMENT_BASE = gen_docker_image(
    "pytorch-linux-xenial-py3.6-gcc5.4"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

              )


def gen_mobile_docker(specifier):
    container_type = "pytorch-linux-xenial-py3-clang5-" + specifier
    return gen_docker_image(container_type)


DOCKER_IMAGE_ASAN, DOCKER_REQUIREMENT_ASAN = gen_mobile_docker("asan")

            

Reported by Pylint.

caffe2/python/layers/bpr_loss.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

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





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

            

Reported by Pylint.

Missing class docstring
Error

Line: 19 Column: 1

              

# ref: https://arxiv.org/pdf/1205.2618.pdf
class BPRLoss(ModelLayer):

    def __init__(self, model, input_record, name='bpr_loss', **kwargs):
        super(BPRLoss, self).__init__(model, name, input_record, **kwargs)
        assert schema.is_schema_subset(
            schema.Struct(

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 22 Column: 9

              class BPRLoss(ModelLayer):

    def __init__(self, model, input_record, name='bpr_loss', **kwargs):
        super(BPRLoss, self).__init__(model, name, input_record, **kwargs)
        assert schema.is_schema_subset(
            schema.Struct(
                ('pos_prediction', schema.Scalar()),
                ('neg_prediction', schema.List(np.float32)),
            ),

            

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='bpr_loss', **kwargs):
        super(BPRLoss, self).__init__(model, name, input_record, **kwargs)
        assert schema.is_schema_subset(
            schema.Struct(
                ('pos_prediction', schema.Scalar()),
                ('neg_prediction', schema.List(np.float32)),
            ),
            input_record

            

Reported by Bandit.

.circleci/cimodel/data/simple/mobile_definitions.py
4 issues
Missing class docstring
Error

Line: 15 Column: 1

              )


class MobileJob:
    def __init__(
            self,
            docker_image,
            docker_requires,
            variant_parts,

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 15 Column: 1

              )


class MobileJob:
    def __init__(
            self,
            docker_image,
            docker_requires,
            variant_parts,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 5

                      self.variant_parts = variant_parts
        self.is_master_only = is_master_only

    def gen_tree(self):
        non_phase_parts = [
            "pytorch",
            "linux",
            "xenial",
            "py3",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 85 Column: 1

              ]


def get_workflow_jobs():
    return [item.gen_tree() for item in WORKFLOW_DATA]

            

Reported by Pylint.

caffe2/python/modeling/net_modifier.py
4 issues
Unexpected keyword argument 'modify_output_record' in method call
Error

Line: 29 Column: 9

              
    def __call__(self, net, init_net=None, grad_map=None, blob_to_device=None,
                 modify_output_record=False):
        self.modify_net(
            net,
            init_net=init_net,
            grad_map=grad_map,
            blob_to_device=blob_to_device,
            modify_output_record=modify_output_record)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import abc


class NetModifier(metaclass=abc.ABCMeta):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 5

                      pass

    @abc.abstractmethod
    def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None):
        pass

    def __call__(self, net, init_net=None, grad_map=None, blob_to_device=None,
                 modify_output_record=False):
        self.modify_net(

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 27 Column: 5

                  def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None):
        pass

    def __call__(self, net, init_net=None, grad_map=None, blob_to_device=None,
                 modify_output_record=False):
        self.modify_net(
            net,
            init_net=init_net,
            grad_map=grad_map,

            

Reported by Pylint.

caffe2/python/models/__sym_init__.py
4 issues
TODO(bwasti): A more robust handler for pathnames.
Error

Line: 11 Column: 3

              
def _parseFile(filename):
    out_net = caffe2_pb2.NetDef()
    # TODO(bwasti): A more robust handler for pathnames.
    dir_path = os.path.dirname(__file__)
    with open('{dir_path}/{filename}'.format(dir_path=dir_path,
                                             filename=filename), 'rb') as f:
        out_net.ParseFromString(f.read())
    return out_net

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              



import os
from caffe2.proto import caffe2_pb2


def _parseFile(filename):

            

Reported by Pylint.

Function name "_parseFile" doesn't conform to snake_case naming style
Error

Line: 9 Column: 1

              from caffe2.proto import caffe2_pb2


def _parseFile(filename):
    out_net = caffe2_pb2.NetDef()
    # TODO(bwasti): A more robust handler for pathnames.
    dir_path = os.path.dirname(__file__)
    with open('{dir_path}/{filename}'.format(dir_path=dir_path,
                                             filename=filename), 'rb') as f:

            

Reported by Pylint.

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

Line: 14 Column: 75

                  # TODO(bwasti): A more robust handler for pathnames.
    dir_path = os.path.dirname(__file__)
    with open('{dir_path}/{filename}'.format(dir_path=dir_path,
                                             filename=filename), 'rb') as f:
        out_net.ParseFromString(f.read())
    return out_net


init_net = _parseFile('init_net.pb')

            

Reported by Pylint.