fix(naga): Forbid negative indexing in const expressions (#7155)

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson
2025-02-17 20:38:00 +01:00
committed by GitHub
parent d625d083c3
commit 7240c18554

View File

@@ -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()