raw: bound opcode area count validation

This commit is contained in:
Dylan M. Taylor
2026-11-15 21:49:46 -05:00
parent 75cff558e5
commit fab94c80fe
+5 -1
View File
@@ -254,7 +254,11 @@ pub fn parse(id: u32, bytes: &[u8], context: Context) -> Result<Params<'_>, Pars
_ => {
let n = r.count(4)?;
let vals = (0..n).map(|_| r.f32()).collect::<Result<Vec<_>, _>>()?;
let need = if matches!(id, 10 | 12) { area.rows().count() } else { area.cols().count() };
let need = if matches!(id, 10 | 12) {
area.bottom.saturating_sub(area.top).div_ceil(area.row_pitch)
} else {
area.right.saturating_sub(area.left).div_ceil(area.col_pitch)
};
if vals.len() < need {
return Err(ParseError::Malformed("opcode with fewer values than rows or columns"));
}