Vulkan: Avoid undefined behaviour with adversarial debug label (#6257)

This commit is contained in:
Daniel McNab 2024-09-12 14:03:04 +01:00 committed by GitHub
parent f3cbd6ce54
commit c2e0ad293f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -111,6 +111,10 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).
- Fix GL debug message callbacks not being properly cleaned up (causing UB). By @Imberflur in [#6114](https://github.com/gfx-rs/wgpu/pull/6114) - Fix GL debug message callbacks not being properly cleaned up (causing UB). By @Imberflur in [#6114](https://github.com/gfx-rs/wgpu/pull/6114)
#### Vulkan
- Vulkan debug labels assumed no interior nul byte. By @DJMcNab in [#6257](https://github.com/gfx-rs/wgpu/pull/6257)
### Changes ### Changes
- `wgpu_hal::gles::Adapter::new_external` now requires the context to be current when dropping the adapter and related objects. By @Imberflur in [#6114](https://github.com/gfx-rs/wgpu/pull/6114). - `wgpu_hal::gles::Adapter::new_external` now requires the context to be current when dropping the adapter and related objects. By @Imberflur in [#6114](https://github.com/gfx-rs/wgpu/pull/6114).

View File

@ -15,6 +15,13 @@ use std::{
}; };
impl super::DeviceShared { impl super::DeviceShared {
/// Set the name of `object` to `name`.
///
/// If `name` contains an interior null byte, then the name set will be truncated to that byte.
///
/// # Safety
///
/// It must be valid to set `object`'s debug name
pub(super) unsafe fn set_object_name(&self, object: impl vk::Handle, name: &str) { pub(super) unsafe fn set_object_name(&self, object: impl vk::Handle, name: &str) {
let Some(extension) = self.extension_fns.debug_utils.as_ref() else { let Some(extension) = self.extension_fns.debug_utils.as_ref() else {
return; return;
@ -44,7 +51,7 @@ impl super::DeviceShared {
&buffer_vec &buffer_vec
}; };
let name = unsafe { CStr::from_bytes_with_nul_unchecked(name_bytes) }; let name = CStr::from_bytes_until_nul(name_bytes).expect("We have added a null byte");
let _result = unsafe { let _result = unsafe {
extension.set_debug_utils_object_name( extension.set_debug_utils_object_name(