diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 895d7e068fa..66a35490c91 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -5403,7 +5403,8 @@ impl Global { BufferMapAsyncStatus::InvalidAlignment } &BufferAccessError::OutOfBoundsUnderrun { .. } - | &BufferAccessError::OutOfBoundsOverrun { .. } => { + | &BufferAccessError::OutOfBoundsOverrun { .. } + | &BufferAccessError::NegativeRange { .. } => { BufferMapAsyncStatus::InvalidRange } _ => BufferMapAsyncStatus::Error, @@ -5456,6 +5457,15 @@ impl Global { return Err((op, e.into())); } + if range.start > range.end { + return Err(( + op, + BufferAccessError::NegativeRange { + start: range.start, + end: range.end, + }, + )); + } if range.end > buffer.size { return Err(( op, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 07a7086ff17..0c574d7665b 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -173,6 +173,11 @@ pub enum BufferAccessError { index: wgt::BufferAddress, max: wgt::BufferAddress, }, + #[error("buffer map range start {start} is greater than end {end}")] + NegativeRange { + start: wgt::BufferAddress, + end: wgt::BufferAddress, + }, } pub(crate) struct BufferPendingMapping {