blob: 74bc75f8e9cda6a48fb3ed65251220ace8d143ae [file] [log] [blame]
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use cros_fuzz::fuzz_target;
use qcow::QcowFile;
use sys_util::SharedMemory;
use std::fs::File;
use std::io::{Cursor, Read, Seek, SeekFrom, Write};
use std::mem::size_of;
// Take the first 64 bits of data as an address and the next 64 bits as data to
// store there. The rest of the data is used as a qcow image.
fuzz_target!(|bytes| {
if bytes.len() < 16 {
// Need an address and data, each are 8 bytes.
let mut disk_image = Cursor::new(bytes);
let addr = read_u64(&mut disk_image);
let value = read_u64(&mut disk_image);
let shm = SharedMemory::anon().unwrap();
let mut disk_file: File = shm.into();
if let Ok(mut qcow) = QcowFile::from(disk_file) {
if {
let _ = qcow.write_all(&value.to_le_bytes());
fn read_u64<T: Read>(readable: &mut T) -> u64 {
let mut buf = [0u8; size_of::<u64>()];
readable.read_exact(&mut buf[..]).unwrap();