MCPcopy Create free account
hub / github.com/MultiFuzz/MultiFuzz / from_bytes

Method from_bytes

hail-fuzz/src/input.rs:181–220  ·  view source on GitHub ↗
(buf: &[u8])

Source from the content-addressed store, hash-verified

179 }
180
181 pub fn from_bytes(buf: &[u8]) -> Option<Self> {
182 use byteorder::{ReadBytesExt, LE};
183
184 let mut reader = std::io::Cursor::new(buf);
185
186 let mut magic_with_version = [0; 4];
187 reader.read_exact(&mut magic_with_version).ok()?;
188 if !matches!(magic_with_version, FILE_HEADER) {
189 return None;
190 }
191
192 let num_mmio = reader.read_u32::<LE>().ok()?;
193
194 if num_mmio > 0x10000 {
195 // Too many MMIO peripherals.
196 tracing::error!("Too many MMIO peripherals {num_mmio}");
197 return None;
198 }
199
200 let mut headers = Vec::with_capacity(num_mmio as usize);
201 for _ in 0..num_mmio {
202 let addr = reader.read_u64::<LE>().ok()?;
203 let len = reader.read_u64::<LE>().ok()?;
204 headers.push((addr, len));
205 }
206
207 let mut streams = HashMap::default();
208 streams.reserve(headers.len());
209 for (addr, len) in headers {
210 if len > 0x100000 {
211 // Data too long.
212 tracing::error!("{addr:#x} contains too many bytes: {len}");
213 return None;
214 }
215 let mut buf = vec![0; len as usize];
216 reader.read_exact(&mut buf).ok()?;
217 streams.insert(addr, StreamData::new(buf));
218 }
219 Some(MultiStream { streams, last_read: None, tracer: None })
220 }
221
222 pub fn seek_to_start(&mut self) {
223 self.streams.values_mut().for_each(|x| x.cursor = 0);

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected