Skip to content

fix infinite loop in terminator_EnumeratePhysicalDeviceGroups - #2050

Merged
charles-lunarg merged 2 commits into
KhronosGroup:mainfrom
aizu-m:phys-dev-groups-count-loop-advance
Oct 10, 2026
Merged

charles-lunarg merged 2 commits into
KhronosGroup:mainfrom
aizu-m:phys-dev-groups-count-loop-advance

Conversation

@aizu-m

@aizu-m aizu-m commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Found by grepping loader.c for continue inside a while loop that advances its iterator at the bottom of the body. Two hits. One test driver, its vkEnumeratePhysicalDevices count query returning VK_ERROR_INITIALIZATION_FAILED:

[Vulkan Loader] ERROR:  terminator_EnumeratePhysicalDeviceGroups:  Failed during dispatch call of 'EnumeratePhysicalDevices' to ICD libtest_icd_version_2_0.dylib to get plain phys dev count.
[Vulkan Loader] ERROR:  terminator_EnumeratePhysicalDeviceGroups:  Failed during dispatch call of 'EnumeratePhysicalDevices' to ICD libtest_icd_version_2_0.dylib to get plain phys dev count.
... same line for ever, vkEnumeratePhysicalDeviceGroups never returns

The counting loop does icd_term = icd_term->next at the bottom. Both error paths continue above it, so the failing driver is queried again straight away. The trampoline holds loader_lock the whole time, so anything else taking that lock stops behind the spin. A 1.0 driver reaches the EnumeratePhysicalDevices branch because it exposes no vkEnumeratePhysicalDeviceGroups.

loader_get_fullpath is the other hit: continue on a negative snprintf return skips dir = next_dir. Folded that check into the file-exists test so the loop always advances.

Regression test added. It spins for ever before the change and passes after.

The per-driver counting loop advances icd_term at the bottom of the body, so the two count-query error paths retried the same driver for ever. Advance before the continue, and fold the same shape in loader_get_fullpath into its file-exists check.
@ci-tester-lunarg

Copy link
Copy Markdown

Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg

Copy link
Copy Markdown

Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

@charles-lunarg charles-lunarg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very good to prevent these infinite loops. Thanks!

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 150577.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3805 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3805 passed.

Seems GCC wants to be extra sure that snprintf isn't writing to a nullptr, so add in an
extra check for it.
@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 152341.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 152358.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3809 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3809 passed.

@charles-lunarg
charles-lunarg merged commit 22a50d7 into KhronosGroup:main Oct 10, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants