From c5db8e86ebdcb54e33c93386a18b86615789fc50 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 17 Jun 2022 12:37:53 -0400 Subject: MAINT: Protect against integer overflow in in1d --- numpy/lib/arraysetops.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'numpy/lib/arraysetops.py') diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index bc25743f7..a67472a22 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -652,11 +652,14 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, kind=None): below_memory_constraint = ( ar2_range <= 6 * (ar1_size + ar2_size) ) + range_safe_from_overflow = True except FloatingPointError: - below_memory_constraint = False + range_safe_from_overflow = False - # Use the fast integer algorithm - if below_memory_constraint or kind == 'dictionary': + if ( + range_safe_from_overflow and + (below_memory_constraint or kind == 'dictionary') + ): if invert: outgoing_array = np.ones_like(ar1, dtype=bool) -- cgit v1.2.1