Don't crash on unknown record flag bits

This commit is contained in:
Tyler Hallada 2021-07-15 10:35:04 -04:00
parent 1bc8f59a5c
commit 4eaa287905

View File

@ -357,9 +357,9 @@ fn parse_record_header(input: &[u8]) -> IResult<&[u8], RecordHeader> {
let (input, record_type) = let (input, record_type) =
verify(parse_4char, |record_type: &str| record_type != "GRUP")(input)?; verify(parse_4char, |record_type: &str| record_type != "GRUP")(input)?;
let (input, size) = le_u32(input)?; let (input, size) = le_u32(input)?;
let (input, flags) = map_res(le_u32, |bits| { let (input, flag_bits) = le_u32(input)?;
RecordFlags::from_bits(bits).ok_or("bad record flag") // Okay to truncate since we only care about bits we know about and don't want to crash on unknown bits.
})(input)?; let flags = RecordFlags::from_bits_truncate(flag_bits);
let (input, id) = le_u32(input)?; let (input, id) = le_u32(input)?;
let (input, timestamp) = le_u16(input)?; let (input, timestamp) = le_u16(input)?;
let (input, version_control_info) = le_u16(input)?; let (input, version_control_info) = le_u16(input)?;