Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144281: Fix crash on memoryview slice assignment with shared memory#144284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletionsLib/test/_test_multiprocessing.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4932,6 +4932,15 @@ def test_shared_memory_cleaned_after_process_termination(self):
"resource_tracker: There appear to be 1 leaked "
"shared_memory objects to clean up at shutdown", err)

def test_shared_memory_slice_assignment_no_crash(self):
from multiprocessing import shared_memory
shm = shared_memory.SharedMemory(create=True, size=10)
mv = shm.buf
shm.close()
shm.unlink()
with self.assertRaises((BufferError, ValueError)):
mv[:5] = b'hello'

@unittest.skipIf(os.name != "posix", "resource_tracker is posix only")
@resource_tracker_format_subtests
def test_shared_memory_untracking(self):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix a possible interpreter crash during memoryview slice assignment when the
underlying buffer is backed by shared memory.
5 changes: 5 additions & 0 deletionsObjects/memoryobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2656,6 +2656,11 @@ memory_ass_sub(PyObject *_self, PyObject *key, PyObject *value)

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
ContributorAuthor

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 testworks.

Also note the bug in the OP is aSIGBUS, 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 whenctypes ormmap orgc or various other low-level power tools.

PyErr_SetString(PyExc_BufferError,"memoryview: underlying buffer is no longer valid");
return-1;
}

fmt=adjust_fmt(view);
if (fmt==NULL)
return-1;
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp