Skip to content

Fix apply na overflow #56000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 17, 2023
Merged

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Nov 16, 2023

Another thing flagged by ASAN. I am not very familiar with this algorithm so there may be a better way of doing this, but when n=0 the cython code ends up reading memory one byte to the left of the array

@mroeschke mroeschke added the Bug label Nov 16, 2023
Comment on lines 142 to 145
if n == 0: # avoid OOB access with kth_smallest_c
kth_val = 0
else:
kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if n == 0: # avoid OOB access with kth_smallest_c
kth_val = 0
else:
kth_val = libalgos.kth_smallest(arr.copy(order="C"), n - 1)
# avoid OOB access with kth_smallest_c
kth_val = libalgos.kth_smallest(arr.copy(order="C"), max(n - 1, 0))

I would be more comfortable with this change. Since kth_val is a value in the array and comparisons are made with this value, this may be incorrect if values in arr were all negative for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea

@mroeschke mroeschke added this to the 2.2 milestone Nov 17, 2023
@mroeschke mroeschke merged commit 97828e4 into pandas-dev:main Nov 17, 2023
@mroeschke
Copy link
Member

Thanks @WillAyd

@WillAyd WillAyd mentioned this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants