jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
943 stars 91 forks source link

Enums with many variants break deserialization of incorrect data #120

Open MStarha opened 11 months ago

MStarha commented 11 months ago

I have an enum with many variants with variable sizes. If there is 72 variants and fewer and I pass invalid bytes to the deserializer, it correctly reports the data cannot be deserialized. However, if there are more than 72 variants and I pass invalid bytes, the deserializer returns the 73rd enum variant regardless of how many variants there are or what the variant contains.

I cannot say whether the mistake is in serde or postcard because I cannot get to the derived implementation of Deserialize for my enum.

Is there anything I can do? Maybe use flavors?

I know 70+ variants is a lot, those are commands my application can receive and react to. I do not think I can realistically reduce the number. I am not sure that any of my code can help here.

Thank you.

jamesmunns commented 9 months ago

Hey @MStarha, could you please provide some kind of github repo or gist with a minimal reproduction case showing this behavior?

MStarha commented 9 months ago

Since posting I switched to ciborium and the issue went away. I am now very strapped for time and cannot make an example. I'll try to remember later.