queue_write_texture: Validate the destination texture. (#3378)

This commit is contained in:
Jim Blandy 2023-01-14 01:35:46 -08:00 committed by GitHub
parent 04da0c3f0b
commit 8c9f3f159b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 (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) = let (selector, dst_base, texture_format) =
extract_texture_selector(destination, size, dst)?; extract_texture_selector(destination, size, dst)?;
@ -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 dst = texture_guard.get(destination.texture).unwrap();
let transition = trackers let transition = trackers
.textures .textures