Read a 32-bit little-endian value from bytes at the given offset
(bytes: &[u8], offset: usize)
| 108 | .ok_or_else(|| VmError::Other("ELF read overflow".to_owned()))?; |
| 109 | let slice = bytes |
| 110 | .get(offset..end) |
| 111 | .ok_or_else(|| VmError::Other("ELF read out of bounds".to_owned()))?; |
| 112 | Ok(u32::from_le_bytes([slice[0], slice[1], slice[2], slice[3]])) |
| 113 | } |
| 114 | |
| 115 | fn read_u64(bytes: &[u8], offset: usize) -> Result<u64, VmError> { |
| 116 | let end = offset |
| 117 | .checked_add(8) |
| 118 | .ok_or_else(|| VmError::Other("ELF read overflow".to_owned()))?; |
| 119 | let slice = bytes |
| 120 | .get(offset..end) |
| 121 | .ok_or_else(|| VmError::Other("ELF read out of bounds".to_owned()))?; |