Skip to content
This repository was archived by the owner on Aug 15, 2021. It is now read-only.

Fix deserializing externally tagged enums from indefinite maps #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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