Skip to content

Deserializing an indefinite array of bools (or map with bool keys) fails #1

@joshtriplett

Description

@joshtriplett

The implementation of deserialization for Vec and BTreeMap, in indefinite length case, will assume that if it finds an item of type Special, it must be the Special::Break indicating the end of the indefinite-length item. However, bools (and other things like Null and Undefined) are also encoded as a Special.

Sample code to reproduce the problem:

use cbor_event::Deserialize;

fn main() -> anyhow::Result<()> {
    let mut s = cbor_event::se::Serializer::new_vec();
    cbor_event::se::serialize_indefinite_array([false, true, false].iter(), &mut s)?;
    let encoded = s.finalize();
    let v = Vec::<bool>::deserialize(&mut cbor_event::de::Deserializer::from(encoded.as_slice()))?;
    println!("{:?}", v);
    Ok(())
}

This produces:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Bool(false)`,
 right: `Break`', /rustc/d3fb005a39e62501b8b0b356166e515ae24e2e54/src/libstd/macros.rs:16:9

Currently working on a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions