The following issues were found

c10/util/SmallVector.h
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                  // use memcpy here. Note that Iit and Eit are iterators and thus might be
    // invalid for memcpy if they are equal.
    if (Iit != Eit)
      memcpy(Dest, Iit, (Eit - Iit) * sizeof(T));
  }

  /// Double the size of the allocated memory, guaranteeing space for at
  /// least one more element or MinSize if specified.
  void grow(size_t MinSize = 0) {

            

Reported by FlawFinder.

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

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

                void push_back(const T& Elt) {
    if (this->EndX >= this->CapacityX)
      this->grow();
    memcpy(this->end(), &Elt, sizeof(T));
    this->setEnd(this->end() + 1);
  }

  void pop_back() {
    this->setEnd(this->end() - 1);

            

Reported by FlawFinder.

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

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

                bool operator==(const SmallVectorImpl& RHS) const {
    if (this->size() != RHS.size())
      return false;
    return std::equal(this->begin(), this->end(), RHS.begin());
  }
  bool operator!=(const SmallVectorImpl& RHS) const {
    return !(*this == RHS);
  }


            

Reported by FlawFinder.

aten/src/ATen/native/quantized/cpu/qconcat.cpp
3 issues
syntax error
Error

Line: 128

              
} // namespace

TORCH_LIBRARY_IMPL(quantized, QuantizedCPU, m) {
  m.impl(TORCH_SELECTIVE_NAME("quantized::cat"), TORCH_FN(qcat<false>));
  m.impl(TORCH_SELECTIVE_NAME("quantized::cat_relu"), TORCH_FN(qcat<true>));
  m.impl(TORCH_SELECTIVE_NAME("quantized::cat_out"), TORCH_FN(qcat_out<false>));
  m.impl(TORCH_SELECTIVE_NAME("quantized::cat_relu_out"), TORCH_FN(qcat_out<true>));
}

            

Reported by Cppcheck.

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

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

                    is_valid |= qxs[i].q_scale() == qxs[0].q_scale();
      is_valid |= qxs[i].q_zero_point() == qxs[0].q_zero_point();
    } else if (qxs[0].qscheme() == kPerChannelAffine) {
      is_valid |= qxs[i].q_per_channel_scales().equal(qxs[0].q_per_channel_scales());
      is_valid |= qxs[i].q_per_channel_zero_points().equal(qxs[0].q_per_channel_zero_points());
    } else {
      TORCH_CHECK(false, "Unrecognized qscheme:", toString(qxs[0].qscheme()));
    }
  }

            

Reported by FlawFinder.

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

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

                    is_valid |= qxs[i].q_zero_point() == qxs[0].q_zero_point();
    } else if (qxs[0].qscheme() == kPerChannelAffine) {
      is_valid |= qxs[i].q_per_channel_scales().equal(qxs[0].q_per_channel_scales());
      is_valid |= qxs[i].q_per_channel_zero_points().equal(qxs[0].q_per_channel_zero_points());
    } else {
      TORCH_CHECK(false, "Unrecognized qscheme:", toString(qxs[0].qscheme()));
    }
  }
  return is_valid;

            

Reported by FlawFinder.

aten/src/ATen/native/quantized/cpu/qembeddingbag.cpp
3 issues
syntax error
Error

Line: 853

                }
};

