Repository navigation
fix(core): reject mismatched UUID in register() even under -O #2704
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e603e0e
4eecdbc
13a5c85
620afec
736393d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,37 @@ def test_register_rejects_non_ipc_memory_resource(mempool_device): | |
| DeviceMemoryResource.from_registry(key) | ||
|
|
||
|
|
||
| @pytest.mark.human_authored | ||
| def test_register_rejects_mismatched_uuid(ipc_memory_resource): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis
important: Restrict this test to pool resources. When VMM IPC is supported, --- "a/cuda_core/tests/memory_ipc/test_errors.py"
+++ "b/cuda_core/tests/memory_ipc/test_errors.py"
@@ -94,8 +94,9 @@
DeviceMemoryResource.from_registry(key)
+@pytest.mark.parametrize("ipc_memory_resource", ["device", "pinned"], indirect=True)
@pytest.mark.human_authored
def test_register_rejects_mismatched_uuid(ipc_memory_resource):
"""register() rejects a UUID that does not match the resource's own.
The check is an explicit ValueError (not a bare ``assert``) so it remains |
||
| """register() rejects a UUID that does not match the resource's own. | ||
|
|
||
| The check is an explicit ValueError (not a bare ``assert``) so it remains | ||
| enforced even when CPython runs with ``-O``, where assertions are removed | ||
| (see #2697). Registering under a foreign key would otherwise rewrite the | ||
| resource's UUID and silently corrupt the IPC registry. | ||
| """ | ||
| mr = ipc_memory_resource | ||
| if not is_pool_resource(mr): | ||
| pytest.skip("allocation handles and the registry are pool-only") | ||
| assert mr.is_ipc_enabled | ||
|
|
||
| # The resource must already carry its own UUID (assigned on creation). | ||
| original = mr.uuid | ||
| assert original is not None | ||
| other = uuid.uuid4() | ||
| while other == mr.uuid: | ||
| other = uuid.uuid4() | ||
|
|
||
| with pytest.raises(ValueError, match="already has UUID"): | ||
| mr.register(other) | ||
|
|
||
| # A rejected registration must leave the resource's own UUID unchanged. | ||
| assert mr.uuid == original | ||
|
|
||
| # Registering under the resource's own UUID still succeeds. | ||
| assert mr.register(mr.uuid) is mr | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name == "nt", reason="IPC allocation handles are not supported on Windows") | ||
| @pytest.mark.agent_authored(model="gpt-5.6") | ||
| def test_ipc_allocation_handle_state_tracks_close(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
important: Check the resource UUID before the registry lookup. If a UUID already belongs to another resource,
MP_registerreturns that resource at Lines 477–480. The new check never runs, somr.register(other_uuid)accepts a UUID that differs frommr.uuid. Move the mismatch check before the existing-entry return.