/// Fails if the header pointed at by `bin_fw` is not within the bounds of the firmware image.
fn new(bin_fw: &BinFirmware<'_>) -> Result<Self> {
let offset = usize::from_safe_cast(bin_fw.hdr.header_offset);
+ let end = offset.checked_add(size_of::<Self>()).ok_or(EINVAL)?;
bin_fw
.fw
- .get(offset..offset + size_of::<Self>())
+ .get(offset..end)
.and_then(Self::from_bytes_copy)
.ok_or(EINVAL)
}
let ucode = {
let start = usize::from_safe_cast(bin_fw.hdr.data_offset);
let len = usize::from_safe_cast(bin_fw.hdr.data_size);
+ let end = start.checked_add(len).ok_or(EINVAL)?;
- DmaObject::from_data(dev, fw.data().get(start..start + len).ok_or(EINVAL)?)?
+ DmaObject::from_data(dev, fw.data().get(start..end).ok_or(EINVAL)?)?
};
Ok(Self {