mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
fix(naga): Forbid negative indexing in const expressions (#7155)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
@@ -280,25 +280,26 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
|
||||
// If we know both the length and the index, we can do the
|
||||
// bounds check now.
|
||||
if let crate::proc::IndexableLength::Known(known_length) =
|
||||
base_type.indexable_length(module)?
|
||||
// If index is const we can do check for non-negative index
|
||||
match module
|
||||
.to_ctx()
|
||||
.eval_expr_to_u32_from(index, &function.expressions)
|
||||
{
|
||||
match module
|
||||
.to_ctx()
|
||||
.eval_expr_to_u32_from(index, &function.expressions)
|
||||
{
|
||||
Ok(value) => {
|
||||
Ok(value) => {
|
||||
// If we know both the length and the index, we can do the
|
||||
// bounds check now.
|
||||
if let crate::proc::IndexableLength::Known(known_length) =
|
||||
base_type.indexable_length(module)?
|
||||
{
|
||||
if value >= known_length {
|
||||
return Err(ExpressionError::IndexOutOfBounds(base, value));
|
||||
}
|
||||
}
|
||||
Err(crate::proc::U32EvalError::Negative) => {
|
||||
return Err(ExpressionError::NegativeIndex(base))
|
||||
}
|
||||
Err(crate::proc::U32EvalError::NonConst) => {}
|
||||
}
|
||||
Err(crate::proc::U32EvalError::Negative) => {
|
||||
return Err(ExpressionError::NegativeIndex(base))
|
||||
}
|
||||
Err(crate::proc::U32EvalError::NonConst) => {}
|
||||
}
|
||||
|
||||
ShaderStages::all()
|
||||
|
||||
Reference in New Issue
Block a user