The following issues were found

numpy/matrixlib/__init__.py
3 issues
Unable to import '__init__.defmatrix'
Error

Line: 4 Column: 1

              """Sub-package containing the matrix class and related functions.

"""
from .defmatrix import *

__all__ = defmatrix.__all__

from numpy._pytesttester import PytestTester
test = PytestTester(__name__)

            

Reported by Pylint.

Undefined variable 'defmatrix'
Error

Line: 6 Column: 11

              """
from .defmatrix import *

__all__ = defmatrix.__all__

from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester

            

Reported by Pylint.

third party import "from numpy._pytesttester import PytestTester" should be placed before "from .defmatrix import *"
Error

Line: 8 Column: 1

              
__all__ = defmatrix.__all__

from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester

            

Reported by Pylint.

numpy/core/tests/examples/setup.py
3 issues
Unable to import 'Cython.Build'
Error

Line: 8 Column: 1

              
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
from setuptools.extension import Extension
import os

macros = [("NPY_NO_DEPRECATED_API", 0)]


            

Reported by Pylint.

standard import "from distutils.core import setup" should be placed before "import numpy as np"
Error

Line: 7 Column: 1

              """

import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
from setuptools.extension import Extension
import os

macros = [("NPY_NO_DEPRECATED_API", 0)]

            

Reported by Pylint.

standard import "import os" should be placed before "import numpy as np"
Error

Line: 10 Column: 1

              from distutils.core import setup
from Cython.Build import cythonize
from setuptools.extension import Extension
import os

macros = [("NPY_NO_DEPRECATED_API", 0)]

checks = Extension(
    "checks",

            

Reported by Pylint.

numpy/core/src/multiarray/descriptor.c
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                      return NULL;
    }
    /* Don't copy PyObject_HEAD part */
    memcpy((char *)newdescr + sizeof(PyObject),
           (char *)base + sizeof(PyObject),
           sizeof(PyArray_Descr) - sizeof(PyObject));

    /*
     * The c_metadata has a by-value ownership model, need to clone it

            

Reported by FlawFinder.

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

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

                          Py_DECREF(newdescr);
            return (PyArray_Descr *)PyErr_NoMemory();
        }
        memcpy(newdescr->subarray, base->subarray, sizeof(PyArray_ArrayDescr));
        Py_INCREF(newdescr->subarray->shape);
        Py_INCREF(newdescr->subarray->base);
    }
    Py_XINCREF(newdescr->typeobj);
    Py_XINCREF(newdescr->metadata);

            

Reported by FlawFinder.

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

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

              
        old_metadata = self->metadata;
        self->metadata = PyTuple_GET_ITEM(metadata, 0);
        memcpy((char *) &((PyArray_DatetimeDTypeMetaData *)self->c_metadata)->meta,
               (char *) &temp_dt_data,
               sizeof(PyArray_DatetimeMetaData));
        Py_XINCREF(self->metadata);
        Py_XDECREF(old_metadata);
    }

            

Reported by FlawFinder.

numpy/core/src/multiarray/datetime_busday.c
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                      /* Copy the private normalized weekmask/holidays data */
        holidays = busdaycal->holidays;
        busdays_in_weekmask = busdaycal->busdays_in_weekmask;
        memcpy(weekmask, busdaycal->weekmask, 7);
    }
    else {
        /*
         * Fix up the weekmask from the uninitialized
         * signal value to a proper default.

            

Reported by FlawFinder.

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

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

                      /* Copy the private normalized weekmask/holidays data */
        holidays = busdaycal->holidays;
        busdays_in_weekmask = busdaycal->busdays_in_weekmask;
        memcpy(weekmask, busdaycal->weekmask, 7);
    }
    else {
        /*
         * Fix up the weekmask from the uninitialized
         * signal value to a proper default.

            

Reported by FlawFinder.

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

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

                      /* Copy the private normalized weekmask/holidays data */
        holidays = busdaycal->holidays;
        busdays_in_weekmask = busdaycal->busdays_in_weekmask;
        memcpy(weekmask, busdaycal->weekmask, 7);
    }
    else {
        /*
         * Fix up the weekmask from the uninitialized
         * signal value to a proper default.

            

Reported by FlawFinder.

numpy/core/src/multiarray/convert.c
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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

                      i = it->size;
        elsize = PyArray_DESCR(self)->elsize;
        while (i--) {
            memcpy(dptr, it->dataptr, elsize);
            dptr += elsize;
            PyArray_ITER_NEXT(it);
        }
        Py_DECREF(it);
    }

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 137 Column: 17 CWE codes: 126

                  PyArrayIterObject *it;
    PyObject *obj, *strobj, *tupobj, *byteobj;

    n3 = (sep ? strlen((const char *)sep) : 0);
    if (n3 == 0) {
        /* binary data */
        if (PyDataType_FLAGCHK(PyArray_DESCR(self), NPY_LIST_PICKLE)) {
            PyErr_SetString(PyExc_IOError,
                    "cannot write object arrays to a file in binary mode");

            

Reported by FlawFinder.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

Line: 220 Column: 24 CWE codes: 126

              
        it = (PyArrayIterObject *)
            PyArray_IterNew((PyObject *)self);
        n4 = (format ? strlen((const char *)format) : 0);
        while (it->index < it->size) {
            obj = PyArray_GETITEM(self, it->dataptr);
            if (obj == NULL) {
                Py_DECREF(it);
                return -1;

            

Reported by FlawFinder.

numpy/polynomial/setup.py
3 issues
Missing function or method docstring
Error

Line: 1 Column: 1

              def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('polynomial', parent_package, top_path)
    config.add_subpackage('tests')
    config.add_data_files('*.pyi')
    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('polynomial', parent_package, top_path)
    config.add_subpackage('tests')
    config.add_data_files('*.pyi')
    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup

            

Reported by Pylint.

Import outside toplevel (numpy.distutils.misc_util.Configuration)
Error

Line: 2 Column: 5

              def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('polynomial', parent_package, top_path)
    config.add_subpackage('tests')
    config.add_data_files('*.pyi')
    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup

            

Reported by Pylint.

numpy/random/src/mt19937/randomkit.c
3 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 138 Column: 1 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

              #define RK_DEV_RANDOM "/dev/random"
#endif

char *rk_strerror[RK_ERR_MAX] = {"no error", "random device unvavailable"};

/* static functions */
static unsigned long rk_hash(unsigned long key);

void rk_seed(unsigned long seed, rk_state *state) {

            

Reported by FlawFinder.

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: 512 Column: 13 CWE codes: 362

                int done;

  if (strong) {
    rfile = fopen(RK_DEV_RANDOM, "rb");
  } else {
    rfile = fopen(RK_DEV_URANDOM, "rb");
  }
  if (rfile == NULL) {
    return RK_ENODEV;

            

Reported by FlawFinder.

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: 514 Column: 13 CWE codes: 362

                if (strong) {
    rfile = fopen(RK_DEV_RANDOM, "rb");
  } else {
    rfile = fopen(RK_DEV_URANDOM, "rb");
  }
  if (rfile == NULL) {
    return RK_ENODEV;
  }
  done = fread(buffer, size, 1, rfile);

            

Reported by FlawFinder.

numpy/setup.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('numpy', parent_package, top_path)

    config.add_subpackage('compat')
    config.add_subpackage('core')
    config.add_subpackage('distutils')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 3 Column: 1

              #!/usr/bin/env python3

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('numpy', parent_package, top_path)

    config.add_subpackage('compat')
    config.add_subpackage('core')
    config.add_subpackage('distutils')

            

Reported by Pylint.

Import outside toplevel (numpy.distutils.misc_util.Configuration)
Error

Line: 4 Column: 5

              #!/usr/bin/env python3

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('numpy', parent_package, top_path)

    config.add_subpackage('compat')
    config.add_subpackage('core')
    config.add_subpackage('distutils')

            

Reported by Pylint.

numpy/lib/tests/test_financial_expired.py
3 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import sys
import pytest
import numpy as np


@pytest.mark.skipif(sys.version_info[:2] < (3, 7),
                    reason="requires python 3.7 or higher")
def test_financial_expired():
    match = 'NEP 32'

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import sys
import pytest
import numpy as np


@pytest.mark.skipif(sys.version_info[:2] < (3, 7),
                    reason="requires python 3.7 or higher")
def test_financial_expired():
    match = 'NEP 32'

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              
@pytest.mark.skipif(sys.version_info[:2] < (3, 7),
                    reason="requires python 3.7 or higher")
def test_financial_expired():
    match = 'NEP 32'
    with pytest.warns(DeprecationWarning, match=match):
        func = np.fv
    with pytest.raises(RuntimeError, match=match):
        func(1, 2, 3)

            

Reported by Pylint.

numpy/distutils/msvc9compiler.py
3 issues
Attempted relative import beyond top-level package
Error

Line: 4 Column: 1

              import os
from distutils.msvc9compiler import MSVCCompiler as _MSVCCompiler

from .system_info import platform_bits


def _merge(old, new):
    """Concatenate two environment paths avoiding repeats.


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os
from distutils.msvc9compiler import MSVCCompiler as _MSVCCompiler

from .system_info import platform_bits


def _merge(old, new):
    """Concatenate two environment paths avoiding repeats.


            

Reported by Pylint.

Missing class docstring
Error

Line: 39 Column: 1

                  return ';'.join([old, new])


class MSVCCompiler(_MSVCCompiler):
    def __init__(self, verbose=0, dry_run=0, force=0):
        _MSVCCompiler.__init__(self, verbose, dry_run, force)

    def initialize(self, plat_name=None):
        # The 'lib' and 'include' variables may be overwritten

            

Reported by Pylint.