From 21f8f5a4b95a9df4f94e356a60a185ffdc65ee96 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 28 Mar 2020 22:26:13 +1300 Subject: [PATCH] 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. --- age/src/format.rs | 2 +- age/src/lib.rs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/age/src/format.rs b/age/src/format.rs index ac83331..7b5bb31 100644 --- a/age/src/format.rs +++ b/age/src/format.rs @@ -298,7 +298,7 @@ mod write { pub(super) fn header<'a, W: 'a + Write>(h: &'a Header) -> impl SerializeFn + 'a { move |w: WriteContext| 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), } } } diff --git a/age/src/lib.rs b/age/src/lib.rs index d2d3d0e..d306bac 100644 --- a/age/src/lib.rs +++ b/age/src/lib.rs @@ -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()]); } }