Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Avoid heap buffer overflow for stringdtype searchsorted#31535

Merged
charris merged 1 commit into
numpy:mainfrom
ngoldbaum:fix-searchsorted-stringdtype
May 30, 2026
Merged

BUG: Avoid heap buffer overflow for stringdtype searchsorted#31535
charris merged 1 commit into
numpy:mainfrom
ngoldbaum:fix-searchsorted-stringdtype

Conversation

@ngoldbaum
Copy link
Copy Markdown
Member

PR summary

Fixes #31533.

Currently the low-level searchsorted implementation is wired up to assume the needle and haystack arrays share a descriptor. This breaks that assumption and adds a hacky special-case in the searchsorted implementation.

I'm deferring a nicer, less hacky fix for later in the 2.6 development cycle (ping @MaanasArora if you're interested in taking that on).

AI Disclosure

I used Claude to help analyze the bug.

@charris
Copy link
Copy Markdown
Member

charris commented May 29, 2026

Is the test known to fail before this PR?

@ngoldbaum
Copy link
Copy Markdown
Member Author

Yeah I confirmed manually that it triggers an ASan heap overflow report.

Copy link
Copy Markdown
Contributor

@MaanasArora MaanasArora left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me! I think this is at the right level for a hack (just at the edge of npy_binsearch). And thanks for the ping, definitely willing to do the larger refactor for 2.6!

I wonder if the test can be made repetitive enough to fail more reliably, not sure if that would be too slow?

@ngoldbaum
Copy link
Copy Markdown
Member Author

I wonder if the test can be made repetitive enough to fail more reliably, not sure if that would be too slow?

On an ASan build the test I added will fail without any iteration without the other C changes, so I'm not worried.

I do want to add more searchsorted tests but that can come later.

@MaanasArora
Copy link
Copy Markdown
Contributor

On an ASan build the test I added will fail without any iteration

Yeah sounds good, so at least CI is good, and a bit niche anyway!

@charris charris merged commit 3088b44 into numpy:main May 30, 2026
88 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented May 30, 2026

Thanks Nathan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: np.searchsorted gives flaky results with StringDType arrays

3 participants