10000 Merge pull request #8114 from pv/bugfix · numpy/numpy@9914e60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9914e60

Browse files
authored
Merge pull request #8114 from pv/bugfix
BUG: core: add missing error check after PyLong_AsSsize_t
2 parents b58bed8 + fd6ff26 commit 9914e60

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,9 @@ array_shares_memory_impl(PyObject *args, PyObject *kwds, Py_ssize_t default_max_
39813981
}
39823982
else if (PyLong_Check(max_work_obj)) {
39833983
max_work = PyLong_AsSsize_t(max_work_obj);
3984+
if (PyErr_Occurred()) {
3985+
goto fail;
3986+
}
39843987
}
39853988
#if !defined(NPY_PY3K)
39863989
else if (PyInt_Check(max_work_obj)) {

numpy/core/tests/test_mem_overlap.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ def test_shares_memory_api():
348348
assert_raises(np.TooHardError, np.shares_memory, a, b, max_work=long(1))
349349

350350

351+
def test_may_share_memory_bad_max_work():
352+
x = np.zeros([1])
353+
assert_raises(OverflowError, np.may_share_memory, x, x, max_work=10**100)
354+
assert_raises(OverflowError, np.shares_memory, x, x, max_work=10**100)
355+
356+
351357
def test_internal_overlap_diophantine():
352358
def check(A, U, exists=None):
353359
X = solve_diophantine(A, U, 0, require_ub_nontrivial=1)

0 commit comments

Comments
 (0)
0