BUG: prevent crash when setting array flags with non-ASCII strings by Breno-Favaretto · Pull Request #31297 · numpy/numpy · GitHub
Skip to content

BUG: prevent crash when setting array flags with non-ASCII strings#31297

Closed
Breno-Favaretto wants to merge 1 commit intonumpy:mainfrom
Breno-Favaretto:main
Closed

BUG: prevent crash when setting array flags with non-ASCII strings#31297
Breno-Favaretto wants to merge 1 commit intonumpy:mainfrom
Breno-Favaretto:main

Conversation

@Breno-Favaretto
Copy link
Copy Markdown
Contributor

PR summary

Fix a crash when using non-ASCII keys in:
arr.flags.__setitem__

As reported in:
https://gist.github.com/devdanzin/ccc2d9553ca1c90ab1835362ee21a40a#reproducer-2-arrflags-segfault-on-non-ascii-key
(discussed in #31046)

Using non-ASCII characters as keys could lead to a segmentation fault due to
unsafe handling of Unicode input in the C implementation.

Reproducer

import numpy as np

arr = np.array([1, 2, 3])
arr.flags["é"] = True

Previous behavior

Segmentation fault    (core dumped)

New behavior

KeyError: 'Unknown flag'

First time committer introduction

AI Disclosure

AI was used to help me understand the English better and to assist in writing this message. All code and debugging were done by me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick:

Suggested change
if (tmp_str == NULL){
if (tmp_str == NULL) {

@jorenham
Copy link
Copy Markdown
Member

oh, actually, this looks like it's a duplicate of #31257

@jorenham jorenham closed this Apr 21, 2026
@Breno-Favaretto
Copy link
Copy Markdown
Contributor Author

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