Add support for packing and unpacking Android sparse images

This supports all features of Android sparse images, including holes,
and CRC32 (both full image checksum and CRC32 chunks).

Partial sparse images, like those included in GrapheneOS' new optimized
factory images, can also be packed and unpacked with these new commands,
unlike AOSP's simg2img and img2simg tools.

This new functionality is not relevant for avbroot's main use case, but
is useful for unpacking certain factory images for comparison with OTAs
during troubleshooting.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
Andrew Gunnerson
2024-09-01 01:39:18 -04:00
parent e25080ddef
commit e9638d25b0
12 changed files with 2146 additions and 6 deletions
+27
View File
@@ -0,0 +1,27 @@
#[cfg(not(windows))]
mod fuzz {
use std::io::{self, Cursor};
use avbroot::format::sparse::{ChunkData, CrcMode, SparseReader};
use honggfuzz::fuzz;
pub fn main() {
loop {
fuzz!(|data: &[u8]| {
let reader = Cursor::new(data);
if let Ok(mut sparse_reader) = SparseReader::new(reader, CrcMode::Ignore) {
while let Ok(Some(chunk)) = sparse_reader.next_chunk() {
if chunk.data == ChunkData::Data {
let _ = io::copy(&mut sparse_reader, &mut io::sink());
}
}
}
});
}
}
}
fn main() {
#[cfg(not(windows))]
fuzz::main();
}