From 6f5b7130e926e2953803b0fa33a8ee348561c4ee Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Mon, 28 Jun 2021 19:59:56 +0900 Subject: [PATCH] Fix deserializing externally tagged enums from indefinite maps (#199) --- src/de.rs | 7 +++++++ tests/de.rs | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/de.rs b/src/de.rs index 170e0593..aca03514 100644 --- a/src/de.rs +++ b/src/de.rs @@ -863,6 +863,13 @@ where self.consume(); self.parse_enum_map(visitor) } + Some(0xbf) => { + if !self.accept_standard_enums { + return Err(self.error(ErrorCode::WrongEnumFormat)); + } + self.consume(); + self.parse_indefinite_enum(visitor) + } None => Err(self.error(ErrorCode::EofWhileParsingValue)), _ => { if !self.accept_standard_enums && !self.accept_legacy_enums { diff --git a/tests/de.rs b/tests/de.rs index 01d79145..c1b4fc01 100644 --- a/tests/de.rs +++ b/tests/de.rs @@ -573,6 +573,17 @@ mod std_tests { value.unwrap_err().classify(), serde_cbor::error::Category::Syntax ); + + // Externally tagged enum with a variable length map + let v: Vec = vec![ + 0xbf, // map + 0x67, 0x4e, 0x65, 0x77, 0x54, 0x79, 0x70, 0x65, // utf8 string: NewType + 0x1a, // u32 + 0x00, 0x00, 0x00, 0x0a, // 10 (dec) + 0xff, // stop + ]; + let (_rest, value): (&[u8], Enum) = from_slice_stream(&v[..]).unwrap(); + assert_eq!(value, Enum::NewType(10)); } #[test]