BUG: validate UTF-8 and harden StringDType bounds handling - #32296
Open
ngoldbaum wants to merge 2 commits into
Open
BUG: validate UTF-8 and harden StringDType bounds handling#32296ngoldbaum wants to merge 2 commits into
ngoldbaum wants to merge 2 commits into
Conversation
ngoldbaum
force-pushed
the
fix-stringdtype-utf-8
branch
from
August 14, 2026 22:34
3cd53ac to
a0c85a0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Fixes #32287, Fixes #32288
Both issues relied on injecting invalid UTF-8 via the bytes to string cast, which did not validate UTF-8.
This led to hangs and UB, which I've defensively hardened in a few spots but the main bugfix is adding UTF-8 validation to the bytes to string cast. I also saw a spot to avoid unnecessary re-scanning in the np.strings.slice loop, which is fixed to avoid possible UTF-8 validation issues.
Also documents that
NpyString_Packdoesn't do UTF-8 validation, so input data must be validated as UTF-8 by users of the C API.Additionally, fixes signed integer overflow issues and issues on 32-bit builds caused by using
npy_intpinternally but still accepting 64-bit data in the Python API.AI Disclosure
I used an AI to do code review, address corner cases, and spot UB sites.