The following issues were found
tools/code_coverage/package/tool/parser/coverage_record.py
3 issues
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.
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.
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
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.
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.
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
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.
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.
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
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.
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.
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
Line: 7
Column: 1
import caffe2.proto.predictor_consts_pb2 as predictor_consts
predictor_constants = predictor_consts.PredictorConsts()
Reported by Pylint.
Line: 7
Column: 1
import caffe2.proto.predictor_consts_pb2 as predictor_consts
predictor_constants = predictor_consts.PredictorConsts()
Reported by Pylint.
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
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.
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.
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
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.
Line: 1
Column: 1
import argparse
import numpy as np
from caffe2.python import core, workspace
Reported by Pylint.
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
Line: 1
Column: 1
from caffe2.python import core, workspace
from caffe2.python.test_util import TestCase
import numpy as np
Reported by Pylint.
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.
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
Line: 1
Column: 1
## @package serde
# Module caffe2.python.predictor.serde
def serialize_protobuf_struct(protobuf_struct):
Reported by Pylint.
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.
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
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.
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.
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.