Skip to content

Commit

Permalink
Validate that map_async's range is not negative.
Browse files Browse the repository at this point in the history
map_async already checks that the range's end is within the bounds of the buffer, so this also ensures the range start is within bounds.
  • Loading branch information
nical committed Aug 3, 2022
1 parent 780209d commit 3cf1501
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5403,7 +5403,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
BufferMapAsyncStatus::InvalidAlignment
}
&BufferAccessError::OutOfBoundsUnderrun { .. }
| &BufferAccessError::OutOfBoundsOverrun { .. } => {
| &BufferAccessError::OutOfBoundsOverrun { .. }
| &BufferAccessError::NegativeRange { .. } => {
BufferMapAsyncStatus::InvalidRange
}
_ => BufferMapAsyncStatus::Error,
Expand Down Expand Up @@ -5456,6 +5457,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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,
Expand Down
5 changes: 5 additions & 0 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3cf1501

Please sign in to comment.