Skip to content

Commit

Permalink
Fix deserializing externally tagged enums from indefinite maps (pyfis…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaesar committed Jun 28, 2021
1 parent a218403 commit 6f5b713
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions tests/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = 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]
Expand Down

0 comments on commit 6f5b713

Please sign in to comment.