Skip to content

Conversation

@VanshAgarwal24036
Copy link
Contributor

@VanshAgarwal24036 VanshAgarwal24036 commented Jan 27, 2026

Fix a possible interpreter crash when assigning to a memoryview slice backed by shared memory by validating the underlying buffer before writing. A regression test and NEWS entry are included.

@VanshAgarwal24036 VanshAgarwal24036 force-pushed the gh-144281-shared-memory-crash branch from 20c6f0b to 4cfbb0a Compare January 27, 2026 18:13

CHECK_RELEASED_INT(self);

if (view->buf == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear this is a necessary or sufficient fix without a valid specific trigger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve updated the test that should also make the need for the view->buf NULL check clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue is moot since this has been closed, but I'm afraid this still wouldn't have been useful. Your fix is unrelated to the test; it passes with or without it. It is good practice to always run your test scripts against affected versions, to confirm it reproduces the bug. Without that you don't know the test works.

Also note the bug in the OP is a SIGBUS, a fatal signal. It is completely expected that invalid operations like this raise exceptions, but it shouldn't be possible to trigger a fatal signal via the public API-ish. Terms and conditions apply. Offer void when ctypes or mmap or gc or various other low-level power tools.

@da-woods
Copy link
Contributor

I don't think this can be right. Partly because if it is you'd need to guard every use of view->buf and not just that one. And you'd probably have to do that in a thread-safe way. But also because memoryview owns view so nothing else should even have access to modify view and make it "no longer valid".

@picnixz
Copy link
Member

picnixz commented Jan 28, 2026

If this is a legitimate issue, I believe this should be fixed as part of #143324. I will take care of that once I have time as well. More generally, I would prefer that you avoid addressing crash issues because many of your PRs are eventually closed and the issue is usually non-trivial so it is better to have a more seasoned contributor for those issues.

@picnixz picnixz closed this Jan 28, 2026
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.

4 participants