Skip to content

Commit ef3b31c

Browse files
authored
Map bounds check (#2938)
* Validate that map_async's range is not negative. 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. * Add an entry in the changelog.
1 parent 228998a commit ef3b31c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ the same every time it is rendered, we now warn if it is missing.
104104
- Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877)
105105
- Fix out-of-bound write in `map_buffer` with non-zero offset by @nical in [#2916](https://github.com/gfx-rs/wgpu/pull/2916)
106106
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
107-
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892]
107+
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892](https://github.com/gfx-rs/wgpu/pull/2892)
108+
- Validate that map_async's range is not negative by @nical in [#2938](https://github.com/gfx-rs/wgpu/pull/2938)
108109

109110
#### DX12
110111
- `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851)

wgpu-core/src/device/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,9 +5403,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
54035403
BufferMapAsyncStatus::InvalidAlignment
54045404
}
54055405
&BufferAccessError::OutOfBoundsUnderrun { .. }
5406-
| &BufferAccessError::OutOfBoundsOverrun { .. } => {
5407-
BufferMapAsyncStatus::InvalidRange
5408-
}
5406+
| &BufferAccessError::OutOfBoundsOverrun { .. }
5407+
| &BufferAccessError::NegativeRange { .. } => BufferMapAsyncStatus::InvalidRange,
54095408
_ => BufferMapAsyncStatus::Error,
54105409
};
54115410

@@ -5456,6 +5455,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
54565455
return Err((op, e.into()));
54575456
}
54585457

5458+
if range.start > range.end {
5459+
return Err((
5460+
op,
5461+
BufferAccessError::NegativeRange {
5462+
start: range.start,
5463+
end: range.end,
5464+
},
5465+
));
5466+
}
54595467
if range.end > buffer.size {
54605468
return Err((
54615469
op,

wgpu-core/src/resource.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ pub enum BufferAccessError {
173173
index: wgt::BufferAddress,
174174
max: wgt::BufferAddress,
175175
},
176+
#[error("buffer map range start {start} is greater than end {end}")]
177+
NegativeRange {
178+
start: wgt::BufferAddress,
179+
end: wgt::BufferAddress,
180+
},
176181
}
177182

178183
pub(crate) struct BufferPendingMapping {

0 commit comments

Comments
 (0)