Vulkan: Avoid undefined behaviour with adversarial debug label #6257
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
This method was first added in #1471
There was no discussion at the time about this use of unsafe, and the original code in
gfx-hal
does not have this unsoundness.Description
In Rust, it is valid for an
&str
to contain an interior nul byte.However, the Vulkan debug object name code uses
CStr::from_bytes_with_nul_unchecked
with a user-provided&str
, on which as far as I can see there is no additional validation.This is technically an unsoundness fix, but I don't think it's a significant security issue, and so would not recommend backporting this fix.
The tradeoff I have chosen to make in the case of an interior nul-byte is to truncate to that byte.
Alternatives include:
0
?)It's also not clear to me why
set_object_name
is unsafe, as there are no provided preconditions.I guessed at some, but would be happier just removing the
unsafe
marker entirely.Testing
This change is untested.
Checklist
cargo fmt
.cargo clippy
cargo xtask test
to run tests. (Same behaviour as on main of crashing my editor)CHANGELOG.md
. See simple instructions inside file.