Skip to content

clamp emulated property copies to the caller-allocated count#1939

Merged
charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:emulation-count-clamp
Jun 19, 2026
Merged

clamp emulated property copies to the caller-allocated count#1939
charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:emulation-count-clamp

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

The 2-variant emulation terminators have a count-handling mismatch:

loader/wsi.c  terminator_GetPhysicalDeviceSurfaceFormats2KHR
    formats = loader_stack_alloc(*pSurfaceFormatCount * sizeof(...));  // scratch sized by caller count N
    GetPhysicalDeviceSurfaceFormatsKHR(..., pSurfaceFormatCount, formats);  // ICD rewrites *pSurfaceFormatCount
    for (i = 0; i < *pSurfaceFormatCount; ++i)                         // loop now bound by ICD's number
        pSurfaceFormats[i].surfaceFormat = formats[i];                 // caller array also only holds N

Noticed this reading over the emulation paths after the sparse-format size fix. The scratch array and the caller's output array are both sized from the count the caller passed in, yet the copy loop is bound by the count the legacy entrypoint writes back into the count pointer. A driver that reports more entries than the caller's array holds then walks past the stack scratch buffer and the caller's array.

The non-emulated path already guards this. vkEnumerateDeviceExtensionProperties copies min(*pPropertyCount, count) and stops at the caller's capacity. These emulation terminators just missed the same clamp.

Fix snapshots the allocated count before the call and bounds each copy to it. Same shape at all six sites: queue family, sparse image format, surface formats, display properties, display plane properties, display mode properties.

The *2KHR emulation terminators size a temporary array and the caller's output array from the input count, but bound the copy loop by the count the legacy ICD entrypoint writes back. A driver reporting more entries than the caller allocated then copies past both arrays. Snapshot the allocated count before the call and clamp each copy, matching the existing clamp in vkEnumerateDeviceExtensionProperties.
@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.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 11355.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3570 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3570 passed.

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

Good defensive check since while we would like the count to be the same as from the first call, we can't guarantee that.

@charles-lunarg charles-lunarg merged commit 5a5dc83 into KhronosGroup:main Jun 19, 2026
51 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