Skip to content

Commit

Permalink
Fix windows_read_sorted_physical_devices buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn authored and charles-lunarg committed Sep 25, 2024
1 parent 6b31cf1 commit 7a511f0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions loader/loader_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,20 +968,6 @@ VkResult windows_read_sorted_physical_devices(struct loader_instance *inst, uint
continue;
}

if (icd_phys_devs_array_size <= i) {
uint32_t old_size = icd_phys_devs_array_size * sizeof(struct loader_icd_physical_devices);
*icd_phys_devs_array = loader_instance_heap_realloc(inst, *icd_phys_devs_array, old_size, 2 * old_size,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (*icd_phys_devs_array == NULL) {
adapter->lpVtbl->Release(adapter);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
icd_phys_devs_array_size *= 2;
}
(*icd_phys_devs_array)[*icd_phys_devs_array_count].device_count = 0;
(*icd_phys_devs_array)[*icd_phys_devs_array_count].physical_devices = NULL;

icd_term = inst->icd_terms;
while (NULL != icd_term) {
// This is the new behavior, which cannot be run unless the ICD provides EnumerateAdapterPhysicalDevices
Expand All @@ -990,6 +976,20 @@ VkResult windows_read_sorted_physical_devices(struct loader_instance *inst, uint
continue;
}

if (icd_phys_devs_array_size <= *icd_phys_devs_array_count) {
uint32_t old_size = icd_phys_devs_array_size * sizeof(struct loader_icd_physical_devices);
*icd_phys_devs_array = loader_instance_heap_realloc(inst, *icd_phys_devs_array, old_size, 2 * old_size,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (*icd_phys_devs_array == NULL) {
adapter->lpVtbl->Release(adapter);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
icd_phys_devs_array_size *= 2;
}
(*icd_phys_devs_array)[*icd_phys_devs_array_count].device_count = 0;
(*icd_phys_devs_array)[*icd_phys_devs_array_count].physical_devices = NULL;

res = enumerate_adapter_physical_devices(inst, icd_term, description.AdapterLuid, icd_phys_devs_array_count,
*icd_phys_devs_array);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
Expand Down

0 comments on commit 7a511f0

Please sign in to comment.