TORCH_LIBRARY_IMPL(quantized, CPU, m) {
  // Function that works on TorchBind packed weights.
  m.impl(
      TORCH_SELECTIVE_NAME("quantized::embedding_bag_byte"),
      TORCH_FN(QEmbeddingBag<8>::run));
  m.impl(

            

Reported by Cppcheck.

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

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

                  // Avoid `null pointer passed as argument 2` ASAN violation when offsets
    // tensor is empty.
    if (M > 0) {
      std::memcpy(
          offsets_include_last_val.data(),
          offsets_data,
          sizeof(OffsetType) * M);
    }
    offsets_include_last_val[M] = indices.numel();

            

Reported by FlawFinder.

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

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

                  // Avoid `null pointer passed as argument 2` ASAN violation when offsets
    // tensor is empty.
    if (M > 0) {
      std::memcpy(
          offsets_include_last_val.data(),
          offsets_data,
          sizeof(OffsetType) * M);
    }
    offsets_include_last_val[M] = indices.numel();

            

Reported by FlawFinder.

caffe2/python/hip_test_util.py
3 issues
Missing function or method docstring
Error

Line: 16 Column: 1

              
from caffe2.proto import caffe2_pb2

def run_in_hip(gc, dc):
    return (gc.device_type == caffe2_pb2.HIP) or (
        caffe2_pb2.HIP in {d.device_type for d in dc})

            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

              
from caffe2.proto import caffe2_pb2

def run_in_hip(gc, dc):
    return (gc.device_type == caffe2_pb2.HIP) or (
        caffe2_pb2.HIP in {d.device_type for d in dc})

            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

              
from caffe2.proto import caffe2_pb2

def run_in_hip(gc, dc):
    return (gc.device_type == caffe2_pb2.HIP) or (
        caffe2_pb2.HIP in {d.device_type for d in dc})

            

Reported by Pylint.

benchmarks/instruction_counts/main.py
3 issues
Unused argument 'argv'
Error

Line: 19 Column: 10

              from execution.work import WorkOrder


def main(argv: List[str]) -> None:
    work_orders = tuple(
        WorkOrder(label, autolabels, timer_args, timeout=600, retries=2)
        for label, autolabels, timer_args in materialize(BENCHMARKS)
    )


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              from execution.work import WorkOrder


def main(argv: List[str]) -> None:
    work_orders = tuple(
        WorkOrder(label, autolabels, timer_args, timeout=600, retries=2)
        for label, autolabels, timer_args in materialize(BENCHMARKS)
    )


            

Reported by Pylint.

Line too long (123/100)
Error

Line: 27 Column: 1

              
    results = Runner(work_orders).run()
    for work_order in work_orders:
        print(work_order.label, work_order.autolabels, work_order.timer_args.num_threads, results[work_order].instructions)


if __name__ == "__main__":
    modes = {
        "debug": main,

            

Reported by Pylint.

aten/src/ATen/native/quantized/cpu/qnnpack/deps/clog/configure.py
3 issues
Unable to import 'confu'
Error

Line: 9 Column: 1

              # This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import confu
parser = confu.standard_parser("clog configuration script")


def main(args):
    options = parser.parse_args(args)

            

Reported by Pylint.

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 confu

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              parser = confu.standard_parser("clog configuration script")


def main(args):
    options = parser.parse_args(args)
    build = confu.Build.from_options(options)

    build.export_cpath("include", ["clog.h"])


            

Reported by Pylint.

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

Line: 1 Column: 1

              ## @package extension_loader
# Module caffe2.python.extension_loader




import contextlib
import ctypes
import sys

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              

@contextlib.contextmanager
def DlopenGuard(extra_flags=ctypes.RTLD_GLOBAL):
    if _set_global_flags:
        old_flags = sys.getdlopenflags()
        sys.setdlopenflags(old_flags | extra_flags)

    # in case we dlopen something that doesn't exist, yield will fail and throw;

            

Reported by Pylint.

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

Line: 17 Column: 1

              

@contextlib.contextmanager
def DlopenGuard(extra_flags=ctypes.RTLD_GLOBAL):
    if _set_global_flags:
        old_flags = sys.getdlopenflags()
        sys.setdlopenflags(old_flags | extra_flags)

    # in case we dlopen something that doesn't exist, yield will fail and throw;

            

Reported by Pylint.

aten/src/ATen/native/quantized/cpu/qupsample_nearest2d.cpp
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

              
  // special case: just copy
  if (input_height == output_height && input_width == output_width) {
    std::memcpy(o_p, i_p, channels * input_height * input_width * sizeof(typename scalar_t::underlying));
    return;
  }

  for (int64_t h2 = 0; h2 < output_height; ++h2) {
    const int64_t h1 =

            

Reported by FlawFinder.

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

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

                  auto* o_p = reinterpret_cast<typename scalar_t::underlying*>(odata + b * output_height * output_width * channels);
    // special case: just copy
    if (input_height == output_height && input_width == output_width) {
      std::memcpy(o_p, i_p, channels * input_height * input_width * sizeof(typename scalar_t::underlying));
      return;
    }

    for (int64_t h2 = 0; h2 < output_height; ++h2) {
      const int64_t h1 =

            

Reported by FlawFinder.

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

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

              
        const auto* pos1 = &i_p[(h1 * input_width + w1)*channels];
        auto* pos2 = &o_p[(h2 * output_width + w2)*channels];
        std::memcpy(pos2, pos1, channels * sizeof(typename scalar_t::underlying));
      }
    }
  }
}


            

Reported by FlawFinder.

caffe2/python/helpers/elementwise_linear.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              ## @package elementwise_linear
# Module caffe2.python.helpers.elementwise_linear





from caffe2.python import core
from caffe2.python.modeling.parameter_info import ParameterTags

            

Reported by Pylint.

Too many arguments (7/5)
Error

Line: 12 Column: 1

              from caffe2.python.modeling.parameter_info import ParameterTags


def _elementwise_linear(
    model, op_call, blob_in, blob_out, dim,
    weight_init=None, bias_init=None, **kwargs
):
    """Elementwise_Linear"""
    weight_init = weight_init or ('ConstantFill', {'value': 1.0})

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 44 Column: 1

                  return op_call([blob_in, weight, bias], blob_out, **kwargs)


def elementwise_linear(model, *args, **kwargs):
    return _elementwise_linear(
        model, model.net.ElementwiseLinear, *args, **kwargs)

            

Reported by Pylint.

caffe2/python/helpers/db_input.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              ## @package db_input
# Module caffe2.python.helpers.db_input





def db_input(model, blobs_out, batch_size, db, db_type):
    dbreader_name = "dbreader_" + db

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              


def db_input(model, blobs_out, batch_size, db, db_type):
    dbreader_name = "dbreader_" + db
    dbreader = model.param_init_net.CreateDB(
        [],
        dbreader_name,
        db=db,

            

Reported by Pylint.

Argument name "db" doesn't conform to snake_case naming style
Error

Line: 8 Column: 1

              


def db_input(model, blobs_out, batch_size, db, db_type):
    dbreader_name = "dbreader_" + db
    dbreader = model.param_init_net.CreateDB(
        [],
        dbreader_name,
        db=db,

            

Reported by Pylint.