Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queue_write_texture: Validate the destination texture. #3378

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

let (mut texture_guard, _) = hub.textures.write(&mut token); // For clear we need write access to the texture. TODO: Can we acquire write lock later?
let dst = texture_guard.get_mut(destination.texture).unwrap();
let dst = texture_guard
.get_mut(destination.texture)
.map_err(|_| TransferError::InvalidTexture(destination.texture))?;

let (selector, dst_base, texture_format) =
extract_texture_selector(destination, size, dst)?;
Expand Down Expand Up @@ -707,6 +709,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}

// Re-get `dst` immutably here, so that the mutable borrow of the
// `texture_guard.get_mut` above ends in time for the `clear_texture`
// call above. Since we've held `texture_guard` the whole time, we know
// the texture hasn't gone away in the mean time, so we can unwrap.
let dst = texture_guard.get(destination.texture).unwrap();
let transition = trackers
.textures
Expand Down