Serialize unknown headers

We don't store anything after the first line for unknown headers,
because we have no way to determine where the header ends and the data
begins. Anything after the first header line would be treated as fixed
bytes in either case.
This commit is contained in:
Jack Grigg 2020-03-28 22:26:13 +13:00
parent 41674d5d79
commit 21f8f5a4b9
2 changed files with 4 additions and 8 deletions

View file

@ -298,7 +298,7 @@ mod write {
pub(super) fn header<'a, W: 'a + Write>(h: &'a Header) -> impl SerializeFn<W> + 'a {
move |w: WriteContext<W>| match h {
Header::V1(v1) => header_v1(v1)(w),
Header::Unknown(version) => panic!("Cannot write header for version {}", version),
Header::Unknown(version) => tuple((slice(AGE_MAGIC), slice(version), string("\n")))(w),
}
}
}

View file

@ -127,12 +127,8 @@ pub mod cli_common;
#[cfg(fuzzing)]
pub fn fuzz_header(data: &[u8]) {
if let Ok(header) = format::Header::read(data) {
if let format::Header::Unknown(_) = header {
// Unknown headers cause panics on write.
} else {
let mut buf = Vec::with_capacity(data.len());
header.write(&mut buf).expect("can write header");
assert_eq!(&buf[..], &data[..buf.len()]);
}
let mut buf = Vec::with_capacity(data.len());
header.write(&mut buf).expect("can write header");
assert_eq!(&buf[..], &data[..buf.len()]);
}
}