File CVE-2021-41496-bufovrflw-fortranobject-DoS.patch of Package python3-numpy

From 271010f1037150e95017f803f4214b8861e528f2 Mon Sep 17 00:00:00 2001
From: Warren Weckesser <warren.weckesser@gmail.com>
Date: Mon, 20 Dec 2021 10:35:31 -0500
Subject: [PATCH] BUG: f2py: Simplify creation of an exception message. Closes
 gh-19000.

---
 numpy/f2py/src/fortranobject.c |   25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

--- a/numpy/f2py/src/fortranobject.c
+++ b/numpy/f2py/src/fortranobject.c
@@ -653,6 +653,17 @@ static int swap_arrays(PyArrayObject* ob
        ||(PyArray_ISBOOL(arr) && PyTypeNum_ISBOOL(type_num))            \
        )
 
+static int
+find_first_negative_dimension(const int rank, const npy_intp *dims)
+{
+    for (int i = 0; i < rank; ++i) {
+        if (dims[i] < 0) {
+            return i;
+        }
+    }
+    return -1;
+}
+
 extern
 PyArrayObject* array_from_pyobj(const int type_num,
                                 npy_intp *dims,
@@ -682,14 +693,12 @@ PyArrayObject* array_from_pyobj(const in
         || ((intent & F2PY_OPTIONAL) && (obj==Py_None))
         ) {
         /* intent(cache), optional, intent(hide) */
-        if (count_negative_dimensions(rank,dims) > 0) {
-            int i;
-            strcpy(mess, "failed to create intent(cache|hide)|optional array"
-                   "-- must have defined dimensions but got (");
-            for(i=0;i<rank;++i)
-                sprintf(mess+strlen(mess),"%" NPY_INTP_FMT ",",dims[i]);
-            strcat(mess, ")");
-            PyErr_SetString(PyExc_ValueError,mess);
+        int i = find_first_negative_dimension(rank, dims);
+        if (i >= 0) {
+            PyErr_Format(PyExc_ValueError,
+                         "failed to create intent(cache|hide)|optional array"
+                         " -- must have defined dimensions, but dims[%d] = %"
+                         NPY_INTP_FMT, i, dims[i]);
             return NULL;
         }
         arr = (PyArrayObject *)
openSUSE Build Service is sponsored by