diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-07 13:48:17 -0700 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-06-07 14:24:36 -0700 |
commit | 703a6fa6ac7f5049bb17726a1ba93f7835bf92ae (patch) | |
tree | 0b833f2929840aebd1e26e0c9c44f95ef476abd7 /numpy/core/src | |
parent | c7709982c99ee8c3c9d0953dc5be804023417a55 (diff) | |
download | numpy-703a6fa6ac7f5049bb17726a1ba93f7835bf92ae.tar.gz |
BUG: Prevent attempted broadcasting of 0-D output operands in ufuncs
Attempting to broadcast causes crashes when we later check for self
overlap of the output operand (assuming it is 1-D).
But it would also crash if the operation was done, the issue is
not rejecting the broadcasting right-away.
Closes gh-21673
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 290ed24a6..fce7d61de 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -1243,7 +1243,7 @@ try_trivial_single_output_loop(PyArrayMethod_Context *context, int op_ndim = PyArray_NDIM(op[iop]); /* Special case 0-D since we can handle broadcasting using a 0-stride */ - if (op_ndim == 0) { + if (op_ndim == 0 && iop < nin) { fixed_strides[iop] = 0; continue; } @@ -1254,7 +1254,7 @@ try_trivial_single_output_loop(PyArrayMethod_Context *context, operation_shape = PyArray_SHAPE(op[iop]); } else if (op_ndim != operation_ndim) { - return -2; /* dimension mismatch (except 0-d ops) */ + return -2; /* dimension mismatch (except 0-d input ops) */ } else if (!PyArray_CompareLists( operation_shape, PyArray_DIMS(op[iop]), op_ndim)) { |