Skip to content

Commit

Permalink
Vulkan: Avoid undefined behaviour with adversarial debug label (#6257)
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab authored Sep 12, 2024
1 parent f3cbd6c commit c2e0ad2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#### Vulkan

- Vulkan debug labels assumed no interior nul byte. By @DJMcNab in [#6257](https://github.com/gfx-rs/wgpu/pull/6257)

### 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).
Expand Down
9 changes: 8 additions & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ use std::{
};

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) {
let Some(extension) = self.extension_fns.debug_utils.as_ref() else {
return;
Expand Down Expand Up @@ -44,7 +51,7 @@ impl super::DeviceShared {
&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 {
extension.set_debug_utils_object_name(
Expand Down

0 comments on commit c2e0ad2

Please sign in to comment.