From b657930a3ee61f88ada0630afdac6b1c77459244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Sat, 3 Jul 2021 02:49:02 +0000 Subject: [PATCH] aya: don't error out parsing padded map sections Fixes #28 --- aya/src/obj/mod.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/aya/src/obj/mod.rs b/aya/src/obj/mod.rs index 819f8675..7a37f36e 100644 --- a/aya/src/obj/mod.rs +++ b/aya/src/obj/mod.rs @@ -512,7 +512,7 @@ fn parse_map(section: &Section, name: &str) -> Result { } fn parse_map_def(name: &str, data: &[u8]) -> Result { - if data.len() > mem::size_of::() || data.len() < MINIMUM_MAP_SIZE { + if data.len() < MINIMUM_MAP_SIZE { return Err(ParseError::InvalidMapDefinition { name: name.to_owned(), }); @@ -673,10 +673,7 @@ mod tests { parse_map_def("foo", &[]), Err(ParseError::InvalidMapDefinition { .. }) )); - assert!(matches!( - parse_map_def("foo", &[0u8; std::mem::size_of::() + 1]), - Err(ParseError::InvalidMapDefinition { .. }) - )); + assert_eq!( parse_map_def( "foo", @@ -743,13 +740,6 @@ mod tests { parse_map(&fake_section("maps/foo", &[]), "foo"), Err(ParseError::InvalidMapDefinition { .. }) )); - assert!(matches!( - parse_map( - &fake_section("maps/foo", &[0u8; std::mem::size_of::() + 1]), - "foo" - ), - Err(ParseError::InvalidMapDefinition { .. }) - )) } #[test]