Skip to content

BUG: validate UTF-8 and harden StringDType bounds handling - #32296

Open
ngoldbaum wants to merge 2 commits into
numpy:mainfrom
ngoldbaum:fix-stringdtype-utf-8
Open

BUG: validate UTF-8 and harden StringDType bounds handling#32296
ngoldbaum wants to merge 2 commits into
numpy:mainfrom
ngoldbaum:fix-stringdtype-utf-8

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Aug 14, 2026

Copy link
Copy Markdown
Member

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_Pack doesn'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_intp internally 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.

@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Aug 14, 2026
@ngoldbaum
ngoldbaum force-pushed the fix-stringdtype-utf-8 branch from 3cd53ac to a0c85a0 Compare August 14, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 09 - Backport-Candidate PRs tagged should be backported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: StringDType UTF-8 decoder may read out of bounds BUG: Hang in StringDType UTF-8 decoder on malformed input.

1 participant