The following issues were found

tools/code_coverage/package/tool/parser/coverage_record.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              import typing as t


class CoverageRecord(t.NamedTuple):
    filepath: str
    covered_lines: t.List[int]
    uncovered_lines: t.Optional[t.List[int]] = None

    def to_dict(self) -> t.Dict[str, t.Any]:

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              import typing as t


class CoverageRecord(t.NamedTuple):
    filepath: str
    covered_lines: t.List[int]
    uncovered_lines: t.Optional[t.List[int]] = None

    def to_dict(self) -> t.Dict[str, t.Any]:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

                  covered_lines: t.List[int]
    uncovered_lines: t.Optional[t.List[int]] = None

    def to_dict(self) -> t.Dict[str, t.Any]:
        return {
            "filepath": self.filepath,
            "covered_lines": self.covered_lines,
            "uncovered_lines": self.uncovered_lines,
        }

            

Reported by Pylint.

caffe2/serialize/file_adapter.cc
3 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: 12 Column: 9 CWE codes: 362

              namespace serialize {

FileAdapter::RAIIFile::RAIIFile(const std::string& file_name) {
  fp_ = fopen(file_name.c_str(), "rb");
  if (fp_ == nullptr) {
    char buf[1024];
    buf[0] = '\0';
#if defined(_WIN32) && (defined(__MINGW32__) || defined(_MSC_VER))
  strerror_s(buf, sizeof(buf), errno);

            

Reported by FlawFinder.

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

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

              FileAdapter::RAIIFile::RAIIFile(const std::string& file_name) {
  fp_ = fopen(file_name.c_str(), "rb");
  if (fp_ == nullptr) {
    char buf[1024];
    buf[0] = '\0';
#if defined(_WIN32) && (defined(__MINGW32__) || defined(_MSC_VER))
  strerror_s(buf, sizeof(buf), errno);
#else
  strerror_r(errno, buf, sizeof(buf));

            

Reported by FlawFinder.

read - Check buffer boundaries if used in a loop including recursive loops
Security

Line: 55 Column: 21 CWE codes: 120 20

                return size_;
}

size_t FileAdapter::read(uint64_t pos, void* buf, size_t n, const char* what)
    const {
  // Ensure that pos doesn't exceed size_.
  pos = std::min(pos, size_);
  // If pos doesn't exceed size_, then size_ - pos can never be negative (in
  // signed math) or since these are unsigned values, a very large value.

            

Reported by FlawFinder.

ios/TestApp/custom_build/custom_build.py
3 issues
Unable to import 'torch'
Error

Line: 1 Column: 1

              import torch
import torchvision
import yaml

model = torchvision.models.mobilenet_v2(pretrained=True)
model.eval()
example = torch.rand(1, 3, 224, 224)
traced_script_module = torch.jit.trace(model, example)
ops = torch.jit.export_opnames(traced_script_module)

            

Reported by Pylint.

Unable to import 'torchvision'
Error

Line: 2 Column: 1

              import torch
import torchvision
import yaml

model = torchvision.models.mobilenet_v2(pretrained=True)
model.eval()
example = torch.rand(1, 3, 224, 224)
traced_script_module = torch.jit.trace(model, example)
ops = torch.jit.export_opnames(traced_script_module)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import torch
import torchvision
import yaml

model = torchvision.models.mobilenet_v2(pretrained=True)
model.eval()
example = torch.rand(1, 3, 224, 224)
traced_script_module = torch.jit.trace(model, example)
ops = torch.jit.export_opnames(traced_script_module)

            

Reported by Pylint.

test/cpp/api/autograd.cpp
3 issues
equal - Function does not check the second iterator for over-read conditions
Security

Line: 467 Column: 22 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 out = Inplace::apply(x,y);
  auto &q = out[0];
  ASSERT_TRUE(torch::equal(q, x));
  ASSERT_TRUE(q.requires_grad());
  q.sum().backward();
  ASSERT_VARIABLE_EQ(y.grad(), torch::ones({5,5}));
}


            

Reported by FlawFinder.

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

Line: 492 Column: 22 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

                // TODO ASSERT_THROWS_WITH(DoubleInplace::apply(x.clone()[0]), "only one output");

  auto out = DoubleInplace::apply(x.clone());
  ASSERT_TRUE(torch::equal(out[0],out[1]));
}

TEST(CustomAutogradTest, ReturnDuplicate) {
  struct DoubleDuplicate : public Function<DoubleDuplicate> {
    static variable_list forward(AutogradContext *ctx, Variable x) {

            

Reported by FlawFinder.

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

Line: 509 Column: 22 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 x = torch::randn({5,5}, torch::requires_grad());
  auto out = DoubleDuplicate::apply(x);
  ASSERT_TRUE(torch::equal(out[0],out[1]));
}

TEST(CustomAutogradTest, SaveEmptyForBackward) {
  struct MyFunction : public Function<MyFunction> {
    static Variable forward(AutogradContext *ctx, Variable input) {

            

Reported by FlawFinder.

caffe2/python/predictor_constants.py
3 issues
Unable to import 'caffe2.proto.predictor_consts_pb2'
Error

Line: 7 Column: 1

              


import caffe2.proto.predictor_consts_pb2 as predictor_consts

predictor_constants = predictor_consts.PredictorConsts()

            

Reported by Pylint.

No name 'predictor_consts_pb2' in module 'caffe2.proto'
Error

Line: 7 Column: 1

              


import caffe2.proto.predictor_consts_pb2 as predictor_consts

predictor_constants = predictor_consts.PredictorConsts()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              ## @package predictor_constants
# Module caffe2.python.predictor_constants




import caffe2.proto.predictor_consts_pb2 as predictor_consts

predictor_constants = predictor_consts.PredictorConsts()

            

Reported by Pylint.

caffe2/quantization/server/observer_test.py
3 issues
No name 'dnnlowp_pybind11' in module 'caffe2.quantization.server'
Error

Line: 5 Column: 1

              
import numpy as np
from caffe2.python import core, workspace
from caffe2.quantization.server import dnnlowp_pybind11  # type: ignore[attr-defined]


net = core.Net("test_net")

X = np.array([[1, 2], [3, 4]]).astype(np.float32)

            

Reported by Pylint.

Access to a protected member _net of a client class
Error

Line: 41 Column: 5

              workspace.FeedBlob("b", b)

dnnlowp_pybind11.AddOutputColumnMaxHistogramObserver(
    net._net.name, "test_net._col_max_hist", ["Y"]
)
workspace.RunNet(net)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              

import numpy as np
from caffe2.python import core, workspace
from caffe2.quantization.server import dnnlowp_pybind11  # type: ignore[attr-defined]


net = core.Net("test_net")


            

Reported by Pylint.

caffe2/python/operator_test/mul_gradient_benchmark.py
3 issues
Redefining name 'args' from outer scope (line 48)
Error

Line: 12 Column: 28

              from caffe2.python import core, workspace


def benchmark_mul_gradient(args):
    workspace.FeedBlob("dC", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("A", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("B", np.random.rand(args.n).astype(np.float32))

    net = core.Net("mynet")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import argparse
import numpy as np

from caffe2.python import core, workspace

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              from caffe2.python import core, workspace


def benchmark_mul_gradient(args):
    workspace.FeedBlob("dC", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("A", np.random.rand(args.m, args.n).astype(np.float32))
    workspace.FeedBlob("B", np.random.rand(args.n).astype(np.float32))

    net = core.Net("mynet")

            

Reported by Pylint.

caffe2/python/operator_test/data_couple_op_test.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import core, workspace
from caffe2.python.test_util import TestCase
import numpy as np


            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              import numpy as np


class TestDataCoupleOp(TestCase):

    def test_data_couple_op(self):
        param_array = np.random.rand(10, 10)
        gradient_array = np.random.rand(10, 10)
        extra_array = np.random.rand(10, 10)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 5

              
class TestDataCoupleOp(TestCase):

    def test_data_couple_op(self):
        param_array = np.random.rand(10, 10)
        gradient_array = np.random.rand(10, 10)
        extra_array = np.random.rand(10, 10)
        workspace.FeedBlob("param", param_array)
        workspace.FeedBlob("gradient", gradient_array)

            

Reported by Pylint.

caffe2/python/predictor/serde.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              ## @package serde
# Module caffe2.python.predictor.serde






def serialize_protobuf_struct(protobuf_struct):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              


def serialize_protobuf_struct(protobuf_struct):
    return protobuf_struct.SerializeToString()


def deserialize_protobuf_struct(serialized_protobuf, struct_type):
    deser = struct_type()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

                  return protobuf_struct.SerializeToString()


def deserialize_protobuf_struct(serialized_protobuf, struct_type):
    deser = struct_type()
    deser.ParseFromString(serialized_protobuf)
    return deser

            

Reported by Pylint.

test/distributed/launcher/bin/test_script_local_rank.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import argparse

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              import os


def parse_args():
    parser = argparse.ArgumentParser(description="test script")

    parser.add_argument(
        "--local_rank",
        type=int,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

                  return parser.parse_args()


def main():
    print("Start execution")
    args = parse_args()
    expected_rank = int(os.environ["LOCAL_RANK"])
    actual_rank = args.local_rank
    if expected_rank != actual_rank:

            

Reported by Pylint